fantaxy commited on
Commit
e230859
1 Parent(s): 9833d94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -6
app.py CHANGED
@@ -263,15 +263,36 @@ def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7,
263
  error_message = "Model is currently loading. Please try again in a few moments."
264
  raise gr.Error(error_message)
265
 
266
- def generate_grid(prompt, selected_models, custom_lora, negative_prompt, steps, cfg_scale, seed, strength, width, height):
267
  if len(selected_models) > 4:
268
  raise gr.Error("Please select up to 4 models")
269
  if len(selected_models) == 0:
270
  raise gr.Error("Please select at least 1 model")
271
 
272
- # 초기 이미지 배열 생성 (None으로 채움)
273
  images = [None] * 4
274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  def update_gallery():
276
  return images
277
 
@@ -409,8 +430,6 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as dalle:
409
  height="auto"
410
  )
411
 
412
-
413
-
414
  generate_btn.click(
415
  fn=generate_grid,
416
  inputs=[
@@ -425,10 +444,10 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as dalle:
425
  width,
426
  height
427
  ],
428
- outputs=gallery,
429
- every=True # 중간 결과를 실시간으로 업데이트
430
  )
431
 
 
432
 
433
  def filter_models(search_term):
434
  filtered_models = [m for m in models_list if search_term.lower() in m.lower()]
 
263
  error_message = "Model is currently loading. Please try again in a few moments."
264
  raise gr.Error(error_message)
265
 
266
+ def generate_grid(prompt, selected_models, custom_lora, negative_prompt, steps, cfg_scale, seed, strength, width, height, progress=gr.Progress()):
267
  if len(selected_models) > 4:
268
  raise gr.Error("Please select up to 4 models")
269
  if len(selected_models) == 0:
270
  raise gr.Error("Please select at least 1 model")
271
 
272
+ # 초기 이미지 배열 생성
273
  images = [None] * 4
274
 
275
+ # 각 모델별로 이미지 생성
276
+ for idx, model_name in enumerate(selected_models[:4]):
277
+ try:
278
+ progress(idx / len(selected_models), f"Generating image for {model_name}...")
279
+ img = query(prompt, model_name, custom_lora, negative_prompt, steps, cfg_scale, seed, strength, width, height)
280
+ images[idx] = img
281
+ except Exception as e:
282
+ print(f"Error generating image for {model_name}: {str(e)}")
283
+ continue
284
+
285
+ # 남은 슬롯을 마지막 생성된 이미지로 채움
286
+ last_valid_image = next((img for img in reversed(images) if img is not None), None)
287
+ if last_valid_image:
288
+ for i in range(len(images)):
289
+ if images[i] is None:
290
+ images[i] = last_valid_image
291
+
292
+ progress(1.0, "Generation complete!")
293
+ return images
294
+
295
+
296
  def update_gallery():
297
  return images
298
 
 
430
  height="auto"
431
  )
432
 
 
 
433
  generate_btn.click(
434
  fn=generate_grid,
435
  inputs=[
 
444
  width,
445
  height
446
  ],
447
+ outputs=gallery
 
448
  )
449
 
450
+
451
 
452
  def filter_models(search_term):
453
  filtered_models = [m for m in models_list if search_term.lower() in m.lower()]