Skip to content

Commit

Permalink
✨ 添加刷新列表按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulinyv committed Oct 10, 2024
1 parent dcf0a7e commit d841135
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
3 changes: 2 additions & 1 deletion files/languages/en/webui.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"noise_schedule": "Noise Schedule",
"steps": "Sampling Steps",
"smdyn": "sm_dyn (Enable requires sm to be enabled)",
"seed": "Random Seed"
"seed": "Random Seed",
"update_dropdown_list": "Update list"
},
"i2i": {
"tab": "Img2Img",
Expand Down
3 changes: 2 additions & 1 deletion files/languages/zh/webui.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"noise_schedule": "噪声计划表",
"steps": "采样步数",
"smdyn": "sm_dyn(开启需同时开启 sm)",
"seed": "随机种子"
"seed": "随机种子",
"update_dropdown_list": "更新列表"
},
"i2i": {
"tab": "图生图",
Expand Down
46 changes: 39 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ def main():
NOISE_SCHEDULE,
RESOLUTION,
SAMPLER,
cancel_probabilities_for_item,
gen_script,
open_folder,
read_json,
read_txt,
read_yaml,
return_names_list,
return_random,
return_source_or_type_list,
update_t2i_nsf_dropdown_list,
)

# ------------------------------ #
Expand Down Expand Up @@ -193,14 +196,26 @@ def open_output_folder_block(output_folder):
label="固定负面",
)
with gr.Row():
text2image_nsfw_fixed_source = gr.Dropdown(choices=["随机"], value="随机", label="固定角色出处")
text2image_nsfw_fixed_source = gr.Dropdown(
choices=["随机"]
+ return_source_or_type_list(
cancel_probabilities_for_item(read_yaml("./files/favorites/characters.yaml"))
),
value="随机",
label="固定角色出处",
)
text2image_nsfw_fixed_character = gr.Dropdown(
choices=return_names_list(read_yaml("./files/favorites/characters.yaml")),
value="随机",
label="固定角色",
)
text2image_nsfw_fixed_action_type = gr.Dropdown(
choices=["随机"], value="随机", label="固定动作类型"
choices=["随机"]
+ return_source_or_type_list(
cancel_probabilities_for_item(read_yaml("./files/favorites/actions.yaml"))
),
value="随机",
label="固定动作类型",
)
text2image_nsfw_fixed_action = gr.Dropdown(
choices=return_names_list(read_yaml("./files/favorites/actions.yaml")),
Expand All @@ -224,13 +239,14 @@ def open_output_folder_block(output_folder):
label="固定污渍",
)
with gr.Row():
text2image_nsfw_generate_button = gr.Button(webui_language["t2i"]["generate_button"], scale=2)
text2image_nsfw_generate_forever_button = gr.Button(
webui_language["random blue picture"]["generate_forever"], scale=1
text2image_nsfw_update_dropdown_list_button = gr.Button(
webui_language["t2i"]["update_dropdown_list"]
)
text2image_nsfw_stop_button = gr.Button(
webui_language["random blue picture"]["stop_button"], scale=1
text2image_nsfw_generate_button = gr.Button(webui_language["t2i"]["generate_button"])
text2image_nsfw_generate_forever_button = gr.Button(
webui_language["random blue picture"]["generate_forever"]
)
text2image_nsfw_stop_button = gr.Button(webui_language["random blue picture"]["stop_button"])
with gr.Row():
text2image_nsfw_output_image = gr.Image()
text2image_nsfw_forever_output_image = gr.Image()
Expand Down Expand Up @@ -304,6 +320,22 @@ def open_output_folder_block(output_folder):
],
outputs=None,
)
text2image_nsfw_update_dropdown_list_button.click(
update_t2i_nsf_dropdown_list,
inputs=None,
outputs=[
text2image_nsfw_fixed_artist,
text2image_nsfw_fixed_prefix,
text2image_nsfw_fixed_negative,
text2image_nsfw_fixed_source,
text2image_nsfw_fixed_character,
text2image_nsfw_fixed_action_type,
text2image_nsfw_fixed_action,
text2image_nsfw_fixed_emotion,
text2image_nsfw_fixed_surrounding,
text2image_nsfw_fixed_fixed_stains,
],
)
with gr.Tab(webui_language["random picture"]["tab"]):
with gr.Row():
with gr.Column(scale=6):
Expand Down
24 changes: 24 additions & 0 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from io import BytesIO
from pathlib import Path

import gradio as gr
import requests
import ujson as json
import yaml
Expand Down Expand Up @@ -408,6 +409,29 @@ def return_names_list(d: dict):
return names_list


def update_t2i_nsf_dropdown_list():
characters_file = read_yaml("./files/favorites/characters.yaml")
actions_file = read_yaml("./files/favorites/actions.yaml")
return (
gr.update(choices=return_names_list(read_yaml("./files/favorites/artists.yaml")), visible=True),
gr.update(choices=return_names_list(read_yaml("./files/favorites/prefixes.yaml")), visible=True),
gr.update(choices=return_names_list(read_yaml("./files/favorites/negative.yaml")), visible=True),
gr.update(
choices=["随机"] + return_source_or_type_list(cancel_probabilities_for_item(characters_file)),
visible=True,
),
gr.update(choices=return_names_list(characters_file), visible=True),
gr.update(
choices=["随机"] + return_source_or_type_list(cancel_probabilities_for_item(actions_file)),
visible=True,
),
gr.update(choices=return_names_list(actions_file), visible=True),
gr.update(choices=return_names_list(read_yaml("./files/favorites/emotions.yaml")), visible=True),
gr.update(choices=return_names_list(read_yaml("./files/favorites/surroundings.yaml")), visible=True),
gr.update(choices=return_names_list(read_yaml("./files/favorites/stains.yaml")), visible=True),
)


def file_path2name(path) -> str:
"""文件路径返还文件名
Expand Down

0 comments on commit d841135

Please sign in to comment.