fantaxy commited on
Commit
0002555
โ€ข
1 Parent(s): c225692

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -30
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
- if img:
305
- images.append(img)
 
306
  except Exception as e:
307
  print(f"Error generating image for {model_name}: {str(e)}")
308
  continue
309
 
310
- # ์ตœ์†Œํ•œ ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
311
- if not images:
312
- raise gr.Error("Failed to generate any images. Please try again.")
313
-
314
- # 4๊ฐœ์˜ ์ด๋ฏธ์ง€ ์Šฌ๋กฏ์„ ์ฑ„์›€
315
- while len(images) < 4:
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
- return valid_images
 
 
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()]