Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -416,13 +416,12 @@ def run_lora(prompt, image_input, image_strength, cfg_scale, steps, selected_ind
|
|
| 416 |
if randomize_seed:
|
| 417 |
seed = random.randint(0, MAX_SEED)
|
| 418 |
|
|
|
|
| 419 |
# Generate image
|
| 420 |
if image_input is not None:
|
| 421 |
final_image = generate_image_to_image(prompt_mash, image_input, image_strength, steps, cfg_scale, width, height, seed)
|
| 422 |
-
return final_image, seed, gr.update(visible=False)
|
| 423 |
else:
|
| 424 |
image_generator = generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress)
|
| 425 |
-
# Consume the generator to get the final image
|
| 426 |
final_image = None
|
| 427 |
step_counter = 0
|
| 428 |
for image in image_generator:
|
|
@@ -431,13 +430,17 @@ def run_lora(prompt, image_input, image_strength, cfg_scale, steps, selected_ind
|
|
| 431 |
progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
|
| 432 |
yield image, seed, gr.update(value=progress_bar, visible=True)
|
| 433 |
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
except Exception as e:
|
| 439 |
print(f"Error in run_lora: {str(e)}")
|
| 440 |
-
return
|
| 441 |
|
| 442 |
run_lora.zerogpu = True
|
| 443 |
|
|
@@ -563,8 +566,8 @@ def infer_upscale(
|
|
| 563 |
):
|
| 564 |
try:
|
| 565 |
if input_image is None:
|
| 566 |
-
|
| 567 |
-
|
| 568 |
if randomize_seed:
|
| 569 |
seed = random.randint(0, MAX_SEED)
|
| 570 |
|
|
@@ -603,7 +606,7 @@ def infer_upscale(
|
|
| 603 |
return image, seed
|
| 604 |
except Exception as e:
|
| 605 |
print(f"Error in infer_upscale: {str(e)}")
|
| 606 |
-
return
|
| 607 |
|
| 608 |
def check_upscale_input(input_image, *args):
|
| 609 |
if input_image is None:
|
|
@@ -755,29 +758,31 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as a
|
|
| 755 |
inputs=[selected_indices, loras_state],
|
| 756 |
outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_indices, lora_scale_1, lora_scale_2, lora_image_1, lora_image_2]
|
| 757 |
)
|
| 758 |
-
|
| 759 |
gr.on(
|
| 760 |
triggers=[generate_button.click, prompt.submit],
|
| 761 |
fn=run_lora,
|
| 762 |
inputs=[prompt, input_image, image_strength, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, randomize_seed, seed, width, height, loras_state],
|
| 763 |
outputs=[result, seed, progress_bar]
|
| 764 |
).then(
|
| 765 |
-
fn=lambda x, history: update_history(x, history) if x
|
| 766 |
inputs=[result, history_gallery],
|
| 767 |
outputs=history_gallery,
|
| 768 |
)
|
| 769 |
-
|
| 770 |
-
# 업스케일 버튼 이벤트 추가 (이 부분을 gr.Blocks 컨텍스트 내부로 이동)
|
| 771 |
upscale_button.click(
|
| 772 |
-
|
| 773 |
inputs=[
|
| 774 |
-
upscale_input,
|
| 775 |
upscale_seed,
|
| 776 |
upscale_randomize_seed,
|
|
|
|
| 777 |
upscale_steps,
|
| 778 |
upscale_factor,
|
| 779 |
controlnet_conditioning_scale,
|
| 780 |
],
|
|
|
|
|
|
|
|
|
|
| 781 |
outputs=[
|
| 782 |
upscale_input,
|
| 783 |
upscale_seed,
|
|
|
|
| 416 |
if randomize_seed:
|
| 417 |
seed = random.randint(0, MAX_SEED)
|
| 418 |
|
| 419 |
+
|
| 420 |
# Generate image
|
| 421 |
if image_input is not None:
|
| 422 |
final_image = generate_image_to_image(prompt_mash, image_input, image_strength, steps, cfg_scale, width, height, seed)
|
|
|
|
| 423 |
else:
|
| 424 |
image_generator = generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress)
|
|
|
|
| 425 |
final_image = None
|
| 426 |
step_counter = 0
|
| 427 |
for image in image_generator:
|
|
|
|
| 430 |
progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
|
| 431 |
yield image, seed, gr.update(value=progress_bar, visible=True)
|
| 432 |
|
| 433 |
+
if final_image is None:
|
| 434 |
+
raise gr.Error("Failed to generate image")
|
| 435 |
+
|
| 436 |
+
return final_image, seed, gr.update(visible=False)
|
| 437 |
+
except spaces.zero.gradio.HTMLError as e:
|
| 438 |
+
if "You have exceeded your Pro GPU quota" in str(e):
|
| 439 |
+
return gr.Error("GPU quota exceeded. Please try again later."), seed, gr.update(visible=False)
|
| 440 |
+
raise
|
| 441 |
except Exception as e:
|
| 442 |
print(f"Error in run_lora: {str(e)}")
|
| 443 |
+
return gr.Error(f"An error occurred: {str(e)}"), seed, gr.update(visible=False)
|
| 444 |
|
| 445 |
run_lora.zerogpu = True
|
| 446 |
|
|
|
|
| 566 |
):
|
| 567 |
try:
|
| 568 |
if input_image is None:
|
| 569 |
+
return gr.Error("No input image provided"), seed
|
| 570 |
+
|
| 571 |
if randomize_seed:
|
| 572 |
seed = random.randint(0, MAX_SEED)
|
| 573 |
|
|
|
|
| 606 |
return image, seed
|
| 607 |
except Exception as e:
|
| 608 |
print(f"Error in infer_upscale: {str(e)}")
|
| 609 |
+
return gr.Error(f"Upscaling failed: {str(e)}"), seed
|
| 610 |
|
| 611 |
def check_upscale_input(input_image, *args):
|
| 612 |
if input_image is None:
|
|
|
|
| 758 |
inputs=[selected_indices, loras_state],
|
| 759 |
outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_indices, lora_scale_1, lora_scale_2, lora_image_1, lora_image_2]
|
| 760 |
)
|
| 761 |
+
|
| 762 |
gr.on(
|
| 763 |
triggers=[generate_button.click, prompt.submit],
|
| 764 |
fn=run_lora,
|
| 765 |
inputs=[prompt, input_image, image_strength, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, randomize_seed, seed, width, height, loras_state],
|
| 766 |
outputs=[result, seed, progress_bar]
|
| 767 |
).then(
|
| 768 |
+
fn=lambda x, history: update_history(x, history) if not isinstance(x, gr.Error) else history,
|
| 769 |
inputs=[result, history_gallery],
|
| 770 |
outputs=history_gallery,
|
| 771 |
)
|
| 772 |
+
|
|
|
|
| 773 |
upscale_button.click(
|
| 774 |
+
infer_upscale,
|
| 775 |
inputs=[
|
|
|
|
| 776 |
upscale_seed,
|
| 777 |
upscale_randomize_seed,
|
| 778 |
+
upscale_input,
|
| 779 |
upscale_steps,
|
| 780 |
upscale_factor,
|
| 781 |
controlnet_conditioning_scale,
|
| 782 |
],
|
| 783 |
+
outputs=[upscale_result, upscale_seed_output],
|
| 784 |
+
)
|
| 785 |
+
|
| 786 |
outputs=[
|
| 787 |
upscale_input,
|
| 788 |
upscale_seed,
|