Spaces:
Running
Running
Sebastiankay
commited on
Commit
•
d262ca0
1
Parent(s):
28d4a96
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,6 @@ MAX_IMAGE_SIZE = 2048
|
|
12 |
|
13 |
GROQ_APIKEY_PROMPTENHANCE = os.environ["GROQ_APIKEY_PROMPTENHANCE"]
|
14 |
|
15 |
-
|
16 |
# delete cache folder if exist and create new
|
17 |
CACHE_DIR = os.path.join(os.path.dirname(__file__), "cache")
|
18 |
IMAGE_DIR = os.path.join(CACHE_DIR, "images")
|
@@ -65,7 +64,7 @@ def groq_enhance_process(Prompt=""):
|
|
65 |
model="llama-3.1-70b-versatile",
|
66 |
messages=[SYSTEMPROMPT, {"role": "user", "content": Prompt}],
|
67 |
temperature=0.8,
|
68 |
-
max_tokens=
|
69 |
top_p=0.9,
|
70 |
stream=False,
|
71 |
stop=None,
|
@@ -135,9 +134,8 @@ def process(Prompt, image_width, image_height, image_seed, randomize_seed):
|
|
135 |
|
136 |
time.sleep(1)
|
137 |
|
138 |
-
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)
|
139 |
else:
|
140 |
-
used_seed = random.randint(0, MAX_SEED) if image_seed == 0 or randomize_seed else image_seed
|
141 |
used_model = "turbo" if int(image_width) > 1024 or int(image_height) > 1024 else "flux" # turbo, flux
|
142 |
|
143 |
timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
@@ -158,7 +156,7 @@ def process(Prompt, image_width, image_height, image_seed, randomize_seed):
|
|
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)
|
162 |
|
163 |
|
164 |
with gr.Blocks(theme=theme, css=custom_css, js=custom_js, title=title) as demo:
|
@@ -175,10 +173,8 @@ with gr.Blocks(theme=theme, css=custom_css, js=custom_js, title=title) as demo:
|
|
175 |
with gr.Row(elem_classes="image_size_selctor_wrapper"):
|
176 |
with gr.Column(scale=1):
|
177 |
with gr.Row():
|
178 |
-
|
179 |
-
|
180 |
-
# image_height = gr.Number(label="Höhe", minimum=256, maximum=MAX_IMAGE_SIZE, value=683, step=128, elem_id="image_height_selector", elem_classes="image-height-selector", scale=1)
|
181 |
-
image_height = gr.Textbox(label="Höhe", value=683, lines=1, max_lines=1, elem_id="image_height_selector", elem_classes="image-height-selector", scale=1)
|
182 |
with gr.Row():
|
183 |
image_ratio_buttons = gr.Radio(["16:9", "4:3", "3:2", "1:1"], value="3:2", label="Querformat", show_label=True, info="Die gängigsten Seitenverhältnissen.", interactive=True, elem_id="image_ratio_buttons", elem_classes="image-ratio-buttons", container=True, scale=2)
|
184 |
switch_width_height = gr.Button("", size="sm", elem_id="switch_width_height", elem_classes="switch-ratio-btn", variant="primary", scale=1)
|
@@ -207,17 +203,37 @@ with gr.Blocks(theme=theme, css=custom_css, js=custom_js, title=title) as demo:
|
|
207 |
output_url = gr.Textbox(label="Output URL", show_label=True, interactive=False, visible=False)
|
208 |
outpu_image_comment = gr.Json(visible=False)
|
209 |
output_dominant_image_color = gr.Textbox(show_label=False, elem_id="dominant_image_color", visible=True, elem_classes="output-dominant-image-color")
|
210 |
-
|
211 |
|
212 |
def switch_image_size_values(image_width, image_height):
|
213 |
return image_height, image_width
|
214 |
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
|
219 |
enhance_prompt_button.click(fn=groq_enhance_process, inputs=[text_prompt], outputs=[text_prompt])
|
220 |
random_prompt_button.click(fn=groq_enhance_process, inputs=None, outputs=[text_prompt])
|
221 |
-
|
222 |
|
223 |
demo.launch()
|
|
|
12 |
|
13 |
GROQ_APIKEY_PROMPTENHANCE = os.environ["GROQ_APIKEY_PROMPTENHANCE"]
|
14 |
|
|
|
15 |
# delete cache folder if exist and create new
|
16 |
CACHE_DIR = os.path.join(os.path.dirname(__file__), "cache")
|
17 |
IMAGE_DIR = os.path.join(CACHE_DIR, "images")
|
|
|
64 |
model="llama-3.1-70b-versatile",
|
65 |
messages=[SYSTEMPROMPT, {"role": "user", "content": Prompt}],
|
66 |
temperature=0.8,
|
67 |
+
max_tokens=1024,
|
68 |
top_p=0.9,
|
69 |
stream=False,
|
70 |
stop=None,
|
|
|
134 |
|
135 |
time.sleep(1)
|
136 |
|
137 |
+
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)
|
138 |
else:
|
|
|
139 |
used_model = "turbo" if int(image_width) > 1024 or int(image_height) > 1024 else "flux" # turbo, flux
|
140 |
|
141 |
timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
|
|
156 |
img_dominant_color = image_get_dominant_color(file_path)
|
157 |
img_width, img_height = image_get_size(file_path)
|
158 |
|
159 |
+
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)
|
160 |
|
161 |
|
162 |
with gr.Blocks(theme=theme, css=custom_css, js=custom_js, title=title) as demo:
|
|
|
173 |
with gr.Row(elem_classes="image_size_selctor_wrapper"):
|
174 |
with gr.Column(scale=1):
|
175 |
with gr.Row():
|
176 |
+
image_width = gr.Number(label="Breite", minimum=256, maximum=MAX_IMAGE_SIZE, value=1024, step=128, elem_id="image_width_selector", elem_classes="image-width-selector", scale=1)
|
177 |
+
image_height = gr.Number(label="Höhe", minimum=256, maximum=MAX_IMAGE_SIZE, value=683, step=128, elem_id="image_height_selector", elem_classes="image-height-selector", scale=1)
|
|
|
|
|
178 |
with gr.Row():
|
179 |
image_ratio_buttons = gr.Radio(["16:9", "4:3", "3:2", "1:1"], value="3:2", label="Querformat", show_label=True, info="Die gängigsten Seitenverhältnissen.", interactive=True, elem_id="image_ratio_buttons", elem_classes="image-ratio-buttons", container=True, scale=2)
|
180 |
switch_width_height = gr.Button("", size="sm", elem_id="switch_width_height", elem_classes="switch-ratio-btn", variant="primary", scale=1)
|
|
|
203 |
output_url = gr.Textbox(label="Output URL", show_label=True, interactive=False, visible=False)
|
204 |
outpu_image_comment = gr.Json(visible=False)
|
205 |
output_dominant_image_color = gr.Textbox(show_label=False, elem_id="dominant_image_color", visible=True, elem_classes="output-dominant-image-color")
|
|
|
206 |
|
207 |
def switch_image_size_values(image_width, image_height):
|
208 |
return image_height, image_width
|
209 |
|
210 |
+
def switch_image_ratio_buttons(ratio_value):
|
211 |
+
ratio_value = ratio_value.split(":")
|
212 |
+
ratio_value_new = f"{ratio_value[1]}:{ratio_value[0]}"
|
213 |
+
|
214 |
+
if ratio_value[1] > ratio_value[0]:
|
215 |
+
# Querformat
|
216 |
+
new_choises = ["16:9", "4:3", "3:2", "1:1"]
|
217 |
+
new_label = "Querformat"
|
218 |
+
elif ratio_value[1] < ratio_value[0]:
|
219 |
+
# Hochformat
|
220 |
+
new_choises = ["9:16", "3:4", "2:3", "1:1"]
|
221 |
+
new_label = "Hochformat"
|
222 |
+
|
223 |
+
return {"choices": new_choises, "value": ratio_value_new, "label": new_label, "__type__": "update"}
|
224 |
+
|
225 |
+
return image_ratio_buttons
|
226 |
|
227 |
+
switch_width_height.click(fn=switch_image_size_values, inputs=[image_width, image_height], outputs=[image_width, image_height], show_progress="hidden")
|
228 |
+
|
229 |
+
switch_width_height.click(fn=switch_image_ratio_buttons, inputs=[image_ratio_buttons], outputs=[image_ratio_buttons], show_progress="hidden")
|
230 |
+
|
231 |
+
# image_ratio_buttons = gr.Radio(["16:9", "4:3", "3:2", "1:1"], value="3:2", label="Querformat", show_label=True, info="Die gängigsten Seitenverhältnissen.", interactive=True, elem_id="image_ratio_buttons", elem_classes="image-ratio-buttons", container=True, scale=2)
|
232 |
+
|
233 |
+
run_button.click(fn=process, inputs=[text_prompt, image_width, image_height, image_seed, randomize_seed], outputs=[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])
|
234 |
|
235 |
enhance_prompt_button.click(fn=groq_enhance_process, inputs=[text_prompt], outputs=[text_prompt])
|
236 |
random_prompt_button.click(fn=groq_enhance_process, inputs=None, outputs=[text_prompt])
|
237 |
+
|
238 |
|
239 |
demo.launch()
|