Skip to content

Commit 35c45df

Browse files
committed
fix broken ↙ button, fix field paste ignoring most of useful fields for for #3768
1 parent beb6fc2 commit 35c45df

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

modules/generation_parameters_copypaste.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from modules.shared import script_path
77
from modules import shared
88
import tempfile
9-
from PIL import Image, PngImagePlugin
9+
from PIL import Image
1010

1111
re_param_code = r'\s*([\w ]+):\s*("(?:\\|\"|[^\"])+"|[^,]*)(?:,|$)'
1212
re_param = re.compile(re_param_code)
@@ -61,6 +61,24 @@ def add_paste_fields(tabname, init_img, fields):
6161
modules.ui.img2img_paste_fields = fields
6262

6363

64+
def integrate_settings_paste_fields(component_dict):
65+
from modules import ui
66+
67+
settings_map = {
68+
'sd_hypernetwork': 'Hypernet',
69+
'CLIP_stop_at_last_layers': 'Clip skip',
70+
'sd_model_checkpoint': 'Model hash',
71+
}
72+
settings_paste_fields = [
73+
(component_dict[k], lambda d, k=k, v=v: ui.apply_setting(k, d.get(v, None)))
74+
for k, v in settings_map.items()
75+
]
76+
77+
for tabname, info in paste_fields.items():
78+
if info["fields"] is not None:
79+
info["fields"] += settings_paste_fields
80+
81+
6482
def create_buttons(tabs_list):
6583
buttons = {}
6684
for tab in tabs_list:
@@ -87,24 +105,22 @@ def run_bind():
87105
)
88106
else:
89107
button.click(
90-
fn=lambda x:x,
108+
fn=lambda x: x,
91109
inputs=[send_image],
92110
outputs=[paste_fields[tab]["init_img"]],
93111
)
94112

95113
if send_generate_info and paste_fields[tab]["fields"] is not None:
96-
paste_field_names = ['Prompt', 'Negative prompt', 'Steps', 'Face restoration', 'Size-1', 'Size-2']
97-
if shared.opts.send_seed:
98-
paste_field_names += ["Seed"]
99114
if send_generate_info in paste_fields:
115+
paste_field_names = ['Prompt', 'Negative prompt', 'Steps', 'Face restoration', 'Size-1', 'Size-2'] + (["Seed"] if shared.opts.send_seed else [])
116+
100117
button.click(
101-
fn=lambda *x:x,
102-
inputs=[field for field,name in paste_fields[send_generate_info]["fields"] if name in paste_field_names],
103-
outputs=[field for field,name in paste_fields[tab]["fields"] if name in paste_field_names],
118+
fn=lambda *x: x,
119+
inputs=[field for field, name in paste_fields[send_generate_info]["fields"] if name in paste_field_names],
120+
outputs=[field for field, name in paste_fields[tab]["fields"] if name in paste_field_names],
104121
)
105-
106122
else:
107-
connect_paste(button, [(field, name) for field, name in paste_fields[tab]["fields"] if name in paste_field_names], send_generate_info)
123+
connect_paste(button, paste_fields[tab]["fields"], send_generate_info)
108124

109125
button.click(
110126
fn=None,

modules/ui.py

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ def refresh():
589589
)
590590
return refresh_button
591591

592+
592593
def create_output_panel(tabname, outdir):
593594
def open_folder(f):
594595
if not os.path.exists(f):
@@ -716,6 +717,7 @@ def create_ui(wrap_gradio_gpu_call):
716717
custom_inputs = modules.scripts.scripts_txt2img.setup_ui(is_img2img=False)
717718

718719
txt2img_gallery, generation_info, html_info = create_output_panel("txt2img", opts.outdir_txt2img_samples)
720+
parameters_copypaste.bind_buttons({"txt2img": txt2img_paste}, None, txt2img_prompt)
719721

720722
connect_reuse_seed(seed, reuse_seed, generation_info, dummy_component, is_subseed=False)
721723
connect_reuse_seed(subseed, reuse_subseed, generation_info, dummy_component, is_subseed=True)
@@ -784,7 +786,7 @@ def create_ui(wrap_gradio_gpu_call):
784786
]
785787
)
786788

787-
parameters_copypaste.add_paste_fields("txt2img", None, [
789+
txt2img_paste_fields = [
788790
(txt2img_prompt, "Prompt"),
789791
(txt2img_negative_prompt, "Negative prompt"),
790792
(steps, "Steps"),
@@ -805,7 +807,8 @@ def create_ui(wrap_gradio_gpu_call):
805807
(firstphase_width, "First pass size-1"),
806808
(firstphase_height, "First pass size-2"),
807809
*modules.scripts.scripts_txt2img.infotext_fields
808-
])
810+
]
811+
parameters_copypaste.add_paste_fields("txt2img", None, txt2img_paste_fields)
809812

810813
txt2img_preview_params = [
811814
txt2img_prompt,
@@ -893,6 +896,7 @@ def create_ui(wrap_gradio_gpu_call):
893896
custom_inputs = modules.scripts.scripts_img2img.setup_ui(is_img2img=True)
894897

895898
img2img_gallery, generation_info, html_info = create_output_panel("img2img", opts.outdir_img2img_samples)
899+
parameters_copypaste.bind_buttons({"img2img": img2img_paste}, None, img2img_prompt)
896900

897901
connect_reuse_seed(seed, reuse_seed, generation_info, dummy_component, is_subseed=False)
898902
connect_reuse_seed(subseed, reuse_subseed, generation_info, dummy_component, is_subseed=True)
@@ -1038,7 +1042,6 @@ def create_ui(wrap_gradio_gpu_call):
10381042
parameters_copypaste.add_paste_fields("img2img", init_img, img2img_paste_fields)
10391043
parameters_copypaste.add_paste_fields("inpaint", init_img_with_mask, img2img_paste_fields)
10401044

1041-
10421045
with gr.Blocks(analytics_enabled=False) as extras_interface:
10431046
with gr.Row().style(equal_height=False):
10441047
with gr.Column(variant='panel'):
@@ -1050,12 +1053,8 @@ def create_ui(wrap_gradio_gpu_call):
10501053
image_batch = gr.File(label="Batch Process", file_count="multiple", interactive=True, type="file")
10511054

10521055
with gr.TabItem('Batch from Directory'):
1053-
extras_batch_input_dir = gr.Textbox(label="Input directory", **shared.hide_dirs,
1054-
placeholder="A directory on the same machine where the server is running."
1055-
)
1056-
extras_batch_output_dir = gr.Textbox(label="Output directory", **shared.hide_dirs,
1057-
placeholder="Leave blank to save images to the default path."
1058-
)
1056+
extras_batch_input_dir = gr.Textbox(label="Input directory", **shared.hide_dirs, placeholder="A directory on the same machine where the server is running.")
1057+
extras_batch_output_dir = gr.Textbox(label="Output directory", **shared.hide_dirs, placeholder="Leave blank to save images to the default path.")
10591058
show_extras_results = gr.Checkbox(label='Show result images', value=True)
10601059

10611060
with gr.Tabs(elem_id="extras_resize_mode"):
@@ -1087,7 +1086,6 @@ def create_ui(wrap_gradio_gpu_call):
10871086

10881087
submit = gr.Button('Generate', elem_id="extras_generate", variant='primary')
10891088

1090-
10911089
result_images, html_info_x, html_info = create_output_panel("extras", opts.outdir_extras_samples)
10921090

10931091
submit.click(
@@ -1121,7 +1119,6 @@ def create_ui(wrap_gradio_gpu_call):
11211119
)
11221120
parameters_copypaste.add_paste_fields("extras", extras_image, None)
11231121

1124-
11251122
extras_image.change(
11261123
fn=modules.extras.clear_cache,
11271124
inputs=[], outputs=[]
@@ -1587,9 +1584,6 @@ def request_restart():
15871584
if column is not None:
15881585
column.__exit__()
15891586

1590-
1591-
1592-
15931587
interfaces = [
15941588
(txt2img_interface, "txt2img", "txt2img"),
15951589
(img2img_interface, "img2img", "img2img"),
@@ -1599,10 +1593,6 @@ def request_restart():
15991593
(train_interface, "Train", "ti"),
16001594
]
16011595

1602-
interfaces += script_callbacks.ui_tabs_callback()
1603-
1604-
interfaces += [(settings_interface, "Settings", "settings")]
1605-
16061596
css = ""
16071597

16081598
for cssfile in modules.scripts.list_files_with_name("style.css"):
@@ -1619,6 +1609,9 @@ def request_restart():
16191609
if not cmd_opts.no_progressbar_hiding:
16201610
css += css_hide_progressbar
16211611

1612+
interfaces += script_callbacks.ui_tabs_callback()
1613+
interfaces += [(settings_interface, "Settings", "settings")]
1614+
16221615
with gr.Blocks(css=css, analytics_enabled=False, title="Stable Diffusion") as demo:
16231616
with gr.Row(elem_id="quicksettings"):
16241617
for i, k, item in quicksettings_list:
@@ -1627,6 +1620,9 @@ def request_restart():
16271620

16281621
settings_interface.gradio_ref = demo
16291622

1623+
parameters_copypaste.integrate_settings_paste_fields(component_dict)
1624+
parameters_copypaste.run_bind()
1625+
16301626
with gr.Tabs(elem_id="tabs") as tabs:
16311627
for interface, label, ifid in interfaces:
16321628
with gr.TabItem(label, id=ifid, elem_id='tab_' + ifid):
@@ -1681,15 +1677,6 @@ def modelmerger(*args):
16811677
]
16821678
)
16831679

1684-
1685-
settings_map = {
1686-
'sd_hypernetwork': 'Hypernet',
1687-
'CLIP_stop_at_last_layers': 'Clip skip',
1688-
'sd_model_checkpoint': 'Model hash',
1689-
}
1690-
1691-
parameters_copypaste.run_bind()
1692-
16931680
ui_config_file = cmd_opts.ui_config_file
16941681
ui_settings = {}
16951682
settings_count = len(ui_settings)
@@ -1708,7 +1695,7 @@ def loadsave(path, x):
17081695
def apply_field(obj, field, condition=None, init_field=None):
17091696
key = path + "/" + field
17101697

1711-
if getattr(obj,'custom_script_source',None) is not None:
1698+
if getattr(obj, 'custom_script_source', None) is not None:
17121699
key = 'customscript/' + obj.custom_script_source + '/' + key
17131700

17141701
if getattr(obj, 'do_not_save_to_config', False):

0 commit comments

Comments
 (0)