Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -598,72 +598,78 @@ def infer_upscale(
|
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
-
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
|
| 602 |
loras_state = gr.State(loras)
|
| 603 |
selected_indices = gr.State([])
|
| 604 |
-
|
| 605 |
with gr.Row():
|
| 606 |
with gr.Column(scale=3):
|
| 607 |
prompt = gr.Textbox(label="Prompt", lines=1, placeholder="Type a prompt after selecting a LoRA")
|
| 608 |
with gr.Column(scale=1):
|
| 609 |
-
generate_button = gr.Button("Generate", variant="primary")
|
| 610 |
-
|
| 611 |
-
with gr.Row():
|
| 612 |
with gr.Column(scale=1, min_width=25):
|
| 613 |
-
randomize_button = gr.Button("🎲", variant="secondary")
|
| 614 |
with gr.Column(scale=8):
|
| 615 |
with gr.Row():
|
| 616 |
with gr.Column(scale=0, min_width=50):
|
| 617 |
-
lora_image_1 = gr.Image(label="LoRA 1 Image", interactive=False, width=50, height=50)
|
| 618 |
with gr.Column(scale=3, min_width=100):
|
| 619 |
selected_info_1 = gr.Markdown("Select a LoRA 1")
|
| 620 |
with gr.Column(scale=5, min_width=50):
|
| 621 |
lora_scale_1 = gr.Slider(label="LoRA 1 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
| 622 |
-
|
|
|
|
| 623 |
with gr.Column(scale=8):
|
| 624 |
with gr.Row():
|
| 625 |
with gr.Column(scale=0, min_width=50):
|
| 626 |
-
lora_image_2 = gr.Image(label="LoRA 2 Image", interactive=False, width=50, height=50)
|
| 627 |
with gr.Column(scale=3, min_width=100):
|
| 628 |
selected_info_2 = gr.Markdown("Select a LoRA 2")
|
| 629 |
with gr.Column(scale=5, min_width=50):
|
| 630 |
lora_scale_2 = gr.Slider(label="LoRA 2 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
| 631 |
-
|
| 632 |
-
|
|
|
|
| 633 |
with gr.Row():
|
| 634 |
with gr.Column():
|
| 635 |
with gr.Group():
|
| 636 |
-
with gr.Row():
|
| 637 |
-
custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path or *.safetensors public URL", placeholder="ginipick/flux-lora-eric-cat", scale=3)
|
| 638 |
-
add_custom_lora_button = gr.Button("Add Custom LoRA", scale=2)
|
| 639 |
remove_custom_lora_button = gr.Button("Remove Custom LoRA", visible=False)
|
| 640 |
-
gr.Markdown("[Check the list of FLUX LoRAs](https://huggingface.co/models?other=base_model:adapter:black-forest-labs/FLUX.1-dev)")
|
| 641 |
gallery = gr.Gallery(
|
| 642 |
[(item["image"], item["title"]) for item in loras],
|
| 643 |
label="Or pick from the LoRA Explorer gallery",
|
|
|
|
| 644 |
columns=4,
|
|
|
|
| 645 |
)
|
| 646 |
with gr.Column():
|
| 647 |
-
progress_bar = gr.Markdown(visible=False)
|
| 648 |
result = gr.Image(label="Generated Image", interactive=False)
|
| 649 |
with gr.Accordion("History", open=False):
|
| 650 |
history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain", interactive=False)
|
| 651 |
|
| 652 |
-
with gr.
|
| 653 |
-
with gr.
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
|
|
|
|
|
|
| 667 |
with gr.Row():
|
| 668 |
upscale_button = gr.Button("Upscale")
|
| 669 |
|
|
@@ -671,10 +677,34 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
|
|
| 671 |
with gr.Column(scale=4):
|
| 672 |
upscale_input = gr.Image(label="Input Image for Upscaling", type="pil")
|
| 673 |
with gr.Column(scale=1):
|
| 674 |
-
upscale_steps = gr.Slider(
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 678 |
upscale_randomize_seed = gr.Checkbox(label="Randomize seed for Upscaling", value=True)
|
| 679 |
|
| 680 |
with gr.Row():
|
|
@@ -711,15 +741,29 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
|
|
| 711 |
inputs=[selected_indices, loras_state],
|
| 712 |
outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_indices, lora_scale_1, lora_scale_2, lora_image_1, lora_image_2]
|
| 713 |
)
|
| 714 |
-
|
| 715 |
-
|
|
|
|
| 716 |
inputs=[prompt, input_image, image_strength, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, randomize_seed, seed, width, height, loras_state],
|
| 717 |
outputs=[result, seed, progress_bar]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 718 |
)
|
|
|
|
|
|
|
| 719 |
upscale_button.click(
|
| 720 |
infer_upscale,
|
| 721 |
-
inputs=[
|
| 722 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 723 |
)
|
| 724 |
|
| 725 |
if __name__ == "__main__":
|
|
|
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
+
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as app:
|
| 602 |
loras_state = gr.State(loras)
|
| 603 |
selected_indices = gr.State([])
|
| 604 |
+
|
| 605 |
with gr.Row():
|
| 606 |
with gr.Column(scale=3):
|
| 607 |
prompt = gr.Textbox(label="Prompt", lines=1, placeholder="Type a prompt after selecting a LoRA")
|
| 608 |
with gr.Column(scale=1):
|
| 609 |
+
generate_button = gr.Button("Generate", variant="primary", elem_classes=["button_total"])
|
| 610 |
+
|
| 611 |
+
with gr.Row(elem_id="loaded_loras"):
|
| 612 |
with gr.Column(scale=1, min_width=25):
|
| 613 |
+
randomize_button = gr.Button("🎲", variant="secondary", scale=1, elem_id="random_btn")
|
| 614 |
with gr.Column(scale=8):
|
| 615 |
with gr.Row():
|
| 616 |
with gr.Column(scale=0, min_width=50):
|
| 617 |
+
lora_image_1 = gr.Image(label="LoRA 1 Image", interactive=False, min_width=50, width=50, show_label=False, show_share_button=False, show_download_button=False, show_fullscreen_button=False, height=50)
|
| 618 |
with gr.Column(scale=3, min_width=100):
|
| 619 |
selected_info_1 = gr.Markdown("Select a LoRA 1")
|
| 620 |
with gr.Column(scale=5, min_width=50):
|
| 621 |
lora_scale_1 = gr.Slider(label="LoRA 1 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
| 622 |
+
with gr.Row():
|
| 623 |
+
remove_button_1 = gr.Button("Remove", size="sm")
|
| 624 |
with gr.Column(scale=8):
|
| 625 |
with gr.Row():
|
| 626 |
with gr.Column(scale=0, min_width=50):
|
| 627 |
+
lora_image_2 = gr.Image(label="LoRA 2 Image", interactive=False, min_width=50, width=50, show_label=False, show_share_button=False, show_download_button=False, show_fullscreen_button=False, height=50)
|
| 628 |
with gr.Column(scale=3, min_width=100):
|
| 629 |
selected_info_2 = gr.Markdown("Select a LoRA 2")
|
| 630 |
with gr.Column(scale=5, min_width=50):
|
| 631 |
lora_scale_2 = gr.Slider(label="LoRA 2 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
| 632 |
+
with gr.Row():
|
| 633 |
+
remove_button_2 = gr.Button("Remove", size="sm")
|
| 634 |
+
|
| 635 |
with gr.Row():
|
| 636 |
with gr.Column():
|
| 637 |
with gr.Group():
|
| 638 |
+
with gr.Row(elem_id="custom_lora_structure"):
|
| 639 |
+
custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path or *.safetensors public URL", placeholder="ginipick/flux-lora-eric-cat", scale=3, min_width=150)
|
| 640 |
+
add_custom_lora_button = gr.Button("Add Custom LoRA", elem_id="custom_lora_btn", scale=2, min_width=150)
|
| 641 |
remove_custom_lora_button = gr.Button("Remove Custom LoRA", visible=False)
|
| 642 |
+
gr.Markdown("[Check the list of FLUX LoRAs](https://huggingface.co/models?other=base_model:adapter:black-forest-labs/FLUX.1-dev)", elem_id="lora_list")
|
| 643 |
gallery = gr.Gallery(
|
| 644 |
[(item["image"], item["title"]) for item in loras],
|
| 645 |
label="Or pick from the LoRA Explorer gallery",
|
| 646 |
+
allow_preview=False,
|
| 647 |
columns=4,
|
| 648 |
+
elem_id="gallery"
|
| 649 |
)
|
| 650 |
with gr.Column():
|
| 651 |
+
progress_bar = gr.Markdown(elem_id="progress", visible=False)
|
| 652 |
result = gr.Image(label="Generated Image", interactive=False)
|
| 653 |
with gr.Accordion("History", open=False):
|
| 654 |
history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain", interactive=False)
|
| 655 |
|
| 656 |
+
with gr.Row():
|
| 657 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 658 |
+
with gr.Row():
|
| 659 |
+
input_image = gr.Image(label="Input image", type="filepath")
|
| 660 |
+
image_strength = gr.Slider(label="Denoise Strength", info="Lower means more image influence", minimum=0.1, maximum=1.0, step=0.01, value=0.75)
|
| 661 |
+
with gr.Column():
|
| 662 |
+
with gr.Row():
|
| 663 |
+
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, step=0.5, value=3.5)
|
| 664 |
+
steps = gr.Slider(label="Steps", minimum=1, maximum=50, step=1, value=28)
|
| 665 |
+
with gr.Row():
|
| 666 |
+
width = gr.Slider(label="Width", minimum=256, maximum=1536, step=64, value=1024)
|
| 667 |
+
height = gr.Slider(label="Height", minimum=256, maximum=1536, step=64, value=1024)
|
| 668 |
+
with gr.Row():
|
| 669 |
+
randomize_seed = gr.Checkbox(True, label="Randomize seed")
|
| 670 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True)
|
| 671 |
+
|
| 672 |
+
# 업스케일 관련 UI 추가
|
| 673 |
with gr.Row():
|
| 674 |
upscale_button = gr.Button("Upscale")
|
| 675 |
|
|
|
|
| 677 |
with gr.Column(scale=4):
|
| 678 |
upscale_input = gr.Image(label="Input Image for Upscaling", type="pil")
|
| 679 |
with gr.Column(scale=1):
|
| 680 |
+
upscale_steps = gr.Slider(
|
| 681 |
+
label="Number of Inference Steps for Upscaling",
|
| 682 |
+
minimum=8,
|
| 683 |
+
maximum=50,
|
| 684 |
+
step=1,
|
| 685 |
+
value=28,
|
| 686 |
+
)
|
| 687 |
+
upscale_factor = gr.Slider(
|
| 688 |
+
label="Upscale Factor",
|
| 689 |
+
minimum=1,
|
| 690 |
+
maximum=4,
|
| 691 |
+
step=1,
|
| 692 |
+
value=4,
|
| 693 |
+
)
|
| 694 |
+
controlnet_conditioning_scale = gr.Slider(
|
| 695 |
+
label="Controlnet Conditioning Scale",
|
| 696 |
+
minimum=0.1,
|
| 697 |
+
maximum=1.5,
|
| 698 |
+
step=0.1,
|
| 699 |
+
value=0.6,
|
| 700 |
+
)
|
| 701 |
+
upscale_seed = gr.Slider(
|
| 702 |
+
label="Seed for Upscaling",
|
| 703 |
+
minimum=0,
|
| 704 |
+
maximum=MAX_SEED,
|
| 705 |
+
step=1,
|
| 706 |
+
value=42,
|
| 707 |
+
)
|
| 708 |
upscale_randomize_seed = gr.Checkbox(label="Randomize seed for Upscaling", value=True)
|
| 709 |
|
| 710 |
with gr.Row():
|
|
|
|
| 741 |
inputs=[selected_indices, loras_state],
|
| 742 |
outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_indices, lora_scale_1, lora_scale_2, lora_image_1, lora_image_2]
|
| 743 |
)
|
| 744 |
+
gr.on(
|
| 745 |
+
triggers=[generate_button.click, prompt.submit],
|
| 746 |
+
fn=run_lora,
|
| 747 |
inputs=[prompt, input_image, image_strength, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, randomize_seed, seed, width, height, loras_state],
|
| 748 |
outputs=[result, seed, progress_bar]
|
| 749 |
+
).then( # Update the history gallery
|
| 750 |
+
fn=lambda x, history: update_history(x, history),
|
| 751 |
+
inputs=[result, history_gallery],
|
| 752 |
+
outputs=history_gallery,
|
| 753 |
)
|
| 754 |
+
|
| 755 |
+
# 업스케일 버튼 이벤트 추가
|
| 756 |
upscale_button.click(
|
| 757 |
infer_upscale,
|
| 758 |
+
inputs=[
|
| 759 |
+
upscale_seed,
|
| 760 |
+
upscale_randomize_seed,
|
| 761 |
+
upscale_input,
|
| 762 |
+
upscale_steps,
|
| 763 |
+
upscale_factor,
|
| 764 |
+
controlnet_conditioning_scale,
|
| 765 |
+
],
|
| 766 |
+
outputs=upscale_result,
|
| 767 |
)
|
| 768 |
|
| 769 |
if __name__ == "__main__":
|