Spaces:
Running
Running
Sebastiankay commited on
Commit ·
37581ea
1
Parent(s): 6ae3c6f
Sep 10, 2024, 6:12 PM
Browse files
app.py
CHANGED
|
@@ -129,18 +129,14 @@ def image_get_dominant_color(image_path):
|
|
| 129 |
|
| 130 |
|
| 131 |
# MARK: PROCESS IMAGE
|
| 132 |
-
def process(Prompt, image_width, image_height, image_seed, randomize_seed
|
| 133 |
-
random_prompt_value = None
|
| 134 |
if Prompt == "":
|
| 135 |
gr.Info("Kein Prompt angegeben, es wird ein zufälliger Prompt generiert.", duration=15)
|
| 136 |
Prompt = groq_enhance_process("random prompt")
|
| 137 |
-
random_prompt_value = Prompt
|
| 138 |
|
| 139 |
used_seed = random.randint(0, MAX_SEED) if image_seed == 0 or randomize_seed else image_seed
|
| 140 |
used_model = "turbo" if int(image_width) > 1024 or int(image_height) > 1024 else "flux" # turbo, flux
|
| 141 |
|
| 142 |
-
previous_prompt = Prompt if previous_prompt == Prompt else previous_prompt
|
| 143 |
-
|
| 144 |
timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
| 145 |
filename_prompt = re.sub(r"[^\w\s-]", "", Prompt).strip().replace(" ", "_")
|
| 146 |
filename = timestamp + "_" + filename_prompt[:100] + ".png"
|
|
@@ -158,7 +154,7 @@ def process(Prompt, image_width, image_height, image_seed, randomize_seed, previ
|
|
| 158 |
img_dominant_color = image_get_dominant_color(file_path)
|
| 159 |
img_width, img_height = image_get_size(file_path)
|
| 160 |
|
| 161 |
-
return ({"value": file_path, "__type__": "update"}, {"value": None, "visible": False, "__type__": "update"}, img_exif_comment, {"visible": True, "__type__": "update"}, {"value": Prompt, "visible": True, "__type__": "update"}, img_width, img_height, used_seed, {"value": file_path, "visible": True, "__type__": "update"}, img_dominant_color, used_seed
|
| 162 |
|
| 163 |
|
| 164 |
# MARK: Gradio BLOCKS UI
|
|
@@ -209,7 +205,6 @@ with gr.Blocks(theme=theme, head=custom_head, css=custom_css, js=custom_js, titl
|
|
| 209 |
outpu_image_comment = gr.Json(visible=False)
|
| 210 |
output_dominant_image_color = gr.Textbox(show_label=False, elem_id="dominant_image_color", visible=True, elem_classes="output-dominant-image-color")
|
| 211 |
image_info_tb_prompt = gr.Textbox("Bild Prompt", lines=4, max_lines=8, interactive=False, elem_classes="hide-progress", show_copy_button=True, visible=True)
|
| 212 |
-
random_promp_output = gr.Textbox(show_label=False, elem_id="random_promp_output", elem_classes="random_promp_output hide-progress", visible=True, interactive=False)
|
| 213 |
|
| 214 |
def switch_image_size_values(image_width, image_height):
|
| 215 |
return image_height, image_width
|
|
@@ -252,7 +247,7 @@ with gr.Blocks(theme=theme, head=custom_head, css=custom_css, js=custom_js, titl
|
|
| 252 |
|
| 253 |
image_ratio_buttons.input(fn=calculate_ratio_values, inputs=[image_ratio_buttons, image_width, image_height], outputs=[image_width, image_height], show_progress="hidden")
|
| 254 |
|
| 255 |
-
run_button.click(fn=process, inputs=[text_prompt, image_width, image_height, image_seed, randomize_seed
|
| 256 |
|
| 257 |
enhance_prompt_button.click(fn=groq_enhance_process, inputs=[text_prompt], outputs=[text_prompt])
|
| 258 |
random_prompt_button.click(fn=groq_enhance_process, inputs=None, outputs=[text_prompt])
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
# MARK: PROCESS IMAGE
|
| 132 |
+
def process(Prompt, image_width, image_height, image_seed, randomize_seed):
|
|
|
|
| 133 |
if Prompt == "":
|
| 134 |
gr.Info("Kein Prompt angegeben, es wird ein zufälliger Prompt generiert.", duration=15)
|
| 135 |
Prompt = groq_enhance_process("random prompt")
|
|
|
|
| 136 |
|
| 137 |
used_seed = random.randint(0, MAX_SEED) if image_seed == 0 or randomize_seed else image_seed
|
| 138 |
used_model = "turbo" if int(image_width) > 1024 or int(image_height) > 1024 else "flux" # turbo, flux
|
| 139 |
|
|
|
|
|
|
|
| 140 |
timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
| 141 |
filename_prompt = re.sub(r"[^\w\s-]", "", Prompt).strip().replace(" ", "_")
|
| 142 |
filename = timestamp + "_" + filename_prompt[:100] + ".png"
|
|
|
|
| 154 |
img_dominant_color = image_get_dominant_color(file_path)
|
| 155 |
img_width, img_height = image_get_size(file_path)
|
| 156 |
|
| 157 |
+
return ({"value": Prompt, "__type__": "update"}, {"value": file_path, "__type__": "update"}, {"value": None, "visible": False, "__type__": "update"}, img_exif_comment, {"visible": True, "__type__": "update"}, {"value": Prompt, "visible": True, "__type__": "update"}, img_width, img_height, used_seed, {"value": file_path, "visible": True, "__type__": "update"}, img_dominant_color, used_seed)
|
| 158 |
|
| 159 |
|
| 160 |
# MARK: Gradio BLOCKS UI
|
|
|
|
| 205 |
outpu_image_comment = gr.Json(visible=False)
|
| 206 |
output_dominant_image_color = gr.Textbox(show_label=False, elem_id="dominant_image_color", visible=True, elem_classes="output-dominant-image-color")
|
| 207 |
image_info_tb_prompt = gr.Textbox("Bild Prompt", lines=4, max_lines=8, interactive=False, elem_classes="hide-progress", show_copy_button=True, visible=True)
|
|
|
|
| 208 |
|
| 209 |
def switch_image_size_values(image_width, image_height):
|
| 210 |
return image_height, image_width
|
|
|
|
| 247 |
|
| 248 |
image_ratio_buttons.input(fn=calculate_ratio_values, inputs=[image_ratio_buttons, image_width, image_height], outputs=[image_width, image_height], show_progress="hidden")
|
| 249 |
|
| 250 |
+
run_button.click(fn=process, inputs=[text_prompt, image_width, image_height, image_seed, randomize_seed], outputs=[text_prompt, output_image, output_url, outpu_image_comment, image_informations, image_info_tb_prompt, image_info_tb_width, image_info_tb_height, image_info_tb_seed, image_download_button, output_dominant_image_color, image_seed])
|
| 251 |
|
| 252 |
enhance_prompt_button.click(fn=groq_enhance_process, inputs=[text_prompt], outputs=[text_prompt])
|
| 253 |
random_prompt_button.click(fn=groq_enhance_process, inputs=None, outputs=[text_prompt])
|