openfree commited on
Commit
534651e
·
verified ·
1 Parent(s): 5284b90

Update app.py

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