John6666 commited on
Commit
ed51a72
·
verified ·
1 Parent(s): 6c0c6da

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +69 -27
  2. modutils.py +83 -3
  3. tagger.py +8 -0
app.py CHANGED
@@ -413,8 +413,10 @@ from tagger import (
413
  insert_recom_prompt,
414
  compose_prompt_to_copy,
415
  translate_prompt,
 
416
  )
417
  from modutils import (
 
418
  get_t2i_model_info,
419
  get_tupled_model_list,
420
  save_gallery_images,
@@ -424,6 +426,8 @@ from modutils import (
424
  set_lora_prompt,
425
  get_lora_tupled_list,
426
  apply_lora_prompt,
 
 
427
  set_textual_inversion_prompt,
428
  get_model_pipeline,
429
  set_optimization,
@@ -873,7 +877,8 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
873
  with gr.Tab("Generation"):
874
  v2b = V2UI()
875
  with gr.Column(scale=2):
876
- with gr.Accordion("Model and Task", open=False):
 
877
  task_gui = gr.Dropdown(label="Task", choices=sdxl_task, value=task_model_list[0])
878
  model_name_gui = gr.Dropdown(label="Model", info="You can enter a huggingface model repo_id to want to use.", choices=get_tupled_model_list(model_list), value="votepurchase/animagine-xl-3.1", allow_custom_value=True)
879
  model_info_gui = gr.Markdown()
@@ -881,12 +886,13 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
881
  quick_model_type_gui = gr.Radio(label="Model Type", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
882
  quick_genre_gui = gr.Radio(label="Genre", choices=["Anime", "Photo"], value="Anime", interactive=True)
883
  quick_speed_gui = gr.Radio(label="Speed", choices=["Fast", "Standard", "Heavy"], value="Standard", interactive=True)
884
- quick_aspect_gui = gr.Radio(label="Aspect Ratio", choices=["1:1", "3:4"], value="3:4", interactive=True)
885
- quality_selector_gui = gr.Dropdown(label="Quality Tags Presets", interactive=True, choices=list(preset_quality.keys()), value="None")
886
- style_selector_gui = gr.Dropdown(label="Style Preset", interactive=True, choices=list(preset_styles.keys()), value="None")
887
- sampler_selector_gui = gr.Dropdown(label="Sampler Quick Settings", interactive=True, choices=list(preset_sampler_setting.keys()), value="None")
888
- optimization_gui = gr.Dropdown(label="Optimization for SDXL", choices=list(optimization_list.keys()), value="None", interactive=True)
889
- with gr.Accordion("Generate prompt from Image", open=False):
 
890
  input_image_gui = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
891
  with gr.Accordion(label="Advanced options", open=False):
892
  general_threshold_gui = gr.Slider(label="Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.01, interactive=True)
@@ -898,16 +904,17 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
898
  generate_from_image_btn_gui = gr.Button(value="GENERATE TAGS FROM IMAGE", size="lg", variant="primary")
899
  with gr.Group():
900
  prompt_gui = gr.Textbox(lines=6, placeholder="1girl, solo, ...", label="Prompt", show_copy_button=True)
901
- with gr.Accordion("Negative prompt, etc.", open=False):
902
  neg_prompt_gui = gr.Textbox(lines=3, placeholder="lowres, (bad), ...", label="Negative prompt", show_copy_button=True)
903
  translate_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
904
- insert_prompt_gui = gr.Radio(label="Insert reccomended positive / negative prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True, scale=2)
905
- prompt_type_gui = gr.Radio(label="Convert tags to", choices=["danbooru", "e621"], value="e621", visible=False)
906
- prompt_type_button = gr.Button(value="Convert prompt to Pony e621 style", size="sm", variant="secondary")
 
907
  with gr.Row():
908
  character_dbt = gr.Textbox(lines=1, placeholder="kafuu chino, ...", label="Character names")
909
  series_dbt = gr.Textbox(lines=1, placeholder="Is the order a rabbit?, ...", label="Series names")
910
- generate_db_random_button = gr.Button(value="Generate random prompt from character", size="sm", variant="secondary")
911
  model_name_dbt = gr.Dropdown(label="Model", choices=list(V2_ALL_MODELS.keys()), value=list(V2_ALL_MODELS.keys())[0], visible=False)
912
  aspect_ratio_dbt = gr.Radio(label="Aspect ratio", choices=list(V2_ASPECT_RATIO_OPTIONS), value="square", visible=False)
913
  length_dbt = gr.Radio(label="Length", choices=list(V2_LENGTH_OPTIONS), value="very_long", visible=False)
@@ -915,7 +922,8 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
915
  ban_tags_dbt = gr.Textbox(label="Ban tags", placeholder="alternate costumen, ...", value="futanari, censored, furry, furrification", visible=False)
916
  elapsed_time_dbt = gr.Markdown(label="Elapsed time", value="", visible=False)
917
  copy_button_dbt = gr.Button(value="Copy to clipboard", visible=False)
918
- rating_dbt = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="explicit")
 
919
  with gr.Row():
920
  set_params_gui = gr.Button(value="↙️")
921
  clear_prompt_gui = gr.Button(value="🗑️")
@@ -951,7 +959,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
951
 
952
  actual_task_info = gr.HTML()
953
 
954
- with gr.Accordion("Generation settings", open=False, visible=True):
955
  steps_gui = gr.Slider(minimum=1, maximum=100, step=1, value=28, label="Steps")
956
  cfg_gui = gr.Slider(minimum=0, maximum=30, step=0.5, value=7.0, label="CFG")
957
  sampler_gui = gr.Dropdown(label="Sampler", choices=scheduler_names, value="Euler a")
@@ -1043,7 +1051,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1043
  prompt_syntax_gui = gr.Dropdown(label="Prompt Syntax", choices=prompt_s_options, value=prompt_s_options[1][1])
1044
  vae_model_gui = gr.Dropdown(label="VAE Model", choices=vae_model_list)
1045
 
1046
- with gr.Accordion("Hires fix", open=False, visible=True):
1047
 
1048
  upscaler_keys = list(upscaler_dict_gui.keys())
1049
 
@@ -1057,7 +1065,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1057
  hires_prompt_gui = gr.Textbox(label="Hires Prompt", placeholder="Main prompt will be use", lines=3)
1058
  hires_negative_prompt_gui = gr.Textbox(label="Hires Negative Prompt", placeholder="Main negative prompt will be use", lines=3)
1059
 
1060
- with gr.Accordion("LoRA", open=False, visible=True):
1061
  lora1_gui = gr.Dropdown(label="Lora1", choices=get_lora_tupled_list(lora_model_list), allow_custom_value=True)
1062
  lora_scale_1_gui = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="Lora Scale 1")
1063
  with gr.Row():
@@ -1102,6 +1110,12 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1102
  [text_lora],
1103
  [lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui]
1104
  )
 
 
 
 
 
 
1105
 
1106
  with gr.Accordion("From Local", open=True, visible=True):
1107
  file_output_lora = gr.File(label="Uploaded LoRA", file_types=['.ckpt', '.pt', '.pth', '.safetensors', '.bin'], file_count="multiple", interactive=False, visible=False)
@@ -1111,8 +1125,8 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1111
  [file_output_lora],
1112
  [lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui]
1113
  )
1114
- ## END MOD
1115
- with gr.Accordion("IP-Adapter", open=False, visible=True):##############
1116
 
1117
  IP_MODELS = sorted(list(set(IP_ADAPTERS_SD + IP_ADAPTERS_SDXL)))
1118
  MODE_IP_OPTIONS = ["original", "style", "layout", "style+layout"]
@@ -1130,7 +1144,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1130
  mode_ip2 = gr.Dropdown(value="style", label="Mode", choices=MODE_IP_OPTIONS)
1131
  scale_ip2 = gr.Slider(minimum=0., maximum=2., step=0.01, value=0.7, label="Scale")
1132
 
1133
- with gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True):
1134
  image_control = gr.Image(label="Image ControlNet/Inpaint/Img2img", type="filepath")
1135
  image_mask_gui = gr.Image(label="Image Mask", type="filepath")
1136
  strength_gui = gr.Slider(
@@ -1162,12 +1176,12 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1162
  control_net_start_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=0, label="ControlNet Start Threshold (%)")
1163
  control_net_stop_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=1, label="ControlNet Stop Threshold (%)")
1164
 
1165
- with gr.Accordion("T2I adapter", open=False, visible=True):
1166
  t2i_adapter_preprocessor_gui = gr.Checkbox(value=True, label="T2i Adapter Preprocessor")
1167
  adapter_conditioning_scale_gui = gr.Slider(minimum=0, maximum=5., step=0.1, value=1, label="Adapter Conditioning Scale")
1168
  adapter_conditioning_factor_gui = gr.Slider(minimum=0, maximum=1., step=0.01, value=0.55, label="Adapter Conditioning Factor (%)")
1169
 
1170
- with gr.Accordion("Styles", open=False, visible=True):
1171
 
1172
  try:
1173
  style_names_found = sd_gen.model.STYLE_NAMES
@@ -1195,17 +1209,15 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1195
 
1196
  style_button.click(load_json_style_file, [style_json_gui], [style_prompt_gui])
1197
 
1198
- ## BEGIN MOD
1199
- with gr.Accordion("Textual inversion", open=False, visible=True):
1200
  active_textual_inversion_gui = gr.Checkbox(value=False, label="Active Textual Inversion in prompt")
1201
  use_textual_inversion_gui = gr.CheckboxGroup(choices=get_embed_list(get_model_pipeline(model_name_gui.value)) if active_textual_inversion_gui.value else [], value=None, label="Use Textual Invertion in prompt")
1202
  def update_textual_inversion_gui(active_textual_inversion_gui, model_name_gui):
1203
  return gr.update(choices=get_embed_list(get_model_pipeline(model_name_gui)) if active_textual_inversion_gui else [])
1204
  active_textual_inversion_gui.change(update_textual_inversion_gui, [active_textual_inversion_gui, model_name_gui], [use_textual_inversion_gui])
1205
  model_name_gui.change(update_textual_inversion_gui, [active_textual_inversion_gui, model_name_gui], [use_textual_inversion_gui])
1206
- ## END MOD
1207
 
1208
- with gr.Accordion("Detailfix", open=False, visible=True):
1209
 
1210
  # Adetailer Inpaint Only
1211
  adetailer_inpaint_only_gui = gr.Checkbox(label="Inpaint only", value=True)
@@ -1243,7 +1255,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1243
  mask_blur_b_gui = gr.Number(label="Mask blur:", value=4, minimum=1)
1244
  mask_padding_b_gui = gr.Number(label="Mask padding:", value=32, minimum=1)
1245
 
1246
- with gr.Accordion("Other settings", open=False, visible=True):
1247
  image_previews_gui = gr.Checkbox(value=True, label="Image Previews")
1248
  hires_before_adetailer_gui = gr.Checkbox(value=False, label="Hires Before Adetailer")
1249
  hires_after_adetailer_gui = gr.Checkbox(value=True, label="Hires After Adetailer")
@@ -1262,7 +1274,6 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1262
  retain_hires_model_previous_load_gui = gr.Checkbox(value=False, label="Retain Hires Model Previous Load")
1263
  xformers_memory_efficient_attention_gui = gr.Checkbox(value=False, label="Xformers Memory Efficient Attention")
1264
 
1265
- ## BEGIN MOD
1266
  with gr.Accordion("Examples and help", open=True, visible=True):
1267
  gr.Examples(
1268
  examples=[
@@ -1596,6 +1607,12 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1596
  btn_send.click(send_img, [img_source, img_result], [image_control, image_mask_gui])
1597
 
1598
  ## BEGIN MOD
 
 
 
 
 
 
1599
  model_name_gui.change(get_t2i_model_info, [model_name_gui], [model_info_gui])
1600
 
1601
  quick_model_type_gui.change(
@@ -1653,6 +1670,26 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1653
  lora3_copy_button.click(apply_lora_prompt, [prompt_gui, lora3_trigger_gui], [prompt_gui])
1654
  lora4_copy_button.click(apply_lora_prompt, [prompt_gui, lora4_trigger_gui], [prompt_gui])
1655
  lora5_copy_button.click(apply_lora_prompt, [prompt_gui, lora5_trigger_gui], [prompt_gui])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1656
 
1657
  use_textual_inversion_gui.change(set_textual_inversion_prompt, [use_textual_inversion_gui, prompt_gui, neg_prompt_gui, prompt_syntax_gui], [prompt_gui, neg_prompt_gui])
1658
 
@@ -1699,6 +1736,8 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1699
  outputs=[prompt_gui],
1700
  )
1701
 
 
 
1702
  generate_db_random_button.click(
1703
  parse_upsampling_output(v2b.on_generate),
1704
  inputs=[
@@ -1848,6 +1887,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1848
  with gr.Group():
1849
  input_character = gr.Textbox(label="Character tags", placeholder="hatsune miku")
1850
  input_copyright = gr.Textbox(label="Copyright tags", placeholder="vocaloid")
 
1851
  input_general = gr.TextArea(label="General tags", lines=4, placeholder="1girl, ...", value="")
1852
  input_tags_to_copy = gr.Textbox(value="", visible=False)
1853
  copy_input_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
@@ -1913,6 +1953,8 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1913
  gradio_copy_text, inputs=[input_tags_to_copy], js=COPY_ACTION_JS,
1914
  )
1915
 
 
 
1916
  generate_btn.click(
1917
  parse_upsampling_output(v2.on_generate),
1918
  inputs=[
 
413
  insert_recom_prompt,
414
  compose_prompt_to_copy,
415
  translate_prompt,
416
+ select_random_character,
417
  )
418
  from modutils import (
419
+ change_interface_mode,
420
  get_t2i_model_info,
421
  get_tupled_model_list,
422
  save_gallery_images,
 
426
  set_lora_prompt,
427
  get_lora_tupled_list,
428
  apply_lora_prompt,
429
+ search_civitai_lora,
430
+ select_civitai_lora,
431
  set_textual_inversion_prompt,
432
  get_model_pipeline,
433
  set_optimization,
 
877
  with gr.Tab("Generation"):
878
  v2b = V2UI()
879
  with gr.Column(scale=2):
880
+ interface_mode_gui = gr.Radio(label="Quick settings", choices=["Simple", "Standard", "Fast", "LoRA"], value="Standard")
881
+ with gr.Accordion("Model and Task", open=False) as menu_model:
882
  task_gui = gr.Dropdown(label="Task", choices=sdxl_task, value=task_model_list[0])
883
  model_name_gui = gr.Dropdown(label="Model", info="You can enter a huggingface model repo_id to want to use.", choices=get_tupled_model_list(model_list), value="votepurchase/animagine-xl-3.1", allow_custom_value=True)
884
  model_info_gui = gr.Markdown()
 
886
  quick_model_type_gui = gr.Radio(label="Model Type", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
887
  quick_genre_gui = gr.Radio(label="Genre", choices=["Anime", "Photo"], value="Anime", interactive=True)
888
  quick_speed_gui = gr.Radio(label="Speed", choices=["Fast", "Standard", "Heavy"], value="Standard", interactive=True)
889
+ quick_aspect_gui = gr.Radio(label="Aspect Ratio", choices=["1:1", "3:4"], value="1:1", interactive=True)
890
+ with gr.Accordion(label="Advanced options", open=False):
891
+ quality_selector_gui = gr.Dropdown(label="Quality Tags Presets", interactive=True, choices=list(preset_quality.keys()), value="None")
892
+ style_selector_gui = gr.Dropdown(label="Style Preset", interactive=True, choices=list(preset_styles.keys()), value="None")
893
+ sampler_selector_gui = gr.Dropdown(label="Sampler Quick Settings", interactive=True, choices=list(preset_sampler_setting.keys()), value="None")
894
+ optimization_gui = gr.Dropdown(label="Optimization for SDXL", choices=list(optimization_list.keys()), value="None", interactive=True)
895
+ with gr.Accordion("Generate prompt from Image", open=False) as menu_from_image:
896
  input_image_gui = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
897
  with gr.Accordion(label="Advanced options", open=False):
898
  general_threshold_gui = gr.Slider(label="Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.01, interactive=True)
 
904
  generate_from_image_btn_gui = gr.Button(value="GENERATE TAGS FROM IMAGE", size="lg", variant="primary")
905
  with gr.Group():
906
  prompt_gui = gr.Textbox(lines=6, placeholder="1girl, solo, ...", label="Prompt", show_copy_button=True)
907
+ with gr.Accordion("Negative prompt, etc.", open=False) as menu_negative:
908
  neg_prompt_gui = gr.Textbox(lines=3, placeholder="lowres, (bad), ...", label="Negative prompt", show_copy_button=True)
909
  translate_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
910
+ with gr.Accordion(label="Advanced options", open=False):
911
+ insert_prompt_gui = gr.Radio(label="Insert reccomended positive / negative prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True, scale=2)
912
+ prompt_type_gui = gr.Radio(label="Convert tags to", choices=["danbooru", "e621"], value="e621", visible=False)
913
+ prompt_type_button = gr.Button(value="Convert prompt to Pony e621 style", size="sm", variant="secondary")
914
  with gr.Row():
915
  character_dbt = gr.Textbox(lines=1, placeholder="kafuu chino, ...", label="Character names")
916
  series_dbt = gr.Textbox(lines=1, placeholder="Is the order a rabbit?, ...", label="Series names")
917
+ random_character_gui = gr.Button(value="Pick a random character 🎲", size="sm")
918
  model_name_dbt = gr.Dropdown(label="Model", choices=list(V2_ALL_MODELS.keys()), value=list(V2_ALL_MODELS.keys())[0], visible=False)
919
  aspect_ratio_dbt = gr.Radio(label="Aspect ratio", choices=list(V2_ASPECT_RATIO_OPTIONS), value="square", visible=False)
920
  length_dbt = gr.Radio(label="Length", choices=list(V2_LENGTH_OPTIONS), value="very_long", visible=False)
 
922
  ban_tags_dbt = gr.Textbox(label="Ban tags", placeholder="alternate costumen, ...", value="futanari, censored, furry, furrification", visible=False)
923
  elapsed_time_dbt = gr.Markdown(label="Elapsed time", value="", visible=False)
924
  copy_button_dbt = gr.Button(value="Copy to clipboard", visible=False)
925
+ generate_db_random_button = gr.Button(value="Generate random prompt 🎲", size="sm", variant="secondary")
926
+ rating_dbt = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="sfw")
927
  with gr.Row():
928
  set_params_gui = gr.Button(value="↙️")
929
  clear_prompt_gui = gr.Button(value="🗑️")
 
959
 
960
  actual_task_info = gr.HTML()
961
 
962
+ with gr.Accordion("Generation settings", open=False, visible=True) as menu_gen:
963
  steps_gui = gr.Slider(minimum=1, maximum=100, step=1, value=28, label="Steps")
964
  cfg_gui = gr.Slider(minimum=0, maximum=30, step=0.5, value=7.0, label="CFG")
965
  sampler_gui = gr.Dropdown(label="Sampler", choices=scheduler_names, value="Euler a")
 
1051
  prompt_syntax_gui = gr.Dropdown(label="Prompt Syntax", choices=prompt_s_options, value=prompt_s_options[1][1])
1052
  vae_model_gui = gr.Dropdown(label="VAE Model", choices=vae_model_list)
1053
 
1054
+ with gr.Accordion("Hires fix", open=False, visible=True) as menu_hires:
1055
 
1056
  upscaler_keys = list(upscaler_dict_gui.keys())
1057
 
 
1065
  hires_prompt_gui = gr.Textbox(label="Hires Prompt", placeholder="Main prompt will be use", lines=3)
1066
  hires_negative_prompt_gui = gr.Textbox(label="Hires Negative Prompt", placeholder="Main negative prompt will be use", lines=3)
1067
 
1068
+ with gr.Accordion("LoRA", open=False, visible=True) as menu_lora:
1069
  lora1_gui = gr.Dropdown(label="Lora1", choices=get_lora_tupled_list(lora_model_list), allow_custom_value=True)
1070
  lora_scale_1_gui = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="Lora Scale 1")
1071
  with gr.Row():
 
1110
  [text_lora],
1111
  [lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui]
1112
  )
1113
+ with gr.Row():
1114
+ search_civitai_query_lora = gr.Textbox(label="Query", placeholder="oomuro sakurako...", lines=1)
1115
+ search_civitai_basemodel_lora = gr.CheckboxGroup(label="Search LoRA for", choices=["Pony", "SD 1.5", "SDXL 1.0"], value=["Pony", "SDXL 1.0"])
1116
+ search_civitai_button_lora = gr.Button("Search on Civitai")
1117
+ search_civitai_result_lora = gr.Dropdown(label="Search Results", choices=[("", "")], value="", allow_custom_value=True, visible=False)
1118
+ search_civitai_desc_lora = gr.Markdown(value="", visible=False)
1119
 
1120
  with gr.Accordion("From Local", open=True, visible=True):
1121
  file_output_lora = gr.File(label="Uploaded LoRA", file_types=['.ckpt', '.pt', '.pth', '.safetensors', '.bin'], file_count="multiple", interactive=False, visible=False)
 
1125
  [file_output_lora],
1126
  [lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui]
1127
  )
1128
+
1129
+ with gr.Accordion("IP-Adapter", open=False, visible=True) as menu_ipa:##############
1130
 
1131
  IP_MODELS = sorted(list(set(IP_ADAPTERS_SD + IP_ADAPTERS_SDXL)))
1132
  MODE_IP_OPTIONS = ["original", "style", "layout", "style+layout"]
 
1144
  mode_ip2 = gr.Dropdown(value="style", label="Mode", choices=MODE_IP_OPTIONS)
1145
  scale_ip2 = gr.Slider(minimum=0., maximum=2., step=0.01, value=0.7, label="Scale")
1146
 
1147
+ with gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True) as menu_i2i:
1148
  image_control = gr.Image(label="Image ControlNet/Inpaint/Img2img", type="filepath")
1149
  image_mask_gui = gr.Image(label="Image Mask", type="filepath")
1150
  strength_gui = gr.Slider(
 
1176
  control_net_start_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=0, label="ControlNet Start Threshold (%)")
1177
  control_net_stop_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=1, label="ControlNet Stop Threshold (%)")
1178
 
1179
+ with gr.Accordion("T2I adapter", open=False, visible=True) as menu_t2i:
1180
  t2i_adapter_preprocessor_gui = gr.Checkbox(value=True, label="T2i Adapter Preprocessor")
1181
  adapter_conditioning_scale_gui = gr.Slider(minimum=0, maximum=5., step=0.1, value=1, label="Adapter Conditioning Scale")
1182
  adapter_conditioning_factor_gui = gr.Slider(minimum=0, maximum=1., step=0.01, value=0.55, label="Adapter Conditioning Factor (%)")
1183
 
1184
+ with gr.Accordion("Styles", open=False, visible=True) as menu_styles:
1185
 
1186
  try:
1187
  style_names_found = sd_gen.model.STYLE_NAMES
 
1209
 
1210
  style_button.click(load_json_style_file, [style_json_gui], [style_prompt_gui])
1211
 
1212
+ with gr.Accordion("Textual inversion", open=False, visible=True) as menu_ti:
 
1213
  active_textual_inversion_gui = gr.Checkbox(value=False, label="Active Textual Inversion in prompt")
1214
  use_textual_inversion_gui = gr.CheckboxGroup(choices=get_embed_list(get_model_pipeline(model_name_gui.value)) if active_textual_inversion_gui.value else [], value=None, label="Use Textual Invertion in prompt")
1215
  def update_textual_inversion_gui(active_textual_inversion_gui, model_name_gui):
1216
  return gr.update(choices=get_embed_list(get_model_pipeline(model_name_gui)) if active_textual_inversion_gui else [])
1217
  active_textual_inversion_gui.change(update_textual_inversion_gui, [active_textual_inversion_gui, model_name_gui], [use_textual_inversion_gui])
1218
  model_name_gui.change(update_textual_inversion_gui, [active_textual_inversion_gui, model_name_gui], [use_textual_inversion_gui])
 
1219
 
1220
+ with gr.Accordion("Detailfix", open=False, visible=True) as menu_detail:
1221
 
1222
  # Adetailer Inpaint Only
1223
  adetailer_inpaint_only_gui = gr.Checkbox(label="Inpaint only", value=True)
 
1255
  mask_blur_b_gui = gr.Number(label="Mask blur:", value=4, minimum=1)
1256
  mask_padding_b_gui = gr.Number(label="Mask padding:", value=32, minimum=1)
1257
 
1258
+ with gr.Accordion("Other settings", open=False, visible=True) as menu_other:
1259
  image_previews_gui = gr.Checkbox(value=True, label="Image Previews")
1260
  hires_before_adetailer_gui = gr.Checkbox(value=False, label="Hires Before Adetailer")
1261
  hires_after_adetailer_gui = gr.Checkbox(value=True, label="Hires After Adetailer")
 
1274
  retain_hires_model_previous_load_gui = gr.Checkbox(value=False, label="Retain Hires Model Previous Load")
1275
  xformers_memory_efficient_attention_gui = gr.Checkbox(value=False, label="Xformers Memory Efficient Attention")
1276
 
 
1277
  with gr.Accordion("Examples and help", open=True, visible=True):
1278
  gr.Examples(
1279
  examples=[
 
1607
  btn_send.click(send_img, [img_source, img_result], [image_control, image_mask_gui])
1608
 
1609
  ## BEGIN MOD
1610
+ interface_mode_gui.change(
1611
+ change_interface_mode,
1612
+ [interface_mode_gui],
1613
+ [menu_model, menu_from_image, menu_negative, menu_gen, menu_hires, menu_lora, menu_ipa,\
1614
+ menu_i2i, menu_t2i, menu_styles, menu_ti, menu_detail, menu_other, task_gui, quick_speed_gui]
1615
+ )
1616
  model_name_gui.change(get_t2i_model_info, [model_name_gui], [model_info_gui])
1617
 
1618
  quick_model_type_gui.change(
 
1670
  lora3_copy_button.click(apply_lora_prompt, [prompt_gui, lora3_trigger_gui], [prompt_gui])
1671
  lora4_copy_button.click(apply_lora_prompt, [prompt_gui, lora4_trigger_gui], [prompt_gui])
1672
  lora5_copy_button.click(apply_lora_prompt, [prompt_gui, lora5_trigger_gui], [prompt_gui])
1673
+
1674
+ search_civitai_button_lora.click(
1675
+ search_civitai_lora,
1676
+ [search_civitai_query_lora, search_civitai_basemodel_lora],
1677
+ [search_civitai_result_lora, search_civitai_desc_lora],
1678
+ queue=True,
1679
+ show_progress="minimal",
1680
+ )
1681
+ search_civitai_query_lora.submit(
1682
+ search_civitai_lora,
1683
+ [search_civitai_query_lora, search_civitai_basemodel_lora],
1684
+ [search_civitai_result_lora, search_civitai_desc_lora],
1685
+ queue=True,
1686
+ show_progress="minimal",
1687
+ )
1688
+ search_civitai_result_lora.change(
1689
+ select_civitai_lora,
1690
+ [search_civitai_result_lora],
1691
+ [text_lora, search_civitai_desc_lora],
1692
+ )
1693
 
1694
  use_textual_inversion_gui.change(set_textual_inversion_prompt, [use_textual_inversion_gui, prompt_gui, neg_prompt_gui, prompt_syntax_gui], [prompt_gui, neg_prompt_gui])
1695
 
 
1736
  outputs=[prompt_gui],
1737
  )
1738
 
1739
+ random_character_gui.click(select_random_character, [series_dbt, character_dbt], [series_dbt, character_dbt])
1740
+
1741
  generate_db_random_button.click(
1742
  parse_upsampling_output(v2b.on_generate),
1743
  inputs=[
 
1887
  with gr.Group():
1888
  input_character = gr.Textbox(label="Character tags", placeholder="hatsune miku")
1889
  input_copyright = gr.Textbox(label="Copyright tags", placeholder="vocaloid")
1890
+ pick_random_character = gr.Button(value="Pick a random character 🎲", size="sm")
1891
  input_general = gr.TextArea(label="General tags", lines=4, placeholder="1girl, ...", value="")
1892
  input_tags_to_copy = gr.Textbox(value="", visible=False)
1893
  copy_input_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
 
1953
  gradio_copy_text, inputs=[input_tags_to_copy], js=COPY_ACTION_JS,
1954
  )
1955
 
1956
+ pick_random_character.click(select_random_character, [input_copyright, input_character], [input_copyright, input_character])
1957
+
1958
  generate_btn.click(
1959
  parse_upsampling_output(v2.on_generate),
1960
  inputs=[
modutils.py CHANGED
@@ -7,6 +7,34 @@ from PIL import Image
7
  HF_LORA_PRIVATE_REPOS = ['John6666/loratest1', 'John6666/loratest3', 'John6666/loratest4', 'John6666/loratest6', 'John6666/loratest10', 'John6666/loratest']
8
  HF_LORA_ESSENTIAL_PRIVATE_REPO = 'John6666/loratest1'
9
  directory_loras = 'loras'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
 
12
  def get_model_list(directory_path):
@@ -294,9 +322,7 @@ def get_civitai_info(path):
294
  if path in set(civitai_not_exists_list): return ["", "", "", "", ""]
295
  from pathlib import Path
296
  if not Path(path).exists(): return None
297
- from fake_useragent import UserAgent
298
- ua = UserAgent()
299
- user_agent = ua.random
300
  headers = {'User-Agent': user_agent, 'content-type': 'application/json'}
301
  base_url = 'https://civitai.com/api/v1/model-versions/by-hash/'
302
  params = {}
@@ -442,6 +468,60 @@ def move_file_lora(filepaths):
442
  ),
443
 
444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
  quality_prompt_list = [
446
  {
447
  "name": "None",
 
7
  HF_LORA_PRIVATE_REPOS = ['John6666/loratest1', 'John6666/loratest3', 'John6666/loratest4', 'John6666/loratest6', 'John6666/loratest10', 'John6666/loratest']
8
  HF_LORA_ESSENTIAL_PRIVATE_REPO = 'John6666/loratest1'
9
  directory_loras = 'loras'
10
+ CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
11
+
12
+
13
+ def get_user_agent():
14
+ return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
15
+
16
+
17
+ def change_interface_mode(mode: str):
18
+ if mode == "Fast":
19
+ return gr.update(open=False), gr.update(visible=True), gr.update(open=False), gr.update(open=False),\
20
+ gr.update(visible=True), gr.update(open=False), gr.update(visible=True), gr.update(visible=True),\
21
+ gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),\
22
+ gr.update(visible=True), gr.update(visible=True), gr.update(value="Fast")
23
+ elif mode == "Simple": # t2i mode
24
+ return gr.update(open=True), gr.update(visible=True), gr.update(open=True), gr.update(open=True),\
25
+ gr.update(visible=True), gr.update(open=False), gr.update(visible=False), gr.update(visible=False),\
26
+ gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),\
27
+ gr.update(visible=False), gr.update(visible=False), gr.update(value="Standard")
28
+ elif mode == "LoRA": # t2i LoRA mode
29
+ return gr.update(open=True), gr.update(visible=True), gr.update(open=True), gr.update(open=False),\
30
+ gr.update(visible=True), gr.update(open=True), gr.update(visible=True), gr.update(visible=True),\
31
+ gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),\
32
+ gr.update(visible=True), gr.update(visible=False), gr.update(value="Standard")
33
+ else: # Standard
34
+ return gr.update(open=False), gr.update(visible=True), gr.update(open=False), gr.update(open=False),\
35
+ gr.update(visible=True), gr.update(open=False), gr.update(visible=True), gr.update(visible=True),\
36
+ gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),\
37
+ gr.update(visible=True), gr.update(visible=True), gr.update(value="Standard")
38
 
39
 
40
  def get_model_list(directory_path):
 
322
  if path in set(civitai_not_exists_list): return ["", "", "", "", ""]
323
  from pathlib import Path
324
  if not Path(path).exists(): return None
325
+ user_agent = get_user_agent()
 
 
326
  headers = {'User-Agent': user_agent, 'content-type': 'application/json'}
327
  base_url = 'https://civitai.com/api/v1/model-versions/by-hash/'
328
  params = {}
 
468
  ),
469
 
470
 
471
+ def search_lora_on_civitai(query: str, allow_model: list[str]):
472
+ import requests
473
+ if not query: return None
474
+ user_agent = get_user_agent()
475
+ headers = {'User-Agent': user_agent, 'content-type': 'application/json'}
476
+ base_url = 'https://civitai.com/api/v1/models'
477
+ params = {'query': query, 'types': ['LORA'], 'sort': 'Highest Rated', 'period': 'AllTime',
478
+ 'nsfw': 'true'}
479
+ r = requests.get(base_url, params=params, headers=headers, timeout=(3.0, 30))
480
+ if not r.ok: return None
481
+ json = r.json()
482
+ if not 'items' in json: return None
483
+ items = []
484
+ for j in json['items']:
485
+ for model in j['modelVersions']:
486
+ item = {}
487
+ if not model['baseModel'] in set(allow_model): continue
488
+ item['name'] = j['name']
489
+ item['creator'] = j['creator']['username']
490
+ item['tags'] = j['tags']
491
+ item['model_name'] = model['name']
492
+ item['base_model'] = model['baseModel']
493
+ item['dl_url'] = model['downloadUrl']
494
+ item['md'] = f'<img src="{model["images"][0]["url"]}" alt="thumbnail" width="150" height="240"><br>[LoRA Model URL](https://civitai.com/models/{j["id"]})'
495
+ items.append(item)
496
+ return items
497
+
498
+
499
+ civitai_lora_last_results = {}
500
+
501
+
502
+ def search_civitai_lora(query, base_model):
503
+ global civitai_lora_last_results
504
+ items = search_lora_on_civitai(query, base_model)
505
+ if not items: return gr.update(choices=[("", "")], value="", visible=False), gr.update(value="", visible=False)
506
+ civitai_lora_last_results = {}
507
+ choices = []
508
+ for item in items:
509
+ base_model_name = "Pony🐴" if item['base_model'] == "Pony" else item['base_model']
510
+ name = f"{item['name']} (for {base_model_name} / By {item['creator']} / Tags={', '.join(item['tags'])})"
511
+ value = item['dl_url']
512
+ choices.append((name, value))
513
+ civitai_lora_last_results[value] = item['md']
514
+ if not choices: return gr.update(choices=[("", "")], value="", visible=False), gr.update(value="", visible=False)
515
+ md = civitai_lora_last_results.get(choices[0][1], "None")
516
+ return gr.update(choices=choices, value=choices[0][1], visible=True), gr.update(value=md, visible=True)
517
+
518
+
519
+ def select_civitai_lora(search_result):
520
+ if not "http" in search_result: return gr.update(value=""), gr.update(value="None", visible=True)
521
+ md = civitai_lora_last_results.get(search_result, "None")
522
+ return gr.update(value=search_result), gr.update(value=md, visible=True)
523
+
524
+
525
  quality_prompt_list = [
526
  {
527
  "name": "None",
tagger.py CHANGED
@@ -81,6 +81,14 @@ def character_list_to_series_list(character_list):
81
  return output_series_tag
82
 
83
 
 
 
 
 
 
 
 
 
84
  def danbooru_to_e621(dtag, e621_dict):
85
  def d_to_e(match, e621_dict):
86
  dtag = match.group(0)
 
81
  return output_series_tag
82
 
83
 
84
+ def select_random_character(series: str, character: str):
85
+ from random import randrange
86
+ character_list = list(anime_series_dict.keys())
87
+ character = character_list[randrange(len(character_list) - 1)]
88
+ series = anime_series_dict.get(character.split(",")[0].strip(), "")
89
+ return series, character
90
+
91
+
92
  def danbooru_to_e621(dtag, e621_dict):
93
  def d_to_e(match, e621_dict):
94
  dtag = match.group(0)