Spaces:
Sleeping
Sleeping
Andre
commited on
Commit
·
4dea78d
1
Parent(s):
5ce088c
Update
Browse files- colab.ipynb +7 -8
- img_gen_logic_colab.py +4 -4
colab.ipynb
CHANGED
@@ -109,7 +109,6 @@
|
|
109 |
"# Output area to display the image\n",
|
110 |
"output = widgets.Output()\n",
|
111 |
"\n",
|
112 |
-
"# Function to handle button click event\n",
|
113 |
"def on_generate_button_clicked(b):\n",
|
114 |
" with output:\n",
|
115 |
" clear_output(wait=True) # Clear previous output\n",
|
@@ -140,7 +139,7 @@
|
|
140 |
"\n",
|
141 |
" # Generate the image\n",
|
142 |
" print(\"=== Debug: Calling generate_image ===\")\n",
|
143 |
-
" image
|
144 |
" selected_prompt, selected_team, selected_model, height, width,\n",
|
145 |
" num_inference_steps, guidance_scale, seed, custom_prompt, api_token,\n",
|
146 |
" randomize_seed=randomize_seed_checkbox.value\n",
|
@@ -148,10 +147,13 @@
|
|
148 |
"\n",
|
149 |
" # Debug: Check the output of generate_image\n",
|
150 |
" print(\"=== Debug: generate_image Output ===\")\n",
|
151 |
-
" print(f\"
|
152 |
" print(\"====================================\")\n",
|
153 |
"\n",
|
154 |
-
" if image
|
|
|
|
|
|
|
155 |
" # Debug: Indicate that the image is being displayed and saved\n",
|
156 |
" print(\"=== Debug: Image Generation ===\")\n",
|
157 |
" print(\"Image generated successfully!\")\n",
|
@@ -163,10 +165,7 @@
|
|
163 |
" # Save the image with a timestamped filename\n",
|
164 |
" output_filename = save_image(image, model_dropdown.label, prompt_dropdown.label, selected_team)\n",
|
165 |
" print(f\"Image saved as {output_filename}\")\n",
|
166 |
-
"
|
167 |
-
" print(\"=== Debug: Error ===\")\n",
|
168 |
-
" print(message)\n",
|
169 |
-
"\n",
|
170 |
"# Attach the button click event handler\n",
|
171 |
"generate_button.on_click(on_generate_button_clicked)\n",
|
172 |
"\n",
|
|
|
109 |
"# Output area to display the image\n",
|
110 |
"output = widgets.Output()\n",
|
111 |
"\n",
|
|
|
112 |
"def on_generate_button_clicked(b):\n",
|
113 |
" with output:\n",
|
114 |
" clear_output(wait=True) # Clear previous output\n",
|
|
|
139 |
"\n",
|
140 |
" # Generate the image\n",
|
141 |
" print(\"=== Debug: Calling generate_image ===\")\n",
|
142 |
+
" image = generate_image(\n",
|
143 |
" selected_prompt, selected_team, selected_model, height, width,\n",
|
144 |
" num_inference_steps, guidance_scale, seed, custom_prompt, api_token,\n",
|
145 |
" randomize_seed=randomize_seed_checkbox.value\n",
|
|
|
147 |
"\n",
|
148 |
" # Debug: Check the output of generate_image\n",
|
149 |
" print(\"=== Debug: generate_image Output ===\")\n",
|
150 |
+
" print(f\"Image: {image}\")\n",
|
151 |
" print(\"====================================\")\n",
|
152 |
"\n",
|
153 |
+
" if isinstance(image, str):\n",
|
154 |
+
" print(\"=== Debug: Error ===\")\n",
|
155 |
+
" print(image)\n",
|
156 |
+
" else:\n",
|
157 |
" # Debug: Indicate that the image is being displayed and saved\n",
|
158 |
" print(\"=== Debug: Image Generation ===\")\n",
|
159 |
" print(\"Image generated successfully!\")\n",
|
|
|
165 |
" # Save the image with a timestamped filename\n",
|
166 |
" output_filename = save_image(image, model_dropdown.label, prompt_dropdown.label, selected_team)\n",
|
167 |
" print(f\"Image saved as {output_filename}\")\n",
|
168 |
+
" \n",
|
|
|
|
|
|
|
169 |
"# Attach the button click event handler\n",
|
170 |
"generate_button.on_click(on_generate_button_clicked)\n",
|
171 |
"\n",
|
img_gen_logic_colab.py
CHANGED
@@ -22,7 +22,7 @@ def generate_image(prompt, team, model_name, height, width, num_inference_steps,
|
|
22 |
randomize_seed (bool): Whether to randomize the seed.
|
23 |
|
24 |
Returns:
|
25 |
-
|
26 |
"""
|
27 |
# Determine the enemy color
|
28 |
enemy_color = "blue" if team.lower() == "red" else "red"
|
@@ -36,7 +36,7 @@ def generate_image(prompt, team, model_name, height, width, num_inference_steps,
|
|
36 |
elif team.lower() == "blue":
|
37 |
prompt += " The winning army is dressed in blue armor and banners."
|
38 |
else:
|
39 |
-
return
|
40 |
|
41 |
# Append the custom prompt if provided
|
42 |
if custom_prompt.strip():
|
@@ -64,9 +64,9 @@ def generate_image(prompt, team, model_name, height, width, num_inference_steps,
|
|
64 |
height=height, # Height
|
65 |
seed=seed # Random seed
|
66 |
)
|
67 |
-
return image
|
68 |
except Exception as e:
|
69 |
-
return
|
70 |
|
71 |
def save_image(image, model_label, prompt_label, team):
|
72 |
"""
|
|
|
22 |
randomize_seed (bool): Whether to randomize the seed.
|
23 |
|
24 |
Returns:
|
25 |
+
PIL.Image.Image or str: The generated image or an error message.
|
26 |
"""
|
27 |
# Determine the enemy color
|
28 |
enemy_color = "blue" if team.lower() == "red" else "red"
|
|
|
36 |
elif team.lower() == "blue":
|
37 |
prompt += " The winning army is dressed in blue armor and banners."
|
38 |
else:
|
39 |
+
return "Invalid team selection. Please choose 'Red' or 'Blue'."
|
40 |
|
41 |
# Append the custom prompt if provided
|
42 |
if custom_prompt.strip():
|
|
|
64 |
height=height, # Height
|
65 |
seed=seed # Random seed
|
66 |
)
|
67 |
+
return image
|
68 |
except Exception as e:
|
69 |
+
return f"An error occurred: {e}"
|
70 |
|
71 |
def save_image(image, model_label, prompt_label, team):
|
72 |
"""
|