openfree commited on
Commit
e25493e
·
verified ·
1 Parent(s): 925683d

Update app-backup.py

Browse files
Files changed (1) hide show
  1. app-backup.py +338 -134
app-backup.py CHANGED
@@ -522,12 +522,48 @@ def update_history(new_image, history):
522
  history.insert(0, new_image)
523
  return history
524
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
  css = '''
526
  #gen_btn{height: 100%}
527
  #title{text-align: center}
528
  #title h1{font-size: 3em; display:inline-flex; align-items:center}
529
  #title img{width: 100px; margin-right: 0.25em}
530
- #gallery .grid-wrap{height: 5vh}
531
  #lora_list{background: var(--block-background-fill);padding: 0 1em .3em; font-size: 90%}
532
  .custom_lora_card{margin-bottom: 1em}
533
  .card_internal{display: flex;height: 100px;margin-top: .5em}
@@ -543,160 +579,328 @@ css = '''
543
  #custom_lora_btn{margin-top: auto;margin-bottom: 11px}
544
  #random_btn{font-size: 300%}
545
  #component-11{align-self: stretch;}
546
- footer {visibility: hidden;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  '''
548
 
549
- with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as app:
 
550
  loras_state = gr.State(loras)
551
  selected_indices = gr.State([])
552
-
553
  gr.Markdown(
554
  """
555
  # MixGen3: 멀티 Lora(이미지 학습) 통합 생성 모델
556
-
557
  ### 사용 안내:
558
- 1) 갤러리에서 원하는 모델을 선택(최대 3개까지)
559
- 2) 프롬프트에 한글 또는 영문으로 원하는 내용을 입력
560
- 3) Generate 버튼 실행
561
-
562
- ### Contacts: arxivgpt@gmail.com
563
  """
564
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
565
 
566
- with gr.Row():
567
- with gr.Column(scale=3):
568
- prompt = gr.Textbox(label="Prompt", lines=1, placeholder="Type a prompt after selecting a LoRA")
569
- with gr.Column(scale=1):
570
- generate_button = gr.Button("Generate", variant="primary", elem_classes=["button_total"])
571
-
572
-
573
-
574
-
575
- with gr.Row(elem_id="loaded_loras"):
576
- with gr.Column(scale=1, min_width=25):
577
- randomize_button = gr.Button("🎲", variant="secondary", scale=1, elem_id="random_btn")
578
- with gr.Column(scale=8):
579
- with gr.Row():
580
- with gr.Column(scale=0, min_width=50):
581
- 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)
582
- with gr.Column(scale=3, min_width=100):
583
- selected_info_1 = gr.Markdown("Select a LoRA 1")
584
- with gr.Column(scale=5, min_width=50):
585
- lora_scale_1 = gr.Slider(label="LoRA 1 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
586
- with gr.Row():
587
- remove_button_1 = gr.Button("Remove", size="sm")
588
-
589
- with gr.Column(scale=8):
590
- with gr.Row():
591
- with gr.Column(scale=0, min_width=50):
592
- 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)
593
- with gr.Column(scale=3, min_width=100):
594
- selected_info_2 = gr.Markdown("Select a LoRA 2")
595
- with gr.Column(scale=5, min_width=50):
596
- lora_scale_2 = gr.Slider(label="LoRA 2 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
597
- with gr.Row():
598
- remove_button_2 = gr.Button("Remove", size="sm")
599
-
600
- with gr.Column(scale=8):
601
- with gr.Row():
602
- with gr.Column(scale=0, min_width=50):
603
- 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)
604
- with gr.Column(scale=3, min_width=100):
605
- selected_info_3 = gr.Markdown("Select a LoRA 3")
606
- with gr.Column(scale=5, min_width=50):
607
- lora_scale_3 = gr.Slider(label="LoRA 3 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
608
- with gr.Row():
609
- remove_button_3 = gr.Button("Remove", size="sm")
610
 
611
- with gr.Row():
612
- with gr.Column():
613
- with gr.Group():
614
- with gr.Row(elem_id="custom_lora_structure"):
615
- 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)
616
- add_custom_lora_button = gr.Button("Add Custom LoRA", elem_id="custom_lora_btn", scale=2, min_width=150)
617
- remove_custom_lora_button = gr.Button("Remove Custom LoRA", visible=False)
618
- 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")
619
- gallery = gr.Gallery(
620
- [(item["image"], item["title"]) for item in loras],
621
- label="Or pick from the LoRA Explorer gallery",
622
- allow_preview=False,
623
- columns=4,
624
- elem_id="gallery"
625
- )
626
- with gr.Column():
627
- progress_bar = gr.Markdown(elem_id="progress", visible=False)
628
- result = gr.Image(label="Generated Image", interactive=False)
629
- with gr.Accordion("History", open=False):
630
- history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain", interactive=False)
631
 
632
- with gr.Row():
633
- with gr.Accordion("Advanced Settings", open=False):
634
- with gr.Row():
635
- input_image = gr.Image(label="Input image", type="filepath")
636
- 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)
637
- with gr.Column():
638
- with gr.Row():
639
- cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, step=0.5, value=3.5)
640
- steps = gr.Slider(label="Steps", minimum=1, maximum=50, step=1, value=28)
 
 
 
 
 
 
 
 
641
  with gr.Row():
642
- width = gr.Slider(label="Width", minimum=256, maximum=1536, step=64, value=1024)
643
- height = gr.Slider(label="Height", minimum=256, maximum=1536, step=64, value=1024)
 
 
 
 
644
  with gr.Row():
645
- randomize_seed = gr.Checkbox(True, label="Randomize seed")
646
- seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True)
647
 
648
- gallery.select(
649
- update_selection,
650
- inputs=[selected_indices, loras_state, width, height],
651
- outputs=[prompt, selected_info_1, selected_info_2, selected_info_3, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, width, height, lora_image_1, lora_image_2, lora_image_3]
652
- )
 
 
 
 
 
 
653
 
654
- remove_button_1.click(
655
- remove_lora_1,
656
- inputs=[selected_indices, loras_state],
657
- outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, lora_image_1, lora_image_2, lora_image_3]
658
- )
659
-
660
- remove_button_2.click(
661
- remove_lora_2,
662
- inputs=[selected_indices, loras_state],
663
- outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, lora_image_1, lora_image_2, lora_image_3]
664
- )
665
-
666
- remove_button_3.click(
667
- remove_lora_3,
668
- inputs=[selected_indices, loras_state],
669
- outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, lora_image_1, lora_image_2, lora_image_3]
670
- )
671
 
672
- randomize_button.click(
673
- randomize_loras,
674
- inputs=[selected_indices, loras_state],
675
- outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, lora_image_1, lora_image_2, lora_image_3, prompt]
676
- )
 
677
 
678
- add_custom_lora_button.click(
679
- add_custom_lora,
680
- inputs=[custom_lora, selected_indices, loras_state],
681
- outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_info_3, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, lora_image_1, lora_image_2, lora_image_3]
682
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
683
 
684
- remove_custom_lora_button.click(
685
- remove_custom_lora,
686
- inputs=[selected_indices, loras_state],
687
- outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_info_3, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, lora_image_1, lora_image_2, lora_image_3]
688
- )
689
 
690
- gr.on(
691
- triggers=[generate_button.click, prompt.submit],
692
- fn=run_lora,
693
- inputs=[prompt, input_image, image_strength, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, randomize_seed, seed, width, height, loras_state],
694
- outputs=[result, seed, progress_bar]
695
- ).then(
696
- fn=lambda x, history: update_history(x, history) if x is not None else history,
697
- inputs=[result, history_gallery],
698
- outputs=history_gallery,
699
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
700
 
701
  if __name__ == "__main__":
702
  app.queue(max_size=20)
 
522
  history.insert(0, new_image)
523
  return history
524
 
525
+ custom_theme = gr.themes.Base(
526
+ primary_hue="blue",
527
+ secondary_hue="purple",
528
+ neutral_hue="slate",
529
+ ).set(
530
+ button_primary_background_fill="*primary_500",
531
+ button_primary_background_fill_dark="*primary_600",
532
+ button_primary_background_fill_hover="*primary_400",
533
+ button_primary_border_color="*primary_500",
534
+ button_primary_border_color_dark="*primary_600",
535
+ button_primary_text_color="white",
536
+ button_primary_text_color_dark="white",
537
+ button_secondary_background_fill="*neutral_100",
538
+ button_secondary_background_fill_dark="*neutral_700",
539
+ button_secondary_background_fill_hover="*neutral_50",
540
+ button_secondary_text_color="*neutral_800",
541
+ button_secondary_text_color_dark="white",
542
+ background_fill_primary="*neutral_50",
543
+ background_fill_primary_dark="*neutral_900",
544
+ block_background_fill="white",
545
+ block_background_fill_dark="*neutral_800",
546
+ block_label_background_fill="*primary_500",
547
+ block_label_background_fill_dark="*primary_600",
548
+ block_label_text_color="white",
549
+ block_label_text_color_dark="white",
550
+ block_title_text_color="*neutral_800",
551
+ block_title_text_color_dark="white",
552
+ input_background_fill="white",
553
+ input_background_fill_dark="*neutral_800",
554
+ input_border_color="*neutral_200",
555
+ input_border_color_dark="*neutral_700",
556
+ input_placeholder_color="*neutral_400",
557
+ input_placeholder_color_dark="*neutral_400",
558
+ shadow_spread="8px",
559
+ shadow_inset="0px 2px 4px 0px rgba(0,0,0,0.05)"
560
+ )
561
+
562
  css = '''
563
  #gen_btn{height: 100%}
564
  #title{text-align: center}
565
  #title h1{font-size: 3em; display:inline-flex; align-items:center}
566
  #title img{width: 100px; margin-right: 0.25em}
 
567
  #lora_list{background: var(--block-background-fill);padding: 0 1em .3em; font-size: 90%}
568
  .custom_lora_card{margin-bottom: 1em}
569
  .card_internal{display: flex;height: 100px;margin-top: .5em}
 
579
  #custom_lora_btn{margin-top: auto;margin-bottom: 11px}
580
  #random_btn{font-size: 300%}
581
  #component-11{align-self: stretch;}
582
+
583
+ #lora_gallery {
584
+ margin: 20px 0;
585
+ padding: 10px;
586
+ border: 1px solid #ddd;
587
+ border-radius: 12px;
588
+ background: linear-gradient(to bottom right, #ffffff, #f8f9fa);
589
+ width: 100% !important;
590
+ height: 800px !important;
591
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
592
+ display: block !important;
593
+ }
594
+
595
+ /* 갤러리 그리드 컨테이너 */
596
+ #gallery {
597
+ display: grid !important;
598
+ grid-template-columns: repeat(10, 1fr) !important;
599
+ gap: 10px !important;
600
+ padding: 10px !important;
601
+ width: 100% !important;
602
+ height: 100% !important;
603
+ overflow-y: auto !important;
604
+ max-width: 100% !important;
605
+ }
606
+
607
+ /* 갤러리 아이템 */
608
+ .gallery-item {
609
+ position: relative !important;
610
+ width: 100% !important;
611
+ aspect-ratio: 1 !important;
612
+ margin: 0 !important;
613
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
614
+ transition: transform 0.3s ease, box-shadow 0.3s ease;
615
+ border-radius: 12px;
616
+ overflow: hidden;
617
+ }
618
+
619
+ /* 갤러리 이미지 */
620
+ .gallery-item img {
621
+ width: 100% !important;
622
+ height: 100% !important;
623
+ object-fit: cover !important;
624
+ border-radius: 12px !important;
625
+ }
626
+
627
+ /* 갤러리 그리드 래퍼 */
628
+ .wrap, .svelte-w6dy5e {
629
+ display: grid !important;
630
+ grid-template-columns: repeat(10, 1fr) !important; /* 10개로 통일 */
631
+ gap: 10px !important;
632
+ width: 100% !important;
633
+ max-width: 100% !important;
634
+ }
635
+
636
+ /* 모든 컨테이너 공통 설정 */
637
+ .container, .content, .block, .contain {
638
+ width: 100% !important;
639
+ max-width: 100% !important;
640
+ margin: 0 !important;
641
+ padding: 0 !important;
642
+ }
643
+
644
+ /* 행 설정 */
645
+ .row {
646
+ width: 100% !important;
647
+ margin: 0 !important;
648
+ padding: 0 !important;
649
+ }
650
+
651
+ /* 입체감 있는 버튼 */
652
+ .button_total {
653
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
654
+ transition: all 0.3s ease;
655
+ }
656
+
657
+ .button_total:hover {
658
+ transform: translateY(-2px);
659
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
660
+ }
661
+
662
+ /* 입체감 있는 입력 필드 */
663
+ input, textarea {
664
+ box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);
665
+ transition: all 0.3s ease;
666
+ }
667
+
668
+ input:focus, textarea:focus {
669
+ box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
670
+ }
671
+
672
+ /* 컴포넌트들의 border-radius 설정 */
673
+ .gradio-container .input,
674
+ .gradio-container .button,
675
+ .gradio-container .block {
676
+ border-radius: 12px;
677
+ }
678
+
679
+ /* 갤러리 스크롤바 스타일링 */
680
+ #gallery::-webkit-scrollbar {
681
+ width: 8px;
682
+ }
683
+
684
+ #gallery::-webkit-scrollbar-track {
685
+ background: #f1f1f1;
686
+ border-radius: 4px;
687
+ }
688
+
689
+ #gallery::-webkit-scrollbar-thumb {
690
+ background: #888;
691
+ border-radius: 4px;
692
+ }
693
+
694
+ #gallery::-webkit-scrollbar-thumb:hover {
695
+ background: #555;
696
+ }
697
+
698
+ /* 갤러리 flex 컨테이너 */
699
+ .flex {
700
+ width: 100% !important;
701
+ max-width: 100% !important;
702
+ display: flex !important;
703
+ }
704
+
705
+ /* svelte 특정 클래스 */
706
+ .svelte-1p9xokt {
707
+ width: 100% !important;
708
+ max-width: 100% !important;
709
+ }
710
+
711
+ #footer {visibility: hidden;}
712
+
713
+ /* 갤러리 컨테이너 클래스 */
714
+ .gallery-container {
715
+ width: 100% !important;
716
+ max-width: 100% !important;
717
+ }
718
  '''
719
 
720
+
721
+ with gr.Blocks(theme=custom_theme, css=css, delete_cache=(60, 3600)) as app:
722
  loras_state = gr.State(loras)
723
  selected_indices = gr.State([])
724
+
725
  gr.Markdown(
726
  """
727
  # MixGen3: 멀티 Lora(이미지 학습) 통합 생성 모델
 
728
  ### 사용 안내:
729
+ 갤러리에서 원하는 모델을 선택(최대 3개까지) < 프롬프트에 한글 또는 영문으로 원하는 내용을 입력 < Generate 버튼 실행
 
 
 
 
730
  """
731
  )
732
+
733
+ with gr.Row(elem_id="lora_gallery", equal_height=True):
734
+ gallery = gr.Gallery(
735
+ value=[(item["image"], item["title"]) for item in loras],
736
+ label="LoRA Explorer Gallery",
737
+ columns=11, # 10개로 변경
738
+ elem_id="gallery",
739
+ height=800,
740
+ object_fit="cover",
741
+ show_label=True,
742
+ allow_preview=False,
743
+ show_share_button=False,
744
+ container=True,
745
+ preview=False
746
+ )
747
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
 
750
+
751
+ with gr.Tab(label="Generate"):
752
+ # Prompt and Generate Button
753
+ with gr.Row():
754
+ with gr.Column(scale=3):
755
+ prompt = gr.Textbox(label="Prompt", lines=1, placeholder="Type a prompt after selecting a LoRA")
756
+ with gr.Column(scale=1):
757
+ generate_button = gr.Button("Generate", variant="primary", elem_classes=["button_total"])
758
+
759
+ # LoRA Selection Area
760
+ with gr.Row(elem_id="loaded_loras"):
761
+ # Randomize Button
762
+ with gr.Column(scale=1, min_width=25):
763
+ randomize_button = gr.Button("🎲", variant="secondary", scale=1, elem_id="random_btn")
764
+
765
+ # LoRA 1
766
+ with gr.Column(scale=8):
767
  with gr.Row():
768
+ with gr.Column(scale=0, min_width=50):
769
+ 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)
770
+ with gr.Column(scale=3, min_width=100):
771
+ selected_info_1 = gr.Markdown("Select a LoRA 1")
772
+ with gr.Column(scale=5, min_width=50):
773
+ lora_scale_1 = gr.Slider(label="LoRA 1 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
774
  with gr.Row():
775
+ remove_button_1 = gr.Button("Remove", size="sm")
 
776
 
777
+ # LoRA 2
778
+ with gr.Column(scale=8):
779
+ with gr.Row():
780
+ with gr.Column(scale=0, min_width=50):
781
+ 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)
782
+ with gr.Column(scale=3, min_width=100):
783
+ selected_info_2 = gr.Markdown("Select a LoRA 2")
784
+ with gr.Column(scale=5, min_width=50):
785
+ lora_scale_2 = gr.Slider(label="LoRA 2 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
786
+ with gr.Row():
787
+ remove_button_2 = gr.Button("Remove", size="sm")
788
 
789
+ # LoRA 3
790
+ with gr.Column(scale=8):
791
+ with gr.Row():
792
+ with gr.Column(scale=0, min_width=50):
793
+ 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)
794
+ with gr.Column(scale=3, min_width=100):
795
+ selected_info_3 = gr.Markdown("Select a LoRA 3")
796
+ with gr.Column(scale=5, min_width=50):
797
+ lora_scale_3 = gr.Slider(label="LoRA 3 Scale", minimum=0, maximum=3, step=0.01, value=1.15)
798
+ with gr.Row():
799
+ remove_button_3 = gr.Button("Remove", size="sm")
 
 
 
 
 
 
800
 
801
+ # Result and Progress Area
802
+ with gr.Column():
803
+ progress_bar = gr.Markdown(elem_id="progress", visible=False)
804
+ result = gr.Image(label="Generated Image", interactive=False)
805
+ with gr.Accordion("History", open=False):
806
+ history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain", interactive=False)
807
 
808
+ # Advanced Settings
809
+ with gr.Row():
810
+ with gr.Accordion("Advanced Settings", open=False):
811
+ with gr.Row():
812
+ input_image = gr.Image(label="Input image", type="filepath")
813
+ 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)
814
+ with gr.Column():
815
+ with gr.Row():
816
+ cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, step=0.5, value=3.5)
817
+ steps = gr.Slider(label="Steps", minimum=1, maximum=50, step=1, value=28)
818
+ with gr.Row():
819
+ width = gr.Slider(label="Width", minimum=256, maximum=1536, step=64, value=1024)
820
+ height = gr.Slider(label="Height", minimum=256, maximum=1536, step=64, value=1024)
821
+ with gr.Row():
822
+ randomize_seed = gr.Checkbox(True, label="Randomize seed")
823
+ seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True)
824
+
825
+ # Custom LoRA Section
826
+ with gr.Column():
827
+ with gr.Group():
828
+ with gr.Row(elem_id="custom_lora_structure"):
829
+ 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)
830
+ add_custom_lora_button = gr.Button("Add Custom LoRA", elem_id="custom_lora_btn", scale=2, min_width=150)
831
+ remove_custom_lora_button = gr.Button("Remove Custom LoRA", visible=False)
832
+ 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")
833
 
 
 
 
 
 
834
 
835
+ # Event Handlers
836
+ gallery.select(
837
+ update_selection,
838
+ inputs=[selected_indices, loras_state, width, height],
839
+ outputs=[prompt, selected_info_1, selected_info_2, selected_info_3, selected_indices,
840
+ lora_scale_1, lora_scale_2, lora_scale_3, width, height,
841
+ lora_image_1, lora_image_2, lora_image_3]
842
+ )
843
+
844
+ remove_button_1.click(
845
+ remove_lora_1,
846
+ inputs=[selected_indices, loras_state],
847
+ outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices,
848
+ lora_scale_1, lora_scale_2, lora_scale_3,
849
+ lora_image_1, lora_image_2, lora_image_3]
850
+ )
851
+
852
+ remove_button_2.click(
853
+ remove_lora_2,
854
+ inputs=[selected_indices, loras_state],
855
+ outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices,
856
+ lora_scale_1, lora_scale_2, lora_scale_3,
857
+ lora_image_1, lora_image_2, lora_image_3]
858
+ )
859
+
860
+ remove_button_3.click(
861
+ remove_lora_3,
862
+ inputs=[selected_indices, loras_state],
863
+ outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices,
864
+ lora_scale_1, lora_scale_2, lora_scale_3,
865
+ lora_image_1, lora_image_2, lora_image_3]
866
+ )
867
+
868
+ randomize_button.click(
869
+ randomize_loras,
870
+ inputs=[selected_indices, loras_state],
871
+ outputs=[selected_info_1, selected_info_2, selected_info_3, selected_indices,
872
+ lora_scale_1, lora_scale_2, lora_scale_3,
873
+ lora_image_1, lora_image_2, lora_image_3, prompt]
874
+ )
875
+
876
+ add_custom_lora_button.click(
877
+ add_custom_lora,
878
+ inputs=[custom_lora, selected_indices, loras_state],
879
+ outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_info_3,
880
+ selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
881
+ lora_image_1, lora_image_2, lora_image_3]
882
+ )
883
+
884
+ remove_custom_lora_button.click(
885
+ remove_custom_lora,
886
+ inputs=[selected_indices, loras_state],
887
+ outputs=[loras_state, gallery, selected_info_1, selected_info_2, selected_info_3,
888
+ selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
889
+ lora_image_1, lora_image_2, lora_image_3]
890
+ )
891
+
892
+ gr.on(
893
+ triggers=[generate_button.click, prompt.submit],
894
+ fn=run_lora,
895
+ inputs=[prompt, input_image, image_strength, cfg_scale, steps,
896
+ selected_indices, lora_scale_1, lora_scale_2, lora_scale_3,
897
+ randomize_seed, seed, width, height, loras_state],
898
+ outputs=[result, seed, progress_bar]
899
+ ).then(
900
+ fn=lambda x, history: update_history(x, history) if x is not None else history,
901
+ inputs=[result, history_gallery],
902
+ outputs=history_gallery,
903
+ )
904
 
905
  if __name__ == "__main__":
906
  app.queue(max_size=20)