Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -293,45 +293,36 @@ def generate_grid(prompt, selected_models, custom_lora, negative_prompt, steps,
|
|
293 |
raise gr.Error("Please select at least 1 model")
|
294 |
|
295 |
# ์ด๊ธฐ ์ด๋ฏธ์ง ๋ฐฐ์ด ์์ฑ
|
296 |
-
images = []
|
297 |
total_models = len(selected_models[:4])
|
298 |
|
|
|
|
|
|
|
|
|
299 |
# ๊ฐ ๋ชจ๋ธ๋ณ๋ก ์ด๋ฏธ์ง ์์ฑ
|
300 |
for idx, model_name in enumerate(selected_models[:4]):
|
301 |
try:
|
302 |
progress((idx + 1) / total_models, f"Generating image for {model_name}...")
|
303 |
img = query(prompt, model_name, custom_lora, negative_prompt, steps, cfg_scale, seed, strength, width, height)
|
304 |
-
|
305 |
-
|
|
|
306 |
except Exception as e:
|
307 |
print(f"Error generating image for {model_name}: {str(e)}")
|
308 |
continue
|
309 |
|
310 |
-
#
|
311 |
-
if not
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
images.append(images[-1])
|
317 |
-
|
318 |
-
# ์ด๋ฏธ์ง๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ๋ก๋๋์๋์ง ํ์ธ
|
319 |
-
valid_images = []
|
320 |
-
for img in images:
|
321 |
-
try:
|
322 |
-
# ์ด๋ฏธ์ง ๋ณต์ฌ๋ณธ ์์ฑ
|
323 |
-
img_copy = img.copy()
|
324 |
-
valid_images.append(img_copy)
|
325 |
-
except Exception as e:
|
326 |
-
print(f"Error processing image: {str(e)}")
|
327 |
-
# ์ค๋ฅ๊ฐ ๋ฐ์ํ ๊ฒฝ์ฐ ๋ง์ง๋ง ์ ํจํ ์ด๋ฏธ์ง๋ก ๋์ฒด
|
328 |
-
if valid_images:
|
329 |
-
valid_images.append(valid_images[-1].copy())
|
330 |
-
else:
|
331 |
-
raise gr.Error("Failed to process images. Please try again.")
|
332 |
|
333 |
progress(1.0, "Generation complete!")
|
334 |
-
|
|
|
|
|
335 |
|
336 |
css = """
|
337 |
footer {
|
@@ -437,6 +428,8 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as dalle:
|
|
437 |
with gr.Row():
|
438 |
generate_btn = gr.Button("Generate 2x2 Grid", variant="primary", size="lg")
|
439 |
|
|
|
|
|
440 |
with gr.Row():
|
441 |
gallery = gr.Gallery(
|
442 |
label="Generated Images",
|
@@ -444,9 +437,11 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as dalle:
|
|
444 |
elem_id="gallery",
|
445 |
columns=2,
|
446 |
rows=2,
|
447 |
-
height="auto"
|
|
|
448 |
)
|
449 |
|
|
|
450 |
generate_btn.click(
|
451 |
fn=generate_grid,
|
452 |
inputs=[
|
@@ -461,10 +456,9 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as dalle:
|
|
461 |
width,
|
462 |
height
|
463 |
],
|
464 |
-
outputs=gallery
|
|
|
465 |
)
|
466 |
-
|
467 |
-
|
468 |
|
469 |
def filter_models(search_term):
|
470 |
filtered_models = [m for m in models_list if search_term.lower() in m.lower()]
|
|
|
293 |
raise gr.Error("Please select at least 1 model")
|
294 |
|
295 |
# ์ด๊ธฐ ์ด๋ฏธ์ง ๋ฐฐ์ด ์์ฑ
|
296 |
+
images = [None] * 4
|
297 |
total_models = len(selected_models[:4])
|
298 |
|
299 |
+
def update_gallery():
|
300 |
+
# None์ด ์๋ ์ด๋ฏธ์ง๋ง ํฌํจํ์ฌ ๊ฐค๋ฌ๋ฆฌ ์
๋ฐ์ดํธ
|
301 |
+
return [img for img in images if img is not None]
|
302 |
+
|
303 |
# ๊ฐ ๋ชจ๋ธ๋ณ๋ก ์ด๋ฏธ์ง ์์ฑ
|
304 |
for idx, model_name in enumerate(selected_models[:4]):
|
305 |
try:
|
306 |
progress((idx + 1) / total_models, f"Generating image for {model_name}...")
|
307 |
img = query(prompt, model_name, custom_lora, negative_prompt, steps, cfg_scale, seed, strength, width, height)
|
308 |
+
images[idx] = img
|
309 |
+
# ์ด๋ฏธ์ง๊ฐ ์์ฑ๋ ๋๋ง๋ค ๊ฐค๋ฌ๋ฆฌ ์
๋ฐ์ดํธ
|
310 |
+
yield update_gallery()
|
311 |
except Exception as e:
|
312 |
print(f"Error generating image for {model_name}: {str(e)}")
|
313 |
continue
|
314 |
|
315 |
+
# ๋จ์ ์ฌ๋กฏ์ ๋ง์ง๋ง ์์ฑ๋ ์ด๋ฏธ์ง๋ก ์ฑ์
|
316 |
+
last_valid_image = next((img for img in reversed(images) if img is not None), None)
|
317 |
+
if last_valid_image:
|
318 |
+
for i in range(len(images)):
|
319 |
+
if images[i] is None:
|
320 |
+
images[i] = last_valid_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
|
322 |
progress(1.0, "Generation complete!")
|
323 |
+
yield update_gallery()
|
324 |
+
|
325 |
+
|
326 |
|
327 |
css = """
|
328 |
footer {
|
|
|
428 |
with gr.Row():
|
429 |
generate_btn = gr.Button("Generate 2x2 Grid", variant="primary", size="lg")
|
430 |
|
431 |
+
|
432 |
+
|
433 |
with gr.Row():
|
434 |
gallery = gr.Gallery(
|
435 |
label="Generated Images",
|
|
|
437 |
elem_id="gallery",
|
438 |
columns=2,
|
439 |
rows=2,
|
440 |
+
height="auto",
|
441 |
+
preview=True, # ์ค์๊ฐ ํ๋ฆฌ๋ทฐ ํ์ฑํ
|
442 |
)
|
443 |
|
444 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
445 |
generate_btn.click(
|
446 |
fn=generate_grid,
|
447 |
inputs=[
|
|
|
456 |
width,
|
457 |
height
|
458 |
],
|
459 |
+
outputs=gallery,
|
460 |
+
show_progress=True
|
461 |
)
|
|
|
|
|
462 |
|
463 |
def filter_models(search_term):
|
464 |
filtered_models = [m for m in models_list if search_term.lower() in m.lower()]
|