openfree commited on
Commit
7feb9be
·
verified ·
1 Parent(s): 8532f69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -429,13 +429,17 @@ def run_lora(prompt, image_input, image_strength, cfg_scale, steps, selected_ind
429
  progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
430
  yield image, seed, gr.update(value=progress_bar, visible=True)
431
 
 
 
432
  if final_image is None:
433
- raise gr.Error("Failed to generate image")
434
 
435
  return final_image, seed, gr.update(visible=False)
436
  except Exception as e:
437
  print(f"Error in run_lora: {str(e)}")
438
- return gr.Error(str(e)), seed, gr.update(visible=False)
 
 
439
 
440
  run_lora.zerogpu = True
441
 
@@ -492,7 +496,7 @@ def update_history(new_image, history):
492
  """Updates the history gallery with the new image."""
493
  if history is None:
494
  history = []
495
- if not isinstance(new_image, gr.Error):
496
  history.insert(0, new_image)
497
  return history
498
 
@@ -562,14 +566,13 @@ def infer_upscale(
562
  ):
563
  try:
564
  if input_image is None:
565
- return gr.Error("No input image provided"), seed
566
-
567
  if randomize_seed:
568
  seed = random.randint(0, MAX_SEED)
569
 
570
- input_image, w_original, h_original, was_resized = process_input(
571
- input_image, upscale_factor
572
- )
573
 
574
  # rescale with upscale factor
575
  w, h = input_image.size
@@ -599,14 +602,16 @@ def infer_upscale(
599
  # resize to target desired size
600
  image = image.resize((w_original * upscale_factor, h_original * upscale_factor))
601
 
 
602
  return image, seed
603
  except Exception as e:
604
  print(f"Error in infer_upscale: {str(e)}")
605
- return gr.Error(f"Upscaling failed: {str(e)}"), seed
 
606
 
607
  def check_upscale_input(input_image, *args):
608
  if input_image is None:
609
- return gr.Error("Please provide an input image for upscaling."), *args
610
  return input_image, *args
611
 
612
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as app:
@@ -759,11 +764,12 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as a
759
  inputs=[prompt, input_image, image_strength, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, randomize_seed, seed, width, height, loras_state],
760
  outputs=[result, seed, progress_bar]
761
  ).then(
762
- fn=lambda x, history: update_history(x, history) if not isinstance(x, gr.Error) else history,
763
  inputs=[result, history_gallery],
764
  outputs=history_gallery,
765
  )
766
-
 
767
  upscale_button.click(
768
  check_upscale_input,
769
  inputs=[
 
429
  progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
430
  yield image, seed, gr.update(value=progress_bar, visible=True)
431
 
432
+
433
+
434
  if final_image is None:
435
+ raise Exception("Failed to generate image")
436
 
437
  return final_image, seed, gr.update(visible=False)
438
  except Exception as e:
439
  print(f"Error in run_lora: {str(e)}")
440
+ return None, seed, gr.update(visible=False)
441
+
442
+
443
 
444
  run_lora.zerogpu = True
445
 
 
496
  """Updates the history gallery with the new image."""
497
  if history is None:
498
  history = []
499
+ if new_image is not None:
500
  history.insert(0, new_image)
501
  return history
502
 
 
566
  ):
567
  try:
568
  if input_image is None:
569
+ raise ValueError("No input image provided")
570
+
571
  if randomize_seed:
572
  seed = random.randint(0, MAX_SEED)
573
 
574
+ input_image, w_original, h_original, was_resized = process_input(input_image, upscale_factor)
575
+
 
576
 
577
  # rescale with upscale factor
578
  w, h = input_image.size
 
602
  # resize to target desired size
603
  image = image.resize((w_original * upscale_factor, h_original * upscale_factor))
604
 
605
+
606
  return image, seed
607
  except Exception as e:
608
  print(f"Error in infer_upscale: {str(e)}")
609
+ return None, seed
610
+
611
 
612
  def check_upscale_input(input_image, *args):
613
  if input_image is None:
614
+ raise gr.Error("Please provide an input image for upscaling.")
615
  return input_image, *args
616
 
617
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as app:
 
764
  inputs=[prompt, input_image, image_strength, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, randomize_seed, seed, width, height, loras_state],
765
  outputs=[result, seed, progress_bar]
766
  ).then(
767
+ fn=lambda x, history: update_history(x, history) if x is not None else history,
768
  inputs=[result, history_gallery],
769
  outputs=history_gallery,
770
  )
771
+
772
+
773
  upscale_button.click(
774
  check_upscale_input,
775
  inputs=[