Andre commited on
Commit
d1cc8ad
·
1 Parent(s): 4011dd8

dynamic data

Browse files
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
.backup/app_modal.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # gradio_interface.py
2
+ import gradio as gr
3
+ import modal
4
+ from config.config import prompts, models_modal # Indirect import
5
+ #from img_gen import generate_image
6
+
7
+ print("Hello from gradio_interface_head!")
8
+
9
+ # Modal remote function synchronously
10
+ def generate(prompt_dropdown, team_dropdown, model_dropdown, custom_prompt_input, cpu_gpu ="GPU"):
11
+ # Debug:
12
+ debug_message = f"Debug: Button clicked! Inputs - Prompt: {prompt_dropdown}, Team: {team_dropdown}, Model: {model_dropdown}, Custom Prompt: {custom_prompt_input}"
13
+ print(debug_message) # Print to console for debugging
14
+ try:
15
+ # Check for CPU/GPU dropdown option
16
+ if cpu_gpu == "GPU":
17
+ f = modal.Function.from_name("LS-img-gen-modal", "generate_image_gpu")
18
+ else:
19
+ f = modal.Function.from_name("LS-img-gen-modal", "generate_image_cpu")
20
+
21
+ # Import the remote function
22
+ image_path, message = f.remote(
23
+ prompt_dropdown,
24
+ team_dropdown,
25
+ model_dropdown,
26
+ custom_prompt_input,
27
+ )
28
+ return image_path, message
29
+ except Exception as e:
30
+ return None, f"Error calling generate_image function: {e}"
31
+
32
+
33
+ # Gradio Interface
34
+ def gradio_interface():
35
+ with gr.Blocks(css="""
36
+ .gradio-container {
37
+ background-image: url('');
38
+ background-size: cover;
39
+ background-position: center;
40
+ }
41
+ .output-image img {
42
+ width: 2500px; /* Force image to fill container width */
43
+ object-fit: cover; /* ACTIVATE FOR IMAGE-FIT CONTAINER */
44
+ }
45
+ """) as demo:
46
+ gr.Markdown("# ========== Loot Survivor - AI Image Generator ==========")
47
+ with gr.Row():
48
+ # Set default values for dropdowns
49
+ prompt_dropdown = gr.Dropdown(choices=[p["alias"] for p in prompts], label="Select Beast", value=prompts[0]["alias"])
50
+ character_dropdown = gr.Dropdown(choices=["Beast only", "Wizard", "Warrior"], label="Select Character", value="Beast only")
51
+ model_dropdown = gr.Dropdown(choices=[m["alias"] for m in models_modal], label="Select Model", value=models_modal[0]["alias"])
52
+ with gr.Row():
53
+ # Add a text box for custom user input (max 200 characters)
54
+ custom_prompt_input = gr.Textbox(label="Custom Prompt (Optional)", placeholder="Enter additional details (max 200 chars)...", max_lines=1, max_length=200)
55
+ with gr.Row():
56
+ generate_button = gr.Button("Generate Image")
57
+ with gr.Row():
58
+ output_image = gr.Image(elem_classes="output-image", label="Generated Image", show_label=False, scale=1, width="100%")
59
+ with gr.Row():
60
+ status_text = gr.Textbox(label="Status", placeholder="Waiting for input...", interactive=False)
61
+
62
+
63
+ # Import the remote function
64
+ f = modal.Function.from_name("img-gen-modal-gpu", "generate_image")
65
+
66
+ # Connect the button to the function
67
+ generate_button.click(
68
+ generate,
69
+ inputs=[prompt_dropdown,
70
+ custom_prompt_input,
71
+ character_dropdown,
72
+ model_dropdown
73
+ ],
74
+ outputs=[output_image, status_text]
75
+ )
76
+ return demo
77
+
78
+ # Create the demo instance
79
+ demo = gradio_interface()
80
+
81
+ # Only launch if running directly
82
+ if __name__ == "__main__":
83
+ demo.queue().launch()
.backup/img_gen_modal.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #img_gen_modal.py
2
+ import modal
3
+ import random
4
+ import io
5
+ from config.config import prompts, api_token
6
+ from config.models import models_modal
7
+ import os
8
+ import gradio as gr
9
+ import torch
10
+ import sentencepiece
11
+ import torch
12
+ from huggingface_hub import login
13
+ from transformers import AutoTokenizer
14
+ import random
15
+ from datetime import datetime
16
+ from diffusers.callbacks import SDXLCFGCutoffCallback
17
+ from diffusers import FluxPipeline
18
+ from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline, AutoencoderTiny, AutoencoderKL, DiffusionPipeline, FluxTransformer2DModel, GGUFQuantizationConfig
19
+ from PIL import Image
20
+ from src.check_dependecies import check_dependencies
21
+ import numpy as np
22
+
23
+ MAX_SEED = np.iinfo(np.int32).max
24
+ MAX_IMAGE_SIZE = 2048
25
+
26
+ CACHE_DIR = "/model_cache"
27
+
28
+ # Define the Modal image
29
+ image = (
30
+ modal.Image.from_registry("nvidia/cuda:12.2.0-devel-ubuntu22.04", add_python="3.9")
31
+ .pip_install_from_requirements("requirements.txt")
32
+ #modal.Image.debian_slim(python_version="3.9") # Base image
33
+ # .apt_install(
34
+ # "git",
35
+ # )
36
+ # .pip_install(
37
+ # "diffusers",
38
+ # f"git+https://github.com/huggingface/transformers.git"
39
+ # )
40
+ .env(
41
+ {
42
+ "HF_HUB_ENABLE_HF_TRANSFER": "1", "HF_HOME": "HF_HOME", "HF_HUB_CACHE": CACHE_DIR
43
+ }
44
+ )
45
+ )
46
+
47
+ # Create a Modal app
48
+ app = modal.App("LS-img-gen-modal", image=image)
49
+ with image.imports():
50
+ import os
51
+
52
+ flux_model_vol = modal.Volume.from_name("flux-model-vol", create_if_missing=True) # Reference your volume
53
+
54
+ # GPU FUNCTION
55
+ @app.function(volumes={"/data": flux_model_vol},
56
+ secrets=[modal.Secret.from_name("huggingface-token")],
57
+ gpu="L40S",
58
+ timeout = 300
59
+ )
60
+ # MAIN GENERATE IMAGE FUNCTION
61
+ def generate_image_gpu(
62
+ prompt_alias,
63
+ custom_prompt,
64
+ characer_dropdown,
65
+ model_alias,
66
+ height=360,
67
+ width=640,
68
+ num_inference_steps=20,
69
+ guidance_scale=2.0,
70
+ seed=-1):
71
+ # Find the selected prompt and model
72
+ print("Hello from LS_img_gen!")
73
+
74
+ check_dependencies()
75
+
76
+ try:
77
+ prompt = next(p for p in prompts if p["alias"] == prompt_alias)["text"]
78
+ model_name = next(m for m in models_modal if m["alias"] == model_alias)["name"]
79
+
80
+ except StopIteration:
81
+ return None, "ERROR: Invalid prompt or model selected."
82
+
83
+ # Print the original prompt and dynamic values for debugging
84
+ print("Original Prompt:")
85
+ print(prompt)
86
+
87
+ # Append the custom character (if provided)
88
+ if characer_dropdown == "Wizard":
89
+ prompt += f" A wizard combats using powerful magic against the {prompt_alias}"
90
+ elif characer_dropdown == "Warrior":
91
+ prompt += f" A warrior combats using his weapons against the {prompt_alias}"
92
+ else:
93
+ pass
94
+
95
+ # Append the custom prompt (if provided)
96
+ if custom_prompt and len(custom_prompt.strip()) > 0:
97
+ prompt += " " + custom_prompt.strip()
98
+
99
+ # Print the formatted prompt for debugging
100
+ print("\nFormatted Prompt:")
101
+ print(prompt)
102
+
103
+ # Randomize the seed if needed
104
+ if seed == -1:
105
+ seed = random.randint(0, 1000000)
106
+
107
+ # HF LOGIN
108
+ print("Initializing HF TOKEN")
109
+ print (api_token)
110
+ # login(token=api_token)
111
+ # print("model_name:")
112
+ # print(model_name)
113
+
114
+
115
+ # Use absolute path with leading slash
116
+ model_path = f"/data/{model_name}" # Changed from "data/" to "/data/"
117
+ print(f"Loading model from local path: {model_path}")
118
+
119
+ # Debug: Check if the directory exists and list its contents
120
+ if os.path.exists(model_path):
121
+ print("Directory exists. Contents:")
122
+ for item in os.listdir(model_path):
123
+ print(f" - {item}")
124
+ else:
125
+ print(f"Directory does not exist: {model_path}")
126
+ print("Contents of /data:")
127
+ print(os.listdir("/data"))
128
+ # CHECK FOR TORCH USING CUDA
129
+ print("CHECK FOR TORCH USING CUDA")
130
+ print(f"CUDA available: {torch.cuda.is_available()}")
131
+ if torch.cuda.is_available():
132
+ print("inside if")
133
+ print(f"CUDA device count: {torch.cuda.device_count()}")
134
+ print(f"Current device: {torch.cuda.current_device()}")
135
+ print(f"Device name: {torch.cuda.get_device_name(torch.cuda.current_device())}")
136
+
137
+ try:
138
+ print("-----INITIALIZING PIPE-----")
139
+ pipe = FluxPipeline.from_pretrained(
140
+ model_path,
141
+ torch_dtype=torch.bfloat16,
142
+ #torch_dtype=torch.float16,
143
+ #torch_dtype=torch.float32,
144
+ #vae=taef1,
145
+ local_files_only=True,
146
+ )
147
+ #torch.cuda.empty_cache()
148
+
149
+ if torch.cuda.is_available():
150
+ print("CUDA available")
151
+ print("using gpu")
152
+ pipe = pipe.to("cuda")
153
+ pipe_message = "CUDA"
154
+ #pipe.enable_model_cpu_offload() # official recommended method but is running slower w it
155
+ else:
156
+ print("CUDA not available")
157
+ print("using cpu")
158
+ pipe = pipe.to("cpu")
159
+ pipe_message = "CPU"
160
+ print(f"-----{pipe_message} PIPE INITIALIZED-----")
161
+ print(f"Using device: {pipe.device}")
162
+ except Exception as e:
163
+ print(f"Detailed error: {str(e)}")
164
+ return None, f"ERROR: Failed to initialize PIPE2. Details: {e}"
165
+
166
+ ########## SENDING IMG GEN TO PIPE - WORKING CODE ##########
167
+ try:
168
+ print("-----SENDING IMG GEN TO PIPE-----")
169
+ print("-----HOLD ON-----")
170
+ image = pipe(
171
+ prompt,
172
+ guidance_scale=guidance_scale,
173
+ num_inference_steps=num_inference_steps,
174
+ width=width,
175
+ height=height,
176
+ max_sequence_length=512,
177
+ #callback_on_step_end=decode_tensors,
178
+ #callback_on_step_end_tensor_inputs=["latents"],
179
+ # seed=seed
180
+ ).images[0]
181
+ #############################################################
182
+
183
+ print("-----IMAGE GENERATED SUCCESSFULLY!-----")
184
+ print(image)
185
+
186
+ except Exception as e:
187
+ return f"ERROR: Failed to initialize InferenceClient. Details: {e}"
188
+
189
+ try:
190
+ # Save the image with a timestamped filename
191
+ print("-----SAVING-----", image)
192
+
193
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
194
+ output_filename = f"/data/LS_images/{timestamp}_{seed}_{model_alias.replace(' ', '_').lower()}_{prompt_alias.replace(' ', '_').lower()}_{characer_dropdown.replace(' ', '_').lower()}.png"
195
+ try:
196
+ image.save(output_filename)
197
+ except Exception as e:
198
+ return None, f"ERROR: Failed to save image. Details: {e}"
199
+ print("-----DONE!-----")
200
+ print("-----CALL THE BANNERS!-----")
201
+
202
+ except Exception as e:
203
+ print(f"ERROR: Failed to save image. Details: {e}")
204
+ # Return the filename and success message
205
+ return image, "Image generated successfully!"
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  images/
 
2
  .venv/
 
1
  images/
2
+ LS_images/
3
  .venv/
adventurers_data.json CHANGED
@@ -2,32 +2,32 @@
2
  "data": {
3
  "adventurers": [
4
  {
5
- "owner": "0x5182d69e155054d4852c775f3da3df704fd12fd77ebcc97b0a4ec3d619f60e6",
6
- "id": 463,
7
- "name": "The Syndicate #140",
8
- "strength": 0,
9
- "vitality": 2,
10
- "dexterity": 0,
11
- "intelligence": 1,
12
- "wisdom": 4,
13
- "charisma": 2,
14
- "level": 2,
15
- "xp": 4,
16
  "health": 0,
17
- "beastHealth": 0,
18
- "head": null,
19
- "hand": null,
20
- "chest": null,
21
- "waist": null,
22
- "foot": null,
23
- "weapon": "Wand",
24
- "gold": 25,
25
  "neck": null,
26
  "ring": null,
27
- "luck": 0,
28
  "battleActionCount": 0,
29
  "customRenderer": null,
30
- "statUpgrades": 1
31
  }
32
  ]
33
  }
 
2
  "data": {
3
  "adventurers": [
4
  {
5
+ "owner": "0x16c8b6168e8853b6bcc67f046f67d37abf214eb90172f1b184583d46541ed68",
6
+ "id": 750,
7
+ "name": "Blobert #736",
8
+ "strength": 3,
9
+ "vitality": 1,
10
+ "dexterity": 2,
11
+ "intelligence": 0,
12
+ "wisdom": 3,
13
+ "charisma": 4,
14
+ "level": 5,
15
+ "xp": 28,
16
  "health": 0,
17
+ "beastHealth": 74,
18
+ "head": "Helm",
19
+ "hand": "Gloves",
20
+ "chest": "Shirt",
21
+ "waist": "Sash",
22
+ "foot": "Heavy Boots",
23
+ "weapon": "Grimoire",
24
+ "gold": 0,
25
  "neck": null,
26
  "ring": null,
27
+ "luck": 2,
28
  "battleActionCount": 0,
29
  "customRenderer": null,
30
+ "statUpgrades": 0
31
  }
32
  ]
33
  }
adventurers_data2.json CHANGED
@@ -2,12 +2,12 @@
2
  "data": {
3
  "battles": [
4
  {
5
- "adventurerId": 463,
6
  "adventurerHealth": 90,
7
- "beast": "Orc",
8
  "beastHealth": 3,
9
  "beastLevel": 1,
10
- "seed": "0x1cf",
11
  "attacker": "Beast",
12
  "fled": false,
13
  "damageDealt": 0,
@@ -17,12 +17,12 @@
17
  "xpEarnedAdventurer": 0,
18
  "xpEarnedItems": 0,
19
  "goldEarned": 0,
20
- "discoveryTime": "2024-09-10T18:35:14.764Z"
21
  },
22
  {
23
- "adventurerId": 463,
24
  "adventurerHealth": 90,
25
- "beast": "Orc",
26
  "beastHealth": 0,
27
  "beastLevel": 1,
28
  "seed": "0x5a60e008",
@@ -35,7 +35,133 @@
35
  "xpEarnedAdventurer": 4,
36
  "xpEarnedItems": 8,
37
  "goldEarned": 0,
38
- "discoveryTime": "2024-09-10T18:41:37.103Z"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  }
40
  ]
41
  }
 
2
  "data": {
3
  "battles": [
4
  {
5
+ "adventurerId": 750,
6
  "adventurerHealth": 90,
7
+ "beast": "Bear",
8
  "beastHealth": 3,
9
  "beastLevel": 1,
10
+ "seed": "0x2ee",
11
  "attacker": "Beast",
12
  "fled": false,
13
  "damageDealt": 0,
 
17
  "xpEarnedAdventurer": 0,
18
  "xpEarnedItems": 0,
19
  "goldEarned": 0,
20
+ "discoveryTime": "2024-09-10T18:36:03.159Z"
21
  },
22
  {
23
+ "adventurerId": 750,
24
  "adventurerHealth": 90,
25
+ "beast": "Spider",
26
  "beastHealth": 0,
27
  "beastLevel": 1,
28
  "seed": "0x5a60e008",
 
35
  "xpEarnedAdventurer": 4,
36
  "xpEarnedItems": 8,
37
  "goldEarned": 0,
38
+ "discoveryTime": "2024-09-17T00:38:39.843Z"
39
+ },
40
+ {
41
+ "adventurerId": 750,
42
+ "adventurerHealth": 107,
43
+ "beast": "Golem",
44
+ "beastHealth": 0,
45
+ "beastLevel": 6,
46
+ "seed": "0xc7bea6f8",
47
+ "attacker": "Adventurer",
48
+ "fled": true,
49
+ "damageDealt": 0,
50
+ "criticalHit": false,
51
+ "damageTaken": 0,
52
+ "damageLocation": null,
53
+ "xpEarnedAdventurer": 0,
54
+ "xpEarnedItems": 0,
55
+ "goldEarned": 0,
56
+ "discoveryTime": "2024-09-17T00:44:32.620Z"
57
+ },
58
+ {
59
+ "adventurerId": 750,
60
+ "adventurerHealth": 99,
61
+ "beast": "Leprechaun",
62
+ "beastHealth": 22,
63
+ "beastLevel": 9,
64
+ "seed": "0x46fe05ca",
65
+ "attacker": "Adventurer",
66
+ "fled": false,
67
+ "damageDealt": 0,
68
+ "criticalHit": false,
69
+ "damageTaken": 0,
70
+ "damageLocation": null,
71
+ "xpEarnedAdventurer": 0,
72
+ "xpEarnedItems": 0,
73
+ "goldEarned": 0,
74
+ "discoveryTime": "2024-09-17T00:47:42.533Z"
75
+ },
76
+ {
77
+ "adventurerId": 750,
78
+ "adventurerHealth": 99,
79
+ "beast": "Leprechaun",
80
+ "beastHealth": 22,
81
+ "beastLevel": 9,
82
+ "seed": "0x46fe05ca",
83
+ "attacker": "Beast",
84
+ "fled": false,
85
+ "damageDealt": 0,
86
+ "criticalHit": true,
87
+ "damageTaken": 16,
88
+ "damageLocation": "Waist",
89
+ "xpEarnedAdventurer": 0,
90
+ "xpEarnedItems": 0,
91
+ "goldEarned": 0,
92
+ "discoveryTime": "2024-09-17T00:47:42.533Z"
93
+ },
94
+ {
95
+ "adventurerId": 750,
96
+ "adventurerHealth": 92,
97
+ "beast": "Leprechaun",
98
+ "beastHealth": 22,
99
+ "beastLevel": 9,
100
+ "seed": "0x46fe05ca",
101
+ "attacker": "Adventurer",
102
+ "fled": false,
103
+ "damageDealt": 0,
104
+ "criticalHit": false,
105
+ "damageTaken": 0,
106
+ "damageLocation": null,
107
+ "xpEarnedAdventurer": 0,
108
+ "xpEarnedItems": 0,
109
+ "goldEarned": 0,
110
+ "discoveryTime": "2024-09-17T00:47:42.533Z"
111
+ },
112
+ {
113
+ "adventurerId": 750,
114
+ "adventurerHealth": 92,
115
+ "beast": "Leprechaun",
116
+ "beastHealth": 22,
117
+ "beastLevel": 9,
118
+ "seed": "0x46fe05ca",
119
+ "attacker": "Beast",
120
+ "fled": false,
121
+ "damageDealt": 0,
122
+ "criticalHit": false,
123
+ "damageTaken": 7,
124
+ "damageLocation": "Hand",
125
+ "xpEarnedAdventurer": 0,
126
+ "xpEarnedItems": 0,
127
+ "goldEarned": 0,
128
+ "discoveryTime": "2024-09-17T00:47:42.533Z"
129
+ },
130
+ {
131
+ "adventurerId": 750,
132
+ "adventurerHealth": 92,
133
+ "beast": "Leprechaun",
134
+ "beastHealth": 0,
135
+ "beastLevel": 9,
136
+ "seed": "0x46fe05ca",
137
+ "attacker": "Adventurer",
138
+ "fled": true,
139
+ "damageDealt": 0,
140
+ "criticalHit": false,
141
+ "damageTaken": 0,
142
+ "damageLocation": null,
143
+ "xpEarnedAdventurer": 0,
144
+ "xpEarnedItems": 0,
145
+ "goldEarned": 0,
146
+ "discoveryTime": "2024-09-17T00:47:42.533Z"
147
+ },
148
+ {
149
+ "adventurerId": 750,
150
+ "adventurerHealth": 0,
151
+ "beast": "Griffin",
152
+ "beastHealth": 74,
153
+ "beastLevel": 13,
154
+ "seed": "0xe1682360",
155
+ "attacker": "Beast",
156
+ "fled": false,
157
+ "damageDealt": 0,
158
+ "criticalHit": true,
159
+ "damageTaken": 190,
160
+ "damageLocation": "Chest",
161
+ "xpEarnedAdventurer": 0,
162
+ "xpEarnedItems": 0,
163
+ "goldEarned": 0,
164
+ "discoveryTime": "2024-09-17T00:53:20.627Z"
165
  }
166
  ]
167
  }
app.py CHANGED
@@ -1,5 +1,6 @@
1
  # app.py
2
- from config.config import prompts, api_token # Direct import
 
3
  from config.models import models
4
  import gradio as gr
5
  from src.img_gen import generate_image
@@ -23,12 +24,12 @@ def gradio_interface():
23
  # Set default values for dropdowns
24
  #prompt_dropdown = gr.Dropdown(choices=[p["alias"] for p in prompts], label="Select Beast", value=prompts[0]["alias"])
25
  adventurer_id = gr.Number(label="Adventurer ID:")
26
- character_dropdown = gr.Dropdown(choices=["Portait", "Last battle", "Loot bag"], label="Select Scene", value="Portait")
27
- model_dropdown = gr.Dropdown(choices=[m["alias"] for m in models], label="Select Model", value=models[0]["alias"])
 
28
  with gr.Row():
29
  # Add a text box for custom user input (max 200 characters)
30
  custom_prompt_input = gr.Textbox(label="Custom Prompt (Optional)", placeholder="Enter additional details (max 200 chars)...", max_lines=1, max_length=200)
31
- #custom_prompt_input = f""
32
  with gr.Row():
33
  generate_button = gr.Button("Generate Image")
34
  with gr.Row():
@@ -40,9 +41,10 @@ def gradio_interface():
40
  generate_image,
41
  inputs=[adventurer_id,
42
  #prompt_dropdown,
 
 
 
43
  custom_prompt_input,
44
- character_dropdown,
45
- model_dropdown
46
  ],
47
  outputs=[output_image, status_text]
48
  )
 
1
  # app.py
2
+ # venv w python3.11
3
+ from config.config import api_token # Direct import
4
  from config.models import models
5
  import gradio as gr
6
  from src.img_gen import generate_image
 
24
  # Set default values for dropdowns
25
  #prompt_dropdown = gr.Dropdown(choices=[p["alias"] for p in prompts], label="Select Beast", value=prompts[0]["alias"])
26
  adventurer_id = gr.Number(label="Adventurer ID:")
27
+ #character_dropdown = gr.Dropdown(choices=["Wizard", "Hunter", "Warrior"], label="Select Character Type", value="Wizard")
28
+ scene_dropdown = gr.Dropdown(choices=["Adventurer Portait", "Beast Portait", "Last Battle", "Loot Bag"], label="Select Scene", value="Adventurer Portait")
29
+ #model_dropdown = gr.Dropdown(choices=[m["alias"] for m in models], label="Select Model", value=models[0]["alias"])
30
  with gr.Row():
31
  # Add a text box for custom user input (max 200 characters)
32
  custom_prompt_input = gr.Textbox(label="Custom Prompt (Optional)", placeholder="Enter additional details (max 200 chars)...", max_lines=1, max_length=200)
 
33
  with gr.Row():
34
  generate_button = gr.Button("Generate Image")
35
  with gr.Row():
 
41
  generate_image,
42
  inputs=[adventurer_id,
43
  #prompt_dropdown,
44
+ #character_dropdown,
45
+ scene_dropdown,
46
+ #model_dropdown,
47
  custom_prompt_input,
 
 
48
  ],
49
  outputs=[output_image, status_text]
50
  )
app_modal.py CHANGED
@@ -1,15 +1,22 @@
1
  # gradio_interface.py
2
  import gradio as gr
3
  import modal
4
- from config.config import prompts, models_modal # Indirect import
5
  #from img_gen import generate_image
6
 
7
  print("Hello from gradio_interface_head!")
8
 
9
  # Modal remote function synchronously
10
- def generate(prompt_dropdown, team_dropdown, model_dropdown, custom_prompt_input, cpu_gpu ="GPU"):
 
 
 
 
 
 
 
11
  # Debug:
12
- debug_message = f"Debug: Button clicked! Inputs - Prompt: {prompt_dropdown}, Team: {team_dropdown}, Model: {model_dropdown}, Custom Prompt: {custom_prompt_input}"
13
  print(debug_message) # Print to console for debugging
14
  try:
15
  # Check for CPU/GPU dropdown option
@@ -18,11 +25,14 @@ def generate(prompt_dropdown, team_dropdown, model_dropdown, custom_prompt_input
18
  else:
19
  f = modal.Function.from_name("LS-img-gen-modal", "generate_image_cpu")
20
 
 
21
  # Import the remote function
22
  image_path, message = f.remote(
23
- prompt_dropdown,
24
- team_dropdown,
25
- model_dropdown,
 
 
26
  custom_prompt_input,
27
  )
28
  return image_path, message
@@ -46,12 +56,14 @@ def gradio_interface():
46
  gr.Markdown("# ========== Loot Survivor - AI Image Generator ==========")
47
  with gr.Row():
48
  # Set default values for dropdowns
49
- prompt_dropdown = gr.Dropdown(choices=[p["alias"] for p in prompts], label="Select Beast", value=prompts[0]["alias"])
50
- character_dropdown = gr.Dropdown(choices=["Beast only", "Wizard", "Warrior"], label="Select Character", value="Beast only")
51
- model_dropdown = gr.Dropdown(choices=[m["alias"] for m in models_modal], label="Select Model", value=models_modal[0]["alias"])
 
 
52
  with gr.Row():
53
  # Add a text box for custom user input (max 200 characters)
54
- custom_prompt_input = gr.Textbox(label="Custom Prompt (Optional)", placeholder="Enter additional details (max 200 chars)...", max_lines=1, max_length=200)
55
  with gr.Row():
56
  generate_button = gr.Button("Generate Image")
57
  with gr.Row():
@@ -59,17 +71,15 @@ def gradio_interface():
59
  with gr.Row():
60
  status_text = gr.Textbox(label="Status", placeholder="Waiting for input...", interactive=False)
61
 
62
-
63
- # Import the remote function
64
- f = modal.Function.from_name("img-gen-modal-gpu", "generate_image")
65
-
66
  # Connect the button to the function
67
  generate_button.click(
68
  generate,
69
- inputs=[prompt_dropdown,
 
 
 
 
70
  custom_prompt_input,
71
- character_dropdown,
72
- model_dropdown
73
  ],
74
  outputs=[output_image, status_text]
75
  )
 
1
  # gradio_interface.py
2
  import gradio as gr
3
  import modal
4
+ from config.models import models_modal # Indirect import
5
  #from img_gen import generate_image
6
 
7
  print("Hello from gradio_interface_head!")
8
 
9
  # Modal remote function synchronously
10
+ def generate(adventurer_id,
11
+ #prompt_dropdown,
12
+ #character_dropdown,
13
+ scene_dropdown,
14
+ #model_dropdown,
15
+ custom_prompt_input,
16
+ cpu_gpu ="GPU",
17
+ ):
18
  # Debug:
19
+ debug_message = f"Debug: Button clicked! Inputs - ID: {adventurer_id}, Scene: {scene_dropdown}, Custom Prompt: {custom_prompt_input}"
20
  print(debug_message) # Print to console for debugging
21
  try:
22
  # Check for CPU/GPU dropdown option
 
25
  else:
26
  f = modal.Function.from_name("LS-img-gen-modal", "generate_image_cpu")
27
 
28
+ print ("Sending to external function")
29
  # Import the remote function
30
  image_path, message = f.remote(
31
+ adventurer_id,
32
+ #prompt_dropdown,
33
+ #character_dropdown,
34
+ scene_dropdown,
35
+ #model_dropdown,
36
  custom_prompt_input,
37
  )
38
  return image_path, message
 
56
  gr.Markdown("# ========== Loot Survivor - AI Image Generator ==========")
57
  with gr.Row():
58
  # Set default values for dropdowns
59
+ #prompt_dropdown = gr.Dropdown(choices=[p["alias"] for p in prompts], label="Select Beast", value=prompts[0]["alias"])
60
+ adventurer_id = gr.Number(label="Adventurer ID:")
61
+ #character_dropdown = gr.Dropdown(choices=["Wizard", "Hunter", "Warrior"], label="Select Character Type", value="Wizard")
62
+ scene_dropdown = gr.Dropdown(choices=["Adventurer Portait", "Beast Portait", "Last Battle", "Loot Bag"], label="Select Scene", value="Adventurer Portait")
63
+ #model_dropdown = gr.Dropdown(choices=[m["alias"] for m in models_modal], label="Select Model", value=models_modal[0]["alias"])
64
  with gr.Row():
65
  # Add a text box for custom user input (max 200 characters)
66
+ custom_prompt_input = gr.Textbox(label="Custom Prompt (Optional)", placeholder="Enter additional details (max 200 chars)...", max_lines=1, max_length=200)
67
  with gr.Row():
68
  generate_button = gr.Button("Generate Image")
69
  with gr.Row():
 
71
  with gr.Row():
72
  status_text = gr.Textbox(label="Status", placeholder="Waiting for input...", interactive=False)
73
 
 
 
 
 
74
  # Connect the button to the function
75
  generate_button.click(
76
  generate,
77
+ inputs=[adventurer_id,
78
+ #prompt_dropdown,
79
+ #character_dropdown,
80
+ scene_dropdown,
81
+ #model_dropdown,
82
  custom_prompt_input,
 
 
83
  ],
84
  outputs=[output_image, status_text]
85
  )
config/__pycache__/config.cpython-310.pyc CHANGED
Binary files a/config/__pycache__/config.cpython-310.pyc and b/config/__pycache__/config.cpython-310.pyc differ
 
config/__pycache__/config.cpython-311.pyc CHANGED
Binary files a/config/__pycache__/config.cpython-311.pyc and b/config/__pycache__/config.cpython-311.pyc differ
 
config/__pycache__/models.cpython-310.pyc CHANGED
Binary files a/config/__pycache__/models.cpython-310.pyc and b/config/__pycache__/models.cpython-310.pyc differ
 
config/__pycache__/models.cpython-311.pyc CHANGED
Binary files a/config/__pycache__/models.cpython-311.pyc and b/config/__pycache__/models.cpython-311.pyc differ
 
config/__pycache__/prompts.cpython-310.pyc CHANGED
Binary files a/config/__pycache__/prompts.cpython-310.pyc and b/config/__pycache__/prompts.cpython-310.pyc differ
 
config/__pycache__/prompts.cpython-311.pyc CHANGED
Binary files a/config/__pycache__/prompts.cpython-311.pyc and b/config/__pycache__/prompts.cpython-311.pyc differ
 
config/config.py CHANGED
@@ -1,6 +1,6 @@
1
  # config.py
2
  import os
3
- from config.prompts import prompts
4
  from config.models import models_modal
5
 
6
  # Retrieve the Hugging Face token
@@ -8,5 +8,5 @@ api_token = os.getenv("HF_TOKEN")
8
 
9
  # Debugging: Print prompt and model options
10
  print("##### IMPORTING CONFIG #####")
11
- print("Prompt Options:", [p["alias"] for p in prompts])
12
  print("Model Options:", [m["alias"] for m in models_modal])
 
1
  # config.py
2
  import os
3
+ #from config.prompts import prompts
4
  from config.models import models_modal
5
 
6
  # Retrieve the Hugging Face token
 
8
 
9
  # Debugging: Print prompt and model options
10
  print("##### IMPORTING CONFIG #####")
11
+ #print("Prompt Options:", [p["alias"] for p in prompts])
12
  print("Model Options:", [m["alias"] for m in models_modal])
config/models.py CHANGED
@@ -6,8 +6,8 @@ models = [
6
 
7
  models_modal = [
8
  {"alias": "FLUX.1-dev_modal_local", "name": "FLUX.1-dev"},
 
9
  #{"alias": "FLUX.1-schnell_modal_local", "name": "FLUX.1-schnell"},
10
  #{"alias": "FLUX.1-dev", "name": "black-forest-labs/FLUX.1-dev"},
11
- #{"alias": "Midjourney", "name": "strangerzonehf/Flux-Midjourney-Mix2-LoRA"},
12
  #{"alias": "FLUX.1-schnell", "name": "black-forest-labs/FLUX.1-schnell"},
13
  ]
 
6
 
7
  models_modal = [
8
  {"alias": "FLUX.1-dev_modal_local", "name": "FLUX.1-dev"},
9
+ {"alias": "Midjourney", "name": "Flux-Midjourney-Mix2-LoRA"},
10
  #{"alias": "FLUX.1-schnell_modal_local", "name": "FLUX.1-schnell"},
11
  #{"alias": "FLUX.1-dev", "name": "black-forest-labs/FLUX.1-dev"},
 
12
  #{"alias": "FLUX.1-schnell", "name": "black-forest-labs/FLUX.1-schnell"},
13
  ]
config/prompts.py CHANGED
@@ -41,3 +41,4 @@ prompts = [
41
  }
42
  ]
43
 
 
 
41
  }
42
  ]
43
 
44
+
early_notes/ls prompts.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+
2
+ help me create a prompt for img gen . it must be a good generic prompt because i will make it dynamicaly changing a variable. The imgs are about some beasts, or monsters, that are part of a fantasy / magical / medieval world. So lets say i will have a list of spider, wolf, bear, etc. And I need a generic prompt like: A massive VARIABLE monster. and then i will dynamicaly change VARIABLE to the monster i need. Make the promot 250 tokns length, and add light details for a realistic but also exciting scene
metadata/__pycache__/metadata.cpython-311.pyc CHANGED
Binary files a/metadata/__pycache__/metadata.cpython-311.pyc and b/metadata/__pycache__/metadata.cpython-311.pyc differ
 
metadata/metadata copy.py CHANGED
@@ -63,8 +63,9 @@ if response.status_code == 200:
63
  # Print each adventurer's details dynamically
64
  for adventurer in adventurers:
65
  # Assign the 'hand' and 'head' fields to variables
66
- hand_var = adventurer.get("hand")
67
- head_var = adventurer.get("head")
 
68
 
69
  # Print the variables (for debugging)
70
  print(f"Hand: {hand_var}")
 
63
  # Print each adventurer's details dynamically
64
  for adventurer in adventurers:
65
  # Assign the 'hand' and 'head' fields to variables
66
+
67
+ head = adventurer.get("head")
68
+ hand = adventurer.get("hand")
69
 
70
  # Print the variables (for debugging)
71
  print(f"Hand: {hand_var}")
src/__pycache__/img_gen.cpython-311.pyc CHANGED
Binary files a/src/__pycache__/img_gen.cpython-311.pyc and b/src/__pycache__/img_gen.cpython-311.pyc differ
 
src/__pycache__/img_gen_modal.cpython-310.pyc CHANGED
Binary files a/src/__pycache__/img_gen_modal.cpython-310.pyc and b/src/__pycache__/img_gen_modal.cpython-310.pyc differ
 
src/__pycache__/img_gen_modal.cpython-311.pyc CHANGED
Binary files a/src/__pycache__/img_gen_modal.cpython-311.pyc and b/src/__pycache__/img_gen_modal.cpython-311.pyc differ
 
src/__pycache__/prompt_gen.cpython-311.pyc ADDED
Binary file (4.19 kB). View file
 
src/img_gen.py CHANGED
@@ -4,24 +4,27 @@ import os
4
  import random
5
  from huggingface_hub import InferenceClient, login
6
  from datetime import datetime
7
- from config.config import prompts, api_token
8
  from config.models import models
9
  from metadata.metadata import fetch_metadata
 
 
10
 
11
  def generate_image(
12
  adventurer_id,
13
  #prompt_alias,
 
 
 
14
  custom_prompt,
15
- characer_dropdown,
16
- model_alias,
17
  height=360,
18
  width=640,
19
  num_inference_steps=20,
20
  guidance_scale=2.0,
21
  seed=-1):
22
 
23
- adventurer = fetch_metadata(adventurer_id)
24
- print(f"ANDRE {adventurer['name']}")
25
 
26
  id = adventurer['id']
27
  name = adventurer['name']
@@ -31,23 +34,11 @@ def generate_image(
31
  chest_equipment = adventurer['chest']
32
  waist_equipment = adventurer['waist']
33
  foot_equipment = adventurer['foot']
 
34
  beast_last_battle = adventurer['beast']
35
 
36
- # Set the custom prompt variables
37
- if characer_dropdown == "Portait":
38
- prompt = f"A portait of a medieval, fantasy adventurer, holding a {weapon_equipment} (depending on his weapon, make the characer dressed as a warrior, or as a hunter or as a wizard). He is also equiped in the head with a {head_equipment}, the hands with {hand_equipment}, the chest with a {chest_equipment}, and the waist with a {waist_equipment}. Please be sure to use only medieval items that were possble to be made in that period. Make the adventurer unshaved and dirty, he have been figthing for days down into the dungeons. Unreal Engine render style, photorealistic, atmospheric light, realistic fantasy style."
39
-
40
- if characer_dropdown == "Last battle":
41
- prompt = f"A battle between a medieval fantasy adventurer, and a massive {beast_last_battle} monster. The adventurer is holding a weapon: a {weapon_equipment}. He is also equiped in the head with {head_equipment}, the hands with {hand_equipment}, the chest with {chest_equipment}, the waist with {waist_equipment}, the fet with {foot_equipment}. Use only medieval items that were possble to be made in that period. Add details for the monster as well. The scene location is the natural ambient of the {beast_last_battle}. Unreal Engine render style, photorealistic, realistic fantasy style."
42
-
43
- elif characer_dropdown == "Loot bag":
44
- prompt = f"A loot bag from a medieval fantasy adventurer and his equipments. On the floor also a {weapon_equipment} a {head_equipment}, a {hand_equipment}, a {chest_equipment}, a {waist_equipment}, and a {foot_equipment}. Please sure to use only medieval items that were possble to be made in that period. Inside the bag also gold coins. Atmospheric light, cavern, dungeon context. Unreal Engine render style, photorealistic, realistic fantasy style."
45
- else:
46
- pass
47
-
48
-
49
-
50
  # Find the selected prompt and model
 
51
  try:
52
  #prompt = next(p for p in prompts if p["alias"] == prompt_alias)["text"]
53
  model_name = next(m for m in models if m["alias"] == model_alias)["name"]
@@ -108,11 +99,13 @@ def generate_image(
108
  print("-----SAVING-----", image)
109
  path = "images"
110
 
111
- message = f"Image generated successfully! Call the banners! \n\n=====ADVENTURER GENERATED===== \nID: {id}\nNAME: {name}\nWEAPON: {weapon_equipment}\nHEAD: {head_equipment}\nHAND: {hand_equipment}\nCHEST: {chest_equipment}\nWAIST: {waist_equipment}\nBEAST: {beast_last_battle}"
112
- file_name_extension = f"ID: {id}\nNAME: {name}\nWEAPON: {weapon_equipment}\nHEAD: {head_equipment}\nHAND: {hand_equipment}\nCHEST: {chest_equipment}\nWAIST: {waist_equipment}\n LAST BATTLE BEAST: {beast_last_battle}"
 
113
 
114
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
115
- output_filename = f"{path}/{timestamp}_{seed}_{model_alias.replace(' ', '_').lower()}_{characer_dropdown.replace(' ', '_').lower()}_{file_name_extension.replace(' ', '_').lower()}.png"
 
116
 
117
  # output_filename = f"{path}/{timestamp}_{seed}_{model_alias.replace(' ', '_').lower()}_{prompt_alias.replace(' ', '_').lower()}_{characer_dropdown.replace(' ', '_').lower()}_{file_name_extension.replace(' ', '_').lower()}.png"
118
 
 
4
  import random
5
  from huggingface_hub import InferenceClient, login
6
  from datetime import datetime
7
+ from config.config import api_token
8
  from config.models import models
9
  from metadata.metadata import fetch_metadata
10
+ from src.prompt_gen import prompt_gen
11
+
12
 
13
  def generate_image(
14
  adventurer_id,
15
  #prompt_alias,
16
+ #character_dropdown,
17
+ scene_dropdown,
18
+ #model_alias,
19
  custom_prompt,
 
 
20
  height=360,
21
  width=640,
22
  num_inference_steps=20,
23
  guidance_scale=2.0,
24
  seed=-1):
25
 
26
+ print ("Sending to prompt gen")
27
+ adventurer, prompt = prompt_gen(adventurer_id, scene_dropdown)
28
 
29
  id = adventurer['id']
30
  name = adventurer['name']
 
34
  chest_equipment = adventurer['chest']
35
  waist_equipment = adventurer['waist']
36
  foot_equipment = adventurer['foot']
37
+ gold_equipment = adventurer['gold']
38
  beast_last_battle = adventurer['beast']
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  # Find the selected prompt and model
41
+ model_alias = "FLUX.1-dev"
42
  try:
43
  #prompt = next(p for p in prompts if p["alias"] == prompt_alias)["text"]
44
  model_name = next(m for m in models if m["alias"] == model_alias)["name"]
 
99
  print("-----SAVING-----", image)
100
  path = "images"
101
 
102
+ message = f"Image generated successfully! Call the banners! \n\n=====ADVENTURER GENERATED===== \nID: {id}\nNAME: {name}\nWEAPON: {weapon_equipment}\nHEAD: {head_equipment}\nHAND: {hand_equipment}\nCHEST: {chest_equipment}\nWAIST: {waist_equipment}\nFOOT: {foot_equipment}\nGOLD: {gold_equipment}\nLAST BATTLE BEAST: {beast_last_battle}"
103
+
104
+ file_name_extension = f"{id}_{beast_last_battle}"
105
 
106
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
107
+
108
+ output_filename = f"{path}/{timestamp}_{seed}_{model_alias.replace(' ', '_').lower()}_{scene_dropdown.replace(' ', '_').lower()}_{file_name_extension.replace(' ', '_').lower()}.png"
109
 
110
  # output_filename = f"{path}/{timestamp}_{seed}_{model_alias.replace(' ', '_').lower()}_{prompt_alias.replace(' ', '_').lower()}_{characer_dropdown.replace(' ', '_').lower()}_{file_name_extension.replace(' ', '_').lower()}.png"
111
 
src/img_gen_modal.py CHANGED
@@ -2,7 +2,8 @@
2
  import modal
3
  import random
4
  import io
5
- from config.config import prompts, api_token
 
6
  from config.models import models_modal
7
  import os
8
  import gradio as gr
@@ -19,6 +20,8 @@ from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline, Auto
19
  from PIL import Image
20
  from src.check_dependecies import check_dependencies
21
  import numpy as np
 
 
22
 
23
  MAX_SEED = np.iinfo(np.int32).max
24
  MAX_IMAGE_SIZE = 2048
@@ -59,10 +62,12 @@ flux_model_vol = modal.Volume.from_name("flux-model-vol", create_if_missing=True
59
  )
60
  # MAIN GENERATE IMAGE FUNCTION
61
  def generate_image_gpu(
62
- prompt_alias,
 
 
 
 
63
  custom_prompt,
64
- characer_dropdown,
65
- model_alias,
66
  height=360,
67
  width=640,
68
  num_inference_steps=20,
@@ -71,26 +76,44 @@ def generate_image_gpu(
71
  # Find the selected prompt and model
72
  print("Hello from LS_img_gen!")
73
 
74
- check_dependencies()
75
 
76
- try:
77
- prompt = next(p for p in prompts if p["alias"] == prompt_alias)["text"]
78
- model_name = next(m for m in models_modal if m["alias"] == model_alias)["name"]
 
 
 
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  except StopIteration:
81
  return None, "ERROR: Invalid prompt or model selected."
82
 
83
- # Print the original prompt and dynamic values for debugging
84
- print("Original Prompt:")
85
- print(prompt)
86
 
87
- # Append the custom character (if provided)
88
- if characer_dropdown == "Wizard":
89
- prompt += f" A wizard combats using powerful magic against the {prompt_alias}"
90
- elif characer_dropdown == "Warrior":
91
- prompt += f" A warrior combats using his weapons against the {prompt_alias}"
92
- else:
93
- pass
94
 
95
  # Append the custom prompt (if provided)
96
  if custom_prompt and len(custom_prompt.strip()) > 0:
@@ -142,10 +165,13 @@ def generate_image_gpu(
142
  #torch_dtype=torch.float16,
143
  #torch_dtype=torch.float32,
144
  #vae=taef1,
145
- local_files_only=True,
146
  )
147
  #torch.cuda.empty_cache()
148
 
 
 
 
149
  if torch.cuda.is_available():
150
  print("CUDA available")
151
  print("using gpu")
@@ -190,8 +216,13 @@ def generate_image_gpu(
190
  # Save the image with a timestamped filename
191
  print("-----SAVING-----", image)
192
 
 
 
 
 
193
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
194
- output_filename = f"/data/LS_images/{timestamp}_{seed}_{model_alias.replace(' ', '_').lower()}_{prompt_alias.replace(' ', '_').lower()}_{characer_dropdown.replace(' ', '_').lower()}.png"
 
195
  try:
196
  image.save(output_filename)
197
  except Exception as e:
@@ -201,5 +232,6 @@ def generate_image_gpu(
201
 
202
  except Exception as e:
203
  print(f"ERROR: Failed to save image. Details: {e}")
 
204
  # Return the filename and success message
205
- return image, "Image generated successfully!"
 
2
  import modal
3
  import random
4
  import io
5
+ from config.config import api_token
6
+ from config.prompts import prompts
7
  from config.models import models_modal
8
  import os
9
  import gradio as gr
 
20
  from PIL import Image
21
  from src.check_dependecies import check_dependencies
22
  import numpy as np
23
+ from src.prompt_gen import prompt_gen
24
+
25
 
26
  MAX_SEED = np.iinfo(np.int32).max
27
  MAX_IMAGE_SIZE = 2048
 
62
  )
63
  # MAIN GENERATE IMAGE FUNCTION
64
  def generate_image_gpu(
65
+ adventurer_id,
66
+ #prompt_alias,
67
+ #character_dropdown,
68
+ scene_dropdown,
69
+ #model_alias,
70
  custom_prompt,
 
 
71
  height=360,
72
  width=640,
73
  num_inference_steps=20,
 
76
  # Find the selected prompt and model
77
  print("Hello from LS_img_gen!")
78
 
79
+ #check_dependencies()
80
 
81
+ print ("Sending to prompt gen")
82
+ adventurer, prompt = prompt_gen(adventurer_id, scene_dropdown)
83
+
84
+ # Print the original prompt and dynamic values for debugging
85
+ print("Original Prompt:")
86
+ print(prompt)
87
 
88
+ print("Defining advanturer variables")
89
+ id = adventurer['id']
90
+ name = adventurer['name']
91
+ weapon_equipment = adventurer['weapon']
92
+ head_equipment = adventurer['head']
93
+ hand_equipment = adventurer['hand']
94
+ chest_equipment = adventurer['chest']
95
+ waist_equipment = adventurer['waist']
96
+ foot_equipment = adventurer['foot']
97
+ gold_equipment = adventurer['gold']
98
+ beast_last_battle = adventurer['beast']
99
+
100
+ print("Loading Model")
101
+ model_alias = "FLUX.1-dev"
102
+ try:
103
+ #prompt = next(p for p in prompts if p["alias"] == prompt_alias)["text"]
104
+ #model_name = next(m for m in models_modal if m["alias"] == model_alias)["name"]
105
+ model_name = model_alias
106
  except StopIteration:
107
  return None, "ERROR: Invalid prompt or model selected."
108
 
 
 
 
109
 
110
+ # # Append the custom character (if provided)
111
+ # if character_dropdown == "Wizard":
112
+ # prompt += f" A wizard combats using powerful magic against the {beast_last_battle}"
113
+ # elif character_dropdown == "Warrior":
114
+ # prompt += f" A warrior combats using his weapons against the {beast_last_battle}"
115
+ # else:
116
+ # pass
117
 
118
  # Append the custom prompt (if provided)
119
  if custom_prompt and len(custom_prompt.strip()) > 0:
 
165
  #torch_dtype=torch.float16,
166
  #torch_dtype=torch.float32,
167
  #vae=taef1,
168
+ local_files_only=False,
169
  )
170
  #torch.cuda.empty_cache()
171
 
172
+ if model_alias == "Flux-Midjourney-Mix2-LoRA":
173
+ pipe.load_lora_weights("/data/Flux-Midjourney-Mix2-LoRA")
174
+
175
  if torch.cuda.is_available():
176
  print("CUDA available")
177
  print("using gpu")
 
216
  # Save the image with a timestamped filename
217
  print("-----SAVING-----", image)
218
 
219
+ message = f"Image generated successfully! Call the banners! \n\n=====ADVENTURER GENERATED===== \nID: {id}\nNAME: {name}\nWEAPON: {weapon_equipment}\nHEAD: {head_equipment}\nHAND: {hand_equipment}\nCHEST: {chest_equipment}\nWAIST: {waist_equipment}\nFOOT: {foot_equipment}\nGOLD: {gold_equipment}\nLAST BATTLE BEAST: {beast_last_battle}"
220
+
221
+ file_name_extension = f"{id}_{beast_last_battle.replace(' ', '_').lower()}"
222
+
223
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
224
+
225
+ output_filename = f"/data/LS_images/{timestamp}_{seed}_{model_alias.replace(' ', '_').lower()}_{scene_dropdown.replace(' ', '_').lower()}_{file_name_extension.replace(' ', '_').lower()}.png"
226
  try:
227
  image.save(output_filename)
228
  except Exception as e:
 
232
 
233
  except Exception as e:
234
  print(f"ERROR: Failed to save image. Details: {e}")
235
+
236
  # Return the filename and success message
237
+ return image, message
src/old/img_gen copy 2.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # img_gen.py
2
+ import sys
3
+ import os
4
+ import random
5
+ from huggingface_hub import InferenceClient, login
6
+ from datetime import datetime
7
+ from config.config import prompts, api_token
8
+ from config.models import models
9
+ from metadata.metadata import fetch_metadata
10
+
11
+ def generate_image(
12
+ adventurer_id,
13
+ #prompt_alias,
14
+ custom_prompt,
15
+ characer_dropdown,
16
+ model_alias,
17
+ height=360,
18
+ width=640,
19
+ num_inference_steps=20,
20
+ guidance_scale=2.0,
21
+ seed=-1):
22
+
23
+ adventurer = fetch_metadata(adventurer_id)
24
+ print(f"ANDRE {adventurer['name']}")
25
+
26
+ id = adventurer['id']
27
+ name = adventurer['name']
28
+ weapon_equipment = adventurer['weapon']
29
+ head_equipment = adventurer['head']
30
+ hand_equipment = adventurer['hand']
31
+ chest_equipment = adventurer['chest']
32
+ waist_equipment = adventurer['waist']
33
+ foot_equipment = adventurer['foot']
34
+ gold_equipment = adventurer['gold']
35
+ beast_last_battle = adventurer['beast']
36
+
37
+ # Set the custom prompt variables
38
+ if characer_dropdown == "Adventurer Portait":
39
+ prompt = f"A portait of a medieval, fantasy adventurer, holding only a {weapon_equipment} (depending on his weapon, make the characer dressed as a warrior, or as a hunter or as a wizard). He is also equiped in the head with a {head_equipment}, the hands with {hand_equipment}, the chest with a {chest_equipment}, and the waist with a {waist_equipment}. Please be sure to use only medieval items that were possble to be made in that period. Make the adventurer unshaved and dirty, he have been figthing for days down into the dungeons. Unreal Engine render style, photorealistic, atmospheric light, realistic fantasy style."
40
+
41
+ if characer_dropdown == "Beast Portait":
42
+ prompt = f"A massive {beast_last_battle} stands in its natural domain—a place that reflects its primal essence. The beast's eyes burn with an eerie, intelligent light, and its powerful limbs are poised for action, as if ready to pounce or defend its territory. The air is thick with tension, and the ground is littered with signs of its dominance—broken terrain, scattered bones, or remnants of its prey. In the background, a dramatic landscape unfolds: dense forests, jagged mountains, dark caves, or misty swamps. The atmosphere is both terrifying and awe-inspiring, capturing the essence of a fantasy world where magic and monsters reign supreme. Unreal Engine render style, photorealistic, atmospheric light, realistic fantasy style."
43
+
44
+ if characer_dropdown == "Last Battle":
45
+ prompt = f"A battle between a medieval fantasy adventurer, and a massive {beast_last_battle}. The adventurer is holding only a {weapon_equipment}. He is also equiped in the head with {head_equipment}, the hands with {hand_equipment}, the chest with {chest_equipment}, the waist with {waist_equipment}, the feet with {foot_equipment}. Use only medieval items that were possble to be made in that period. The scene location is the natural ambient of the {beast_last_battle}. Unreal Engine render style, photorealistic, realistic fantasy style."
46
+
47
+ elif characer_dropdown == "Loot Bag":
48
+ prompt = f"A loot bag from a medieval fantasy adventurer and his equipments. On the floor also a {weapon_equipment} a {head_equipment}, a {hand_equipment}, a {chest_equipment}, a {waist_equipment}, and a {foot_equipment}. Please sure to use only medieval items that were possble to be made in that period. Inside the bag also {gold_equipment} gold coins. Atmospheric light, cavern, dungeon context. Unreal Engine render style, photorealistic, realistic fantasy style."
49
+ else:
50
+ pass
51
+
52
+
53
+
54
+ # Find the selected prompt and model
55
+ try:
56
+ #prompt = next(p for p in prompts if p["alias"] == prompt_alias)["text"]
57
+ model_name = next(m for m in models if m["alias"] == model_alias)["name"]
58
+
59
+ except StopIteration:
60
+ return None, "ERROR: Invalid prompt or model selected."
61
+
62
+ # Print the original prompt and dynamic values for debugging
63
+ print("Original Prompt:")
64
+ print(prompt)
65
+
66
+
67
+ # Append the custom prompt (if provided)
68
+ if custom_prompt and len(custom_prompt.strip()) > 0:
69
+ prompt += " " + custom_prompt.strip()
70
+
71
+ # Print the formatted prompt for debugging
72
+ print("\nFormatted Prompt:")
73
+ print(prompt)
74
+
75
+ # Randomize the seed if needed
76
+ if seed == -1:
77
+ seed = random.randint(0, 1000000)
78
+
79
+ # HF LOGIN
80
+ print("Initializing HF TOKEN")
81
+ print (api_token)
82
+ # login(token=api_token)
83
+ # print("model_name:")
84
+ # print(model_name)
85
+
86
+
87
+ # Initialize the InferenceClient
88
+ try:
89
+ print("-----INITIALIZING INFERENCE-----")
90
+ client = InferenceClient(model_name, token=api_token)
91
+ print("Inference activated")
92
+ except Exception as e:
93
+ return None, f"ERROR: Failed to initialize InferenceClient. Details: {e}"
94
+
95
+ #Generate the image
96
+ try:
97
+ print("-----GENERATING IMAGE-----")
98
+ print("-----HOLD ON-----")
99
+ image = client.text_to_image(
100
+ prompt,
101
+ guidance_scale=guidance_scale,
102
+ num_inference_steps=num_inference_steps,
103
+ width=width,
104
+ height=height,
105
+ seed=seed
106
+ )
107
+ print("-----IMAGE GENERATED SUCCESSFULLY!-----")
108
+ except Exception as e:
109
+ return None, f"ERROR: Failed to generate image. Details: {e}"
110
+
111
+ # Save the image with a timestamped filename
112
+ print("-----SAVING-----", image)
113
+ path = "images"
114
+
115
+ message = f"Image generated successfully! Call the banners! \n\n=====ADVENTURER GENERATED===== \nID: {id}\nNAME: {name}\nWEAPON: {weapon_equipment}\nHEAD: {head_equipment}\nHAND: {hand_equipment}\nCHEST: {chest_equipment}\nWAIST: {waist_equipment}\nLAST BATTLE BEAST: {beast_last_battle}"
116
+
117
+ file_name_extension = f"{id} {name} {weapon_equipment} {head_equipment} {hand_equipment} {chest_equipment} {waist_equipment} {beast_last_battle}"
118
+
119
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
120
+ output_filename = f"{path}/{timestamp}_{seed}_{model_alias.replace(' ', '_').lower()}_{characer_dropdown.replace(' ', '_').lower()}_{file_name_extension.replace(' ', '_').lower()}.png"
121
+
122
+ # output_filename = f"{path}/{timestamp}_{seed}_{model_alias.replace(' ', '_').lower()}_{prompt_alias.replace(' ', '_').lower()}_{characer_dropdown.replace(' ', '_').lower()}_{file_name_extension.replace(' ', '_').lower()}.png"
123
+
124
+ try:
125
+ image.save(output_filename)
126
+ except Exception as e:
127
+ return None, f"ERROR: Failed to save image. Details: {e}"
128
+ print("-----DONE!-----")
129
+ print("-----CALL THE BANNERS!-----")
130
+
131
+ return output_filename, message
src/{img_gen copy.py → old/img_gen copy.py} RENAMED
File without changes
src/prompt_gen copy 2.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from metadata.metadata import fetch_metadata
2
+
3
+ def prompt_gen(adventurer_id, character_dropdown, scene_dropdown):
4
+ adventurer = fetch_metadata(adventurer_id)
5
+ print(f"ANDRE {adventurer['name']}")
6
+
7
+ id = adventurer['id']
8
+ name = adventurer['name']
9
+ weapon_equipment = adventurer['weapon']
10
+ head_equipment = adventurer['head']
11
+ hand_equipment = adventurer['hand']
12
+ chest_equipment = adventurer['chest']
13
+ waist_equipment = adventurer['waist']
14
+ foot_equipment = adventurer['foot']
15
+ gold_equipment = adventurer['gold']
16
+ beast_last_battle = adventurer['beast']
17
+
18
+ # Check for weapon = None to fix eventual generator mistakes
19
+ if weapon_equipment == None:
20
+ weapon_sentence = "holding nothing in his hands"
21
+ else:
22
+ weapon_sentence = f"holding only a {weapon_equipment}"
23
+
24
+ if character_dropdown == "Wizard":
25
+ character_attack_sentence = f"The adventurer is attacking using powerful magic"
26
+ else:
27
+ character_attack_sentence = f"The adventurer is attacking using his {weapon_equipment}"
28
+
29
+
30
+ # Set the custom prompt variables
31
+ if scene_dropdown == "Adventurer Portait":
32
+ prompt = f"A portait of a medieval, fantasy adventurer, {weapon_sentence}. Make the adventurer dressed as a {character_dropdown}. He is also equiped in the head with a {head_equipment}, the hands with {hand_equipment}, the chest with a {chest_equipment}, and the waist with a {waist_equipment}. Please be sure to use only medieval items that were possble to be made in that period. Make the adventurer unshaved and dirty, he have been figthing for days down into the dungeons. Unreal Engine render style, photorealistic, atmospheric light, realistic fantasy style."
33
+
34
+ if scene_dropdown == "Beast Portait":
35
+ prompt = f"A massive {beast_last_battle} stands in its natural domain—a place that reflects its primal essence. The beast's eyes burn with an eerie, intelligent light, and its powerful limbs are poised for action, as if ready to pounce or defend its territory. It roars menacingly, surrounded by broken weapons and bones. In the background, a dramatic landscape unfolds: dense forests, underground dungeons, jagged mountains, dark caves, or misty swamps. The atmosphere is both terrifying and awe-inspiring, capturing the essence of a fantasy world where magic and monsters reign supreme. Unreal Engine render style, photorealistic, atmospheric light, realistic fantasy style."
36
+
37
+ if scene_dropdown == "Last Battle":
38
+ prompt = f"A battle between a medieval fantasy adventurer, and a massive {beast_last_battle}. The adventurer is {weapon_sentence}. He is also equiped in the head with {head_equipment}, the hands with {hand_equipment}, the chest with {chest_equipment}, the waist with {waist_equipment}, the feet with {foot_equipment}. Use only medieval items that were possible to be made in that period. The {beast_last_battle} stands in its natural domain—a place that reflects its primal essence. The beast's eyes burn with an eerie, intelligent light, and its powerful limbs are poised for action, as if ready to pounce or defend its territory. It roars menacingly, surrounded by broken weapons and bones. {character_attack_sentence}. In the background, a dramatic landscape unfolds: dense forests, underground dungeons, jagged mountains, dark caves, or misty swamps. The atmosphere is both terrifying and awe-inspiring, capturing the essence of a fantasy world where magic and monsters reign supreme. Unreal Engine render style, photorealistic, realistic fantasy style."
39
+
40
+ elif scene_dropdown == "Loot Bag":
41
+ prompt = f"A loot bag from a medieval fantasy adventurer and his equipments. On the floor also a {weapon_equipment} a {head_equipment}, a {hand_equipment}, a {chest_equipment}, a {waist_equipment}, and a {foot_equipment}. Please sure to use only medieval items that were possble to be made in that period. Inside the bag {gold_equipment} gold coins. Atmospheric light, cavern, dungeon context. Unreal Engine render style, photorealistic, realistic fantasy style."
42
+ else:
43
+ pass
44
+
45
+ return adventurer, prompt
46
+
src/prompt_gen copy.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from metadata.metadata import fetch_metadata
2
+
3
+ def prompt_gen(adventurer_id, characer_dropdown):
4
+ adventurer = fetch_metadata(adventurer_id)
5
+ print(f"ANDRE {adventurer['name']}")
6
+
7
+ id = adventurer['id']
8
+ name = adventurer['name']
9
+ weapon_equipment = adventurer['weapon']
10
+ head_equipment = adventurer['head']
11
+ hand_equipment = adventurer['hand']
12
+ chest_equipment = adventurer['chest']
13
+ waist_equipment = adventurer['waist']
14
+ foot_equipment = adventurer['foot']
15
+ gold_equipment = adventurer['gold']
16
+ beast_last_battle = adventurer['beast']
17
+
18
+ # Set the custom prompt variables
19
+ if characer_dropdown == "Adventurer Portait":
20
+ prompt = f"A portait of a medieval, fantasy adventurer, holding only a {weapon_equipment} (depending on his weapon, make the characer dressed as a warrior, or as a hunter or as a wizard). He is also equiped in the head with a {head_equipment}, the hands with {hand_equipment}, the chest with a {chest_equipment}, and the waist with a {waist_equipment}. Please be sure to use only medieval items that were possble to be made in that period. Make the adventurer unshaved and dirty, he have been figthing for days down into the dungeons. Unreal Engine render style, photorealistic, atmospheric light, realistic fantasy style."
21
+
22
+ if characer_dropdown == "Beast Portait":
23
+ prompt = f"A massive {beast_last_battle} stands in its natural domain—a place that reflects its primal essence. The beast's eyes burn with an eerie, intelligent light, and its powerful limbs are poised for action, as if ready to pounce or defend its territory. The air is thick with tension, and the ground is littered with signs of its dominance—broken terrain, scattered bones, or remnants of its prey. In the background, a dramatic landscape unfolds: dense forests, jagged mountains, dark caves, or misty swamps. The atmosphere is both terrifying and awe-inspiring, capturing the essence of a fantasy world where magic and monsters reign supreme. Unreal Engine render style, photorealistic, atmospheric light, realistic fantasy style."
24
+
25
+ if characer_dropdown == "Last Battle":
26
+ prompt = f"A battle between a medieval fantasy adventurer, and a massive {beast_last_battle}. The adventurer is holding only a {weapon_equipment}. He is also equiped in the head with {head_equipment}, the hands with {hand_equipment}, the chest with {chest_equipment}, the waist with {waist_equipment}, the feet with {foot_equipment}. Use only medieval items that were possible to be made in that period. The {beast_last_battle} stands in its natural domain—a place that reflects its primal essence. The beast's eyes burn with an eerie, intelligent light, and its powerful limbs are poised for action, as if ready to pounce or defend its territory. The the ground is littered with signs of its dominance—broken terrain, scattered bones, or remnants of its prey. The adventurer attacks using his {weapon_equipment} or powerful magic. In the background, a dramatic landscape unfolds: dense forests, jagged mountains, dark caves, or misty swamps. The atmosphere is both terrifying and awe-inspiring, capturing the essence of a fantasy world where magic and monsters reign supreme. Unreal Engine render style, photorealistic, realistic fantasy style."
27
+
28
+ elif characer_dropdown == "Loot Bag":
29
+ prompt = f"A loot bag from a medieval fantasy adventurer and his equipments. On the floor also a {weapon_equipment} a {head_equipment}, a {hand_equipment}, a {chest_equipment}, a {waist_equipment}, and a {foot_equipment}. Please sure to use only medieval items that were possble to be made in that period. Inside the bag also {gold_equipment} gold coins. Atmospheric light, cavern, dungeon context. Unreal Engine render style, photorealistic, realistic fantasy style."
30
+ else:
31
+ pass
32
+
33
+ return adventurer, prompt
34
+
src/prompt_gen.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from metadata.metadata import fetch_metadata
2
+
3
+ def prompt_gen(adventurer_id, scene_dropdown):
4
+ adventurer = fetch_metadata(adventurer_id)
5
+ print(f"ANDRE {adventurer['name']}")
6
+
7
+ id = adventurer['id']
8
+ name = adventurer['name']
9
+ weapon_equipment = adventurer['weapon']
10
+ head_equipment = adventurer['head']
11
+ hand_equipment = adventurer['hand']
12
+ chest_equipment = adventurer['chest']
13
+ waist_equipment = adventurer['waist']
14
+ foot_equipment = adventurer['foot']
15
+ gold_equipment = adventurer['gold']
16
+ beast_last_battle = adventurer['beast']
17
+
18
+ # Check for weapon = None to fix eventual generator mistakes
19
+ if weapon_equipment == None:
20
+ weapon_sentence = "holding nothing in his hands"
21
+ else:
22
+ weapon_sentence = f"holding only a {weapon_equipment}"
23
+
24
+ # if character_dropdown == "Wizard":
25
+ # character_attack_sentence = f"The adventurer is attacking using powerful magic"
26
+ # else:
27
+ # character_attack_sentence = f"The adventurer is attacking using his {weapon_equipment}"
28
+
29
+
30
+ # Set the custom prompt variables
31
+ if scene_dropdown == "Adventurer Portait":
32
+ prompt = f"A portait of a medieval, fantasy adventurer, {weapon_sentence} (depending on his weapon, make the character dressed as a warrior, or as a hunter or as a wizard). He is also equiped in the head with a {head_equipment}, the hands with {hand_equipment}, the chest with a {chest_equipment}, and the waist with a {waist_equipment}. Please be sure to use only medieval items that were possble to be made in that period. Make the adventurer unshaved and dirty, he have been figthing for days down into the dungeons. Low light environment. Unreal Engine render style, photorealistic, atmospheric dark light, realistic fantasy style."
33
+
34
+ if scene_dropdown == "Beast Portait":
35
+ prompt = f"A massive {beast_last_battle} stands in its natural domain—a place that reflects its primal essence. The beast's eyes burn with an eerie, intelligent light, and its powerful limbs are poised for action, as if ready to pounce or defend its territory. It roars menacingly surrounded by broken weapons and bones of his past preys. Torchlit environment, underground dungeons, or dense forests, or jagged mountains, or dark caves, or misty damp swamps. Unreal Engine render style, photorealistic, atmospheric dark lights, realistic fantasy style."
36
+
37
+ if scene_dropdown == "Last Battle":
38
+ prompt = f"A battle between a medieval fantasy adventurer, and a massive {beast_last_battle}. The adventurer is {weapon_sentence}. He is also equiped in the head with {head_equipment}, the hands with {hand_equipment}, the chest with {chest_equipment}, the waist with {waist_equipment}, the feet with {foot_equipment}. Use only medieval items that were possible to be made in that period. The {beast_last_battle} stands in its natural domain—a place that reflects its primal essence. The beast's eyes burn with an eerie, intelligent light, and its powerful limbs are poised for action, as if ready to pounce or defend its territory. It roars menacingly, surrounded by broken weapons and bones. The adventurer attacks using his {weapon_equipment} or powerful magic. Torchlit environment, underground dungeons, or dense forests, or jagged mountains, or dark caves, or misty damp swamps. Unreal Engine render style, photorealistic, realistic fantasy style."
39
+
40
+ elif scene_dropdown == "Loot Bag":
41
+ prompt = f"A loot bag from a medieval fantasy adventurer and his equipments. On the floor also a {weapon_equipment} a {head_equipment}, a {hand_equipment}, a {chest_equipment}, a {waist_equipment}, and a {foot_equipment}. Please sure to use only medieval items that were possble to be made in that period. Inside the bag {gold_equipment} gold coins. Atmospheric light, cavern, dungeon context. Torchlit environment. Unreal Engine render style, photorealistic, realistic fantasy style."
42
+ else:
43
+ pass
44
+
45
+ return adventurer, prompt
46
+
src/temp.py CHANGED
@@ -13,4 +13,9 @@ Dungeon context, stones, fire and low light.
13
  elif characer_dropdown == "Loot bag":
14
  prompt = f"A loot bag from a medieval fantasy adventurer and his equipments. On the floor also a {weapon_equipment} a {head_equipment}, a {hand_equipment}, a {chest_equipment}, a {waist_equipment}, and a {foot_equipment}. Please sure to use only medieval items that were possble to be made in that period. Inside the bag also gold coins. Atmospheric light, cavern, dungeon context. Unreal Engine render style, photorealistic, realistic fantasy style."
15
  else:
16
- pass
 
 
 
 
 
 
13
  elif characer_dropdown == "Loot bag":
14
  prompt = f"A loot bag from a medieval fantasy adventurer and his equipments. On the floor also a {weapon_equipment} a {head_equipment}, a {hand_equipment}, a {chest_equipment}, a {waist_equipment}, and a {foot_equipment}. Please sure to use only medieval items that were possble to be made in that period. Inside the bag also gold coins. Atmospheric light, cavern, dungeon context. Unreal Engine render style, photorealistic, realistic fantasy style."
15
  else:
16
+ pass
17
+
18
+
19
+
20
+ keywords:
21
+ - Torchlit environment
tools/__pycache__/create_dir.cpython-311.pyc ADDED
Binary file (2.42 kB). View file
 
tools/__pycache__/download_models_modal_HF.cpython-311.pyc ADDED
Binary file (1.97 kB). View file
 
tools/clean_filenames.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+
4
+ # Define the directory containing the files
5
+ directory = "images/temp/"
6
+
7
+ # Function to clean file names
8
+ def clean_filename(filename):
9
+ # Replace spaces, special characters, and non-alphanumeric characters with underscores
10
+ cleaned_name = re.sub(r'[^a-zA-Z0-9_.-]', '_', filename)
11
+ return cleaned_name
12
+
13
+ # Loop through files in the directory
14
+ for filename in os.listdir(directory):
15
+ # Get the full path of the file
16
+ full_path = os.path.join(directory, filename)
17
+
18
+ # Skip directories (if any)
19
+ if os.path.isfile(full_path):
20
+ # Clean the file name
21
+ new_name = clean_filename(filename)
22
+
23
+ # Rename the file
24
+ new_full_path = os.path.join(directory, new_name)
25
+ os.rename(full_path, new_full_path)
26
+ print(f"Renamed: {filename} -> {new_name}")
tools/create_dir.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # img_gen.py
2
+ #img_gen_modal.py
3
+ # img_gen.py
4
+ # img_gen_modal.py
5
+ import modal
6
+ import random
7
+ import io
8
+ import os
9
+
10
+
11
+ CACHE_DIR = "/model_cache"
12
+
13
+ # Define the Modal image
14
+ image = (
15
+ #modal.Image.from_registry("nvidia/cuda:12.2.0-devel-ubuntu22.04", add_python="3.9")
16
+ modal.Image.debian_slim(python_version="3.9") # Base image
17
+
18
+ .apt_install(
19
+ "git",
20
+ )
21
+ .pip_install(
22
+
23
+ )
24
+ .env(
25
+ {
26
+ "HF_HUB_ENABLE_HF_TRANSFER": "1", "HF_HOME": "HF_HOME", "HF_HUB_CACHE": CACHE_DIR
27
+ }
28
+ )
29
+ )
30
+
31
+ # Create a Modal app
32
+ app = modal.App("tools-test-dir", image=image)
33
+ with image.imports():
34
+ import os
35
+ from datetime import datetime
36
+
37
+ flux_model_vol = modal.Volume.from_name("flux-model-vol", create_if_missing=True) # Reference your volume
38
+
39
+ @app.function(volumes={"/data": flux_model_vol},
40
+ secrets=[modal.Secret.from_name("huggingface-token")],
41
+ #gpu="a100-80gb"
42
+ )
43
+ def test_dir():
44
+
45
+ import os
46
+ import urllib.request
47
+
48
+
49
+ # Define the path of the new directory
50
+ new_directory = "LS_images"
51
+
52
+ # Create the directory (and parent directories if needed)
53
+ os.makedirs(f"/data/{new_directory}", exist_ok=True)
54
+
55
+ #url = "https://huggingface.co/city96/FLUX.1-dev-gguf/resolve/main/flux1-dev-Q8_0.gguf"
56
+ #urllib.request.urlretrieve(url, "/data/FLUX.1-dev-gguf/flux1-dev-Q8_0.gguf")
57
+
58
+ print("Download complete!")
59
+
60
+
61
+ #print(f"Directory created: {new_directory}")
62
+
63
+ # Get the current working directory
64
+ current_directory = os.getcwd()
65
+ # List the contents of the current directory
66
+ print("Contents of current modal directory:")
67
+ print(os.listdir(current_directory))
68
+
69
+ # VOLUME DIRECTORY
70
+ volume_directory = f"{current_directory}/data/"
71
+ print(f"Current volume directory: {volume_directory}")
72
+ print(os.listdir(volume_directory))
73
+
74
+
75
+ flux_model_vol.de
76
+
77
+
78
+
79
+
80
+
tools/download_models_modal_HF.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ################# RUN IT W MODAL RUN TO DOWNLOAD ON MODAL VOLUME ###########
2
+
3
+
4
+ import modal
5
+ import os
6
+
7
+ app = modal.App("flux-model-setup")
8
+
9
+ # Persistent volume for storing models
10
+ volume = modal.Volume.from_name("flux-model-vol", create_if_missing=True)
11
+
12
+ # Image with dependencies
13
+ download_image = (
14
+ modal.Image.debian_slim()
15
+ .pip_install("huggingface_hub[hf_transfer]", "transformers", "aria2") # aria2 for ultra-fast parallel downloads
16
+ .env({"HF_HUB_ENABLE_HF_TRANSFER": "1"}) # Enable fast Rust-based downloads
17
+ )
18
+
19
+ @app.function(
20
+ volumes={"/data": volume},
21
+ image=download_image,
22
+ secrets=[modal.Secret.from_name("huggingface-token")]
23
+ )
24
+ def download_flux():
25
+ from huggingface_hub import snapshot_download
26
+ import transformers
27
+
28
+ repo_id = "strangerzonehf/Flux-Midjourney-Mix2-LoRA"
29
+ local_dir = "/data/Flux-Midjourney-Mix2-LoRA/"
30
+
31
+ # **FASTEST METHOD:** Use max_workers for parallel download
32
+ snapshot_download(
33
+ repo_id,
34
+ local_dir=local_dir,
35
+ revision="main",
36
+ #ignore_patterns=["*.pt", "*.bin"], # Skip large model weights
37
+ max_workers=8 # Higher concurrency for parallel chunk downloads
38
+ )
39
+
40
+ transformers.utils.move_cache()
41
+ print(f"Model downloaded to {local_dir}")
42
+
43
+ @app.local_entrypoint()
44
+ def main():
45
+ download_flux.remote()