Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -766,202 +766,197 @@ input:focus, textarea:focus {
|
|
766 |
margin: 0 auto !important;
|
767 |
}
|
768 |
'''
|
769 |
-
|
770 |
with gr.Blocks(theme=custom_theme, css=css, delete_cache=(60, 3600)) as app:
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
with gr.Row(elem_id="lora_gallery", equal_height=True):
|
783 |
-
gallery = gr.Gallery(
|
784 |
-
value=[(item["image"], item["title"]) for item in loras],
|
785 |
-
label="LoRA Explorer Gallery",
|
786 |
-
columns=11,
|
787 |
-
elem_id="gallery",
|
788 |
-
height=800,
|
789 |
-
object_fit="cover",
|
790 |
-
show_label=True,
|
791 |
-
allow_preview=False,
|
792 |
-
show_share_button=False,
|
793 |
-
container=True,
|
794 |
-
preview=False
|
795 |
-
)
|
796 |
-
|
797 |
-
with gr.Tab(label="Generate"):
|
798 |
-
# Prompt and Generate Button
|
799 |
-
with gr.Row():
|
800 |
-
with gr.Column(scale=3):
|
801 |
-
prompt = gr.Textbox(label="Prompt", lines=1, placeholder="Type a prompt after selecting a LoRA")
|
802 |
-
with gr.Column(scale=1):
|
803 |
-
generate_button = gr.Button("Generate", variant="primary", elem_classes=["button_total"])
|
804 |
-
|
805 |
-
# LoRA Selection Area
|
806 |
-
with gr.Row(elem_id="loaded_loras"):
|
807 |
-
# Randomize Button
|
808 |
-
with gr.Column(scale=1, min_width=25):
|
809 |
-
randomize_button = gr.Button("🎲", variant="secondary", scale=1, elem_id="random_btn")
|
810 |
-
|
811 |
-
# LoRA 1
|
812 |
-
with gr.Column(scale=8):
|
813 |
-
with gr.Row():
|
814 |
-
with gr.Column(scale=0, min_width=50):
|
815 |
-
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)
|
816 |
-
with gr.Column(scale=3, min_width=100):
|
817 |
-
selected_info_1 = gr.Markdown("Select a LoRA 1")
|
818 |
-
with gr.Column(scale=5, min_width=50):
|
819 |
-
lora_scale_1 = gr.Slider(label="LoRA 1 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
820 |
-
with gr.Row():
|
821 |
-
remove_button_1 = gr.Button("Remove", size="sm")
|
822 |
-
|
823 |
-
# LoRA 2
|
824 |
-
with gr.Column(scale=8):
|
825 |
-
with gr.Row():
|
826 |
-
with gr.Column(scale=0, min_width=50):
|
827 |
-
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)
|
828 |
-
with gr.Column(scale=3, min_width=100):
|
829 |
-
selected_info_2 = gr.Markdown("Select a LoRA 2")
|
830 |
-
with gr.Column(scale=5, min_width=50):
|
831 |
-
lora_scale_2 = gr.Slider(label="LoRA 2 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
832 |
-
with gr.Row():
|
833 |
-
remove_button_2 = gr.Button("Remove", size="sm")
|
834 |
|
835 |
-
|
836 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
837 |
with gr.Row():
|
838 |
-
|
839 |
-
|
840 |
-
with gr.Column(scale=3, min_width=100):
|
841 |
-
selected_info_3 = gr.Markdown("Select a LoRA 3")
|
842 |
-
with gr.Column(scale=5, min_width=50):
|
843 |
-
lora_scale_3 = gr.Slider(label="LoRA 3 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
844 |
with gr.Row():
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
# Result and Progress Area (10% 축소)
|
849 |
-
with gr.Column():
|
850 |
-
progress_bar = gr.Markdown(elem_id="progress", visible=False)
|
851 |
-
result = gr.Image(
|
852 |
-
label="Generated Image",
|
853 |
-
interactive=False,
|
854 |
-
elem_classes=["generated-image"],
|
855 |
-
container=True
|
856 |
-
)
|
857 |
-
with gr.Accordion("History", open=False):
|
858 |
-
history_gallery = gr.Gallery(
|
859 |
-
label="History",
|
860 |
-
columns=6,
|
861 |
-
object_fit="contain",
|
862 |
-
interactive=False,
|
863 |
-
elem_classes=["history-gallery"]
|
864 |
-
)
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
# Advanced Settings
|
869 |
-
with gr.Row():
|
870 |
-
with gr.Accordion("Advanced Settings", open=False):
|
871 |
with gr.Row():
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
triggers=[generate_button.click, prompt.submit],
|
954 |
-
fn=run_lora,
|
955 |
-
inputs=[prompt, input_image, image_strength, cfg_scale, steps,
|
956 |
-
selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
|
957 |
-
randomize_seed, seed, width, height, loras_state],
|
958 |
-
outputs=[result, seed, progress_bar]
|
959 |
-
).then(
|
960 |
-
fn=lambda x, history: update_history(x, history) if x is not None else history,
|
961 |
-
inputs=[result, history_gallery],
|
962 |
-
outputs=history_gallery
|
963 |
-
)
|
964 |
|
965 |
if __name__ == "__main__":
|
966 |
-
|
967 |
-
|
|
|
766 |
margin: 0 auto !important;
|
767 |
}
|
768 |
'''
|
|
|
769 |
with gr.Blocks(theme=custom_theme, css=css, delete_cache=(60, 3600)) as app:
|
770 |
+
loras_state = gr.State(loras)
|
771 |
+
selected_indices = gr.State([])
|
772 |
+
|
773 |
+
gr.Markdown(
|
774 |
+
"""
|
775 |
+
# MixGen3: 멀티 Lora(이미지 학습) 통합 생성 모델
|
776 |
+
### 사용 안내:
|
777 |
+
갤러리에서 원하는 모델을 선택(최대 3개까지) < 프롬프트에 한글 또는 영문으로 원하는 내용을 입력 < Generate 버튼 실행
|
778 |
+
"""
|
779 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
780 |
|
781 |
+
with gr.Row(elem_id="lora_gallery", equal_height=True):
|
782 |
+
gallery = gr.Gallery(
|
783 |
+
value=[(item["image"], item["title"]) for item in loras],
|
784 |
+
label="LoRA Explorer Gallery",
|
785 |
+
columns=11,
|
786 |
+
elem_id="gallery",
|
787 |
+
height=800,
|
788 |
+
object_fit="cover",
|
789 |
+
show_label=True,
|
790 |
+
allow_preview=False,
|
791 |
+
show_share_button=False,
|
792 |
+
container=True,
|
793 |
+
preview=False
|
794 |
+
)
|
795 |
+
|
796 |
+
with gr.Tab(label="Generate"):
|
797 |
+
# Prompt and Generate Button
|
798 |
+
with gr.Row():
|
799 |
+
with gr.Column(scale=3):
|
800 |
+
prompt = gr.Textbox(label="Prompt", lines=1, placeholder="Type a prompt after selecting a LoRA")
|
801 |
+
with gr.Column(scale=1):
|
802 |
+
generate_button = gr.Button("Generate", variant="primary", elem_classes=["button_total"])
|
803 |
+
|
804 |
+
# LoRA Selection Area
|
805 |
+
with gr.Row(elem_id="loaded_loras"):
|
806 |
+
# Randomize Button
|
807 |
+
with gr.Column(scale=1, min_width=25):
|
808 |
+
randomize_button = gr.Button("🎲", variant="secondary", scale=1, elem_id="random_btn")
|
809 |
+
|
810 |
+
# LoRA 1
|
811 |
+
with gr.Column(scale=8):
|
812 |
+
with gr.Row():
|
813 |
+
with gr.Column(scale=0, min_width=50):
|
814 |
+
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)
|
815 |
+
with gr.Column(scale=3, min_width=100):
|
816 |
+
selected_info_1 = gr.Markdown("Select a LoRA 1")
|
817 |
+
with gr.Column(scale=5, min_width=50):
|
818 |
+
lora_scale_1 = gr.Slider(label="LoRA 1 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
819 |
+
with gr.Row():
|
820 |
+
remove_button_1 = gr.Button("Remove", size="sm")
|
821 |
+
|
822 |
+
# LoRA 2
|
823 |
+
with gr.Column(scale=8):
|
824 |
+
with gr.Row():
|
825 |
+
with gr.Column(scale=0, min_width=50):
|
826 |
+
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)
|
827 |
+
with gr.Column(scale=3, min_width=100):
|
828 |
+
selected_info_2 = gr.Markdown("Select a LoRA 2")
|
829 |
+
with gr.Column(scale=5, min_width=50):
|
830 |
+
lora_scale_2 = gr.Slider(label="LoRA 2 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
831 |
+
with gr.Row():
|
832 |
+
remove_button_2 = gr.Button("Remove", size="sm")
|
833 |
+
|
834 |
+
# LoRA 3
|
835 |
+
with gr.Column(scale=8):
|
836 |
+
with gr.Row():
|
837 |
+
with gr.Column(scale=0, min_width=50):
|
838 |
+
lora_image_3 = gr.Image(label="LoRA 3 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)
|
839 |
+
with gr.Column(scale=3, min_width=100):
|
840 |
+
selected_info_3 = gr.Markdown("Select a LoRA 3")
|
841 |
+
with gr.Column(scale=5, min_width=50):
|
842 |
+
lora_scale_3 = gr.Slider(label="LoRA 3 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
|
843 |
+
with gr.Row():
|
844 |
+
remove_button_3 = gr.Button("Remove", size="sm")
|
845 |
+
|
846 |
+
# Result and Progress Area
|
847 |
+
with gr.Column():
|
848 |
+
progress_bar = gr.Markdown(elem_id="progress", visible=False)
|
849 |
+
result = gr.Image(
|
850 |
+
label="Generated Image",
|
851 |
+
interactive=False,
|
852 |
+
elem_classes=["generated-image"],
|
853 |
+
container=True
|
854 |
+
)
|
855 |
+
with gr.Accordion("History", open=False):
|
856 |
+
history_gallery = gr.Gallery(
|
857 |
+
label="History",
|
858 |
+
columns=6,
|
859 |
+
object_fit="contain",
|
860 |
+
interactive=False,
|
861 |
+
elem_classes=["history-gallery"]
|
862 |
+
)
|
863 |
+
|
864 |
+
# Advanced Settings
|
865 |
+
with gr.Row():
|
866 |
+
with gr.Accordion("Advanced Settings", open=False):
|
867 |
+
with gr.Row():
|
868 |
+
input_image = gr.Image(label="Input image", type="filepath")
|
869 |
+
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)
|
870 |
+
with gr.Column():
|
871 |
with gr.Row():
|
872 |
+
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, step=0.5, value=3.5)
|
873 |
+
steps = gr.Slider(label="Steps", minimum=1, maximum=50, step=1, value=28)
|
|
|
|
|
|
|
|
|
874 |
with gr.Row():
|
875 |
+
width = gr.Slider(label="Width", minimum=256, maximum=1536, step=64, value=1024)
|
876 |
+
height = gr.Slider(label="Height", minimum=256, maximum=1536, step=64, value=1024)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
877 |
with gr.Row():
|
878 |
+
randomize_seed = gr.Checkbox(True, label="Randomize seed")
|
879 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True)
|
880 |
+
|
881 |
+
# Custom LoRA Section
|
882 |
+
with gr.Column():
|
883 |
+
with gr.Group():
|
884 |
+
with gr.Row(elem_id="custom_lora_structure"):
|
885 |
+
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)
|
886 |
+
add_custom_lora_button = gr.Button("Add Custom LoRA", elem_id="custom_lora_btn", scale=2, min_width=150)
|
887 |
+
remove_custom_lora_button = gr.Button("Remove Custom LoRA", visible=False)
|
888 |
+
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")
|
889 |
+
|
890 |
+
# Event Handlers
|
891 |
+
gallery.select(
|
892 |
+
update_selection,
|
893 |
+
inputs=[selected_indices, loras_state, width, height],
|
894 |
+
outputs=[prompt, selected_info_1, selected_info_2, selected_info_3, selected_indices,
|
895 |
+
lora_scale_1, lora_scale_2, lora_scale_3, width, height,
|
896 |
+
lora_image_1, lora_image_2, lora_image_3]
|
897 |
+
)
|
898 |
+
|
899 |
+
remove_button_1.click(
|
900 |
+
remove_lora_1,
|
901 |
+
inputs=[selected_indices, loras_state],
|
902 |
+
outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices,
|
903 |
+
lora_scale_1, lora_scale_2, lora_scale_3,
|
904 |
+
lora_image_1, lora_image_2, lora_image_3]
|
905 |
+
)
|
906 |
+
|
907 |
+
remove_button_2.click(
|
908 |
+
remove_lora_2,
|
909 |
+
inputs=[selected_indices, loras_state],
|
910 |
+
outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices,
|
911 |
+
lora_scale_1, lora_scale_2, lora_scale_3,
|
912 |
+
lora_image_1, lora_image_2, lora_image_3]
|
913 |
+
)
|
914 |
+
|
915 |
+
remove_button_3.click(
|
916 |
+
remove_lora_3,
|
917 |
+
inputs=[selected_indices, loras_state],
|
918 |
+
outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices,
|
919 |
+
lora_scale_1, lora_scale_2, lora_scale_3,
|
920 |
+
lora_image_1, lora_image_2, lora_image_3]
|
921 |
+
)
|
922 |
+
|
923 |
+
randomize_button.click(
|
924 |
+
randomize_loras,
|
925 |
+
inputs=[selected_indices, loras_state],
|
926 |
+
outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices,
|
927 |
+
lora_scale_1, lora_scale_2, lora_scale_3,
|
928 |
+
lora_image_1, lora_image_2, lora_image_3, prompt]
|
929 |
+
)
|
930 |
+
|
931 |
+
add_custom_lora_button.click(
|
932 |
+
add_custom_lora,
|
933 |
+
inputs=[custom_lora, selected_indices, loras_state],
|
934 |
+
outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_info_3,
|
935 |
+
selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
|
936 |
+
lora_image_1, lora_image_2, lora_image_3]
|
937 |
+
)
|
938 |
+
|
939 |
+
remove_custom_lora_button.click(
|
940 |
+
remove_custom_lora,
|
941 |
+
inputs=[selected_indices, loras_state],
|
942 |
+
outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_info_3,
|
943 |
+
selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
|
944 |
+
lora_image_1, lora_image_2, lora_image_3]
|
945 |
+
)
|
946 |
+
|
947 |
+
gr.on(
|
948 |
+
triggers=[generate_button.click, prompt.submit],
|
949 |
+
fn=run_lora,
|
950 |
+
inputs=[prompt, input_image, image_strength, cfg_scale, steps,
|
951 |
+
selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
|
952 |
+
randomize_seed, seed, width, height, loras_state],
|
953 |
+
outputs=[result, seed, progress_bar]
|
954 |
+
).then(
|
955 |
+
fn=lambda x, history: update_history(x, history) if x is not None else history,
|
956 |
+
inputs=[result, history_gallery],
|
957 |
+
outputs=history_gallery
|
958 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
959 |
|
960 |
if __name__ == "__main__":
|
961 |
+
app.queue(max_size=20)
|
962 |
+
app.launch(debug=True)
|