Update ui.py
Browse files
ui.py
CHANGED
|
@@ -20,7 +20,7 @@ from PIL import Image, PngImagePlugin
|
|
| 20 |
from modules.call_queue import wrap_gradio_gpu_call, wrap_queued_call, wrap_gradio_call
|
| 21 |
|
| 22 |
from modules import sd_hijack, sd_models, localization, script_callbacks, ui_extensions, deepbooru, sd_vae, extra_networks, postprocessing, ui_components, ui_common, ui_postprocessing
|
| 23 |
-
from modules.ui_components import FormRow, FormGroup, ToolButton, FormHTML
|
| 24 |
from modules.paths import script_path, data_path
|
| 25 |
|
| 26 |
from modules.shared import opts, cmd_opts, restricted_opts
|
|
@@ -70,17 +70,6 @@ def gr_show(visible=True):
|
|
| 70 |
sample_img2img = "assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
| 71 |
sample_img2img = sample_img2img if os.path.exists(sample_img2img) else None
|
| 72 |
|
| 73 |
-
css_hide_progressbar = """
|
| 74 |
-
.wrap .m-12 svg { display:none!important; }
|
| 75 |
-
.wrap .m-12::before { content:"Loading..." }
|
| 76 |
-
.wrap .z-20 svg { display:none!important; }
|
| 77 |
-
.wrap .z-20::before { content:"Loading..." }
|
| 78 |
-
.wrap.cover-bg .z-20::before { content:"" }
|
| 79 |
-
.progress-bar { display:none!important; }
|
| 80 |
-
.meta-text { display:none!important; }
|
| 81 |
-
.meta-text-center { display:none!important; }
|
| 82 |
-
"""
|
| 83 |
-
|
| 84 |
# Using constants for these since the variation selector isn't visible.
|
| 85 |
# Important that they exactly match script.js for tooltip to work.
|
| 86 |
random_symbol = '\U0001f3b2\ufe0f' # 🎲️
|
|
@@ -89,7 +78,7 @@ paste_symbol = '\u2199\ufe0f' # ↙
|
|
| 89 |
refresh_symbol = '\U0001f504' # 🔄
|
| 90 |
save_style_symbol = '\U0001f4be' # 💾
|
| 91 |
apply_style_symbol = '\U0001f4cb' # 📋
|
| 92 |
-
clear_prompt_symbol = '\
|
| 93 |
extra_networks_symbol = '\U0001F3B4' # 🎴
|
| 94 |
switch_values_symbol = '\U000021C5' # ⇅
|
| 95 |
|
|
@@ -179,14 +168,13 @@ def interrogate_deepbooru(image):
|
|
| 179 |
|
| 180 |
|
| 181 |
def create_seed_inputs(target_interface):
|
| 182 |
-
with FormRow(elem_id=target_interface + '_seed_row'):
|
| 183 |
seed = (gr.Textbox if cmd_opts.use_textbox_seed else gr.Number)(label='Seed', value=-1, elem_id=target_interface + '_seed')
|
| 184 |
seed.style(container=False)
|
| 185 |
-
random_seed =
|
| 186 |
-
reuse_seed =
|
| 187 |
|
| 188 |
-
|
| 189 |
-
seed_checkbox = gr.Checkbox(label='Extra', elem_id=target_interface + '_subseed_show', value=False)
|
| 190 |
|
| 191 |
# Components to show/hide based on the 'Extra' checkbox
|
| 192 |
seed_extras = []
|
|
@@ -195,8 +183,8 @@ def create_seed_inputs(target_interface):
|
|
| 195 |
seed_extras.append(seed_extra_row_1)
|
| 196 |
subseed = gr.Number(label='Variation seed', value=-1, elem_id=target_interface + '_subseed')
|
| 197 |
subseed.style(container=False)
|
| 198 |
-
random_subseed =
|
| 199 |
-
reuse_subseed =
|
| 200 |
subseed_strength = gr.Slider(label='Variation strength', value=0.0, minimum=0, maximum=1, step=0.01, elem_id=target_interface + '_subseed_strength')
|
| 201 |
|
| 202 |
with FormRow(visible=False) as seed_extra_row_2:
|
|
@@ -291,19 +279,19 @@ def create_toprow(is_img2img):
|
|
| 291 |
with gr.Row():
|
| 292 |
with gr.Column(scale=80):
|
| 293 |
with gr.Row():
|
| 294 |
-
negative_prompt = gr.Textbox(label="Negative prompt", elem_id=f"{id_part}_neg_prompt", show_label=False, lines=
|
| 295 |
|
| 296 |
button_interrogate = None
|
| 297 |
button_deepbooru = None
|
| 298 |
if is_img2img:
|
| 299 |
-
with gr.Column(scale=1,
|
| 300 |
button_interrogate = gr.Button('Interrogate\nCLIP', elem_id="interrogate")
|
| 301 |
button_deepbooru = gr.Button('Interrogate\nDeepBooru', elem_id="deepbooru")
|
| 302 |
|
| 303 |
with gr.Column(scale=1, elem_id=f"{id_part}_actions_column"):
|
| 304 |
-
with gr.Row(elem_id=f"{id_part}_generate_box"):
|
| 305 |
-
interrupt = gr.Button('Interrupt', elem_id=f"{id_part}_interrupt")
|
| 306 |
-
skip = gr.Button('Skip', elem_id=f"{id_part}_skip")
|
| 307 |
submit = gr.Button('Generate', elem_id=f"{id_part}_generate", variant='primary')
|
| 308 |
|
| 309 |
skip.click(
|
|
@@ -325,9 +313,9 @@ def create_toprow(is_img2img):
|
|
| 325 |
prompt_style_apply = ToolButton(value=apply_style_symbol, elem_id=f"{id_part}_style_apply")
|
| 326 |
save_style = ToolButton(value=save_style_symbol, elem_id=f"{id_part}_style_create")
|
| 327 |
|
| 328 |
-
token_counter = gr.HTML(value="<span
|
| 329 |
token_button = gr.Button(visible=False, elem_id=f"{id_part}_token_button")
|
| 330 |
-
negative_token_counter = gr.HTML(value="<span
|
| 331 |
negative_token_button = gr.Button(visible=False, elem_id=f"{id_part}_negative_token_button")
|
| 332 |
|
| 333 |
clear_prompt_button.click(
|
|
@@ -479,7 +467,9 @@ def create_ui():
|
|
| 479 |
width = gr.Slider(minimum=64, maximum=2048, step=8, label="Width", value=512, elem_id="txt2img_width")
|
| 480 |
height = gr.Slider(minimum=64, maximum=2048, step=8, label="Height", value=512, elem_id="txt2img_height")
|
| 481 |
|
| 482 |
-
|
|
|
|
|
|
|
| 483 |
if opts.dimensions_and_batch_together:
|
| 484 |
with gr.Column(elem_id="txt2img_column_batch"):
|
| 485 |
batch_count = gr.Slider(minimum=1, step=1, label='Batch count', value=1, elem_id="txt2img_batch_count")
|
|
@@ -492,7 +482,7 @@ def create_ui():
|
|
| 492 |
seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w, seed_checkbox = create_seed_inputs('txt2img')
|
| 493 |
|
| 494 |
elif category == "checkboxes":
|
| 495 |
-
with FormRow(
|
| 496 |
restore_faces = gr.Checkbox(label='Restore faces', value=False, visible=len(shared.face_restorers) > 1, elem_id="txt2img_restore_faces")
|
| 497 |
tiling = gr.Checkbox(label='Tiling', value=False, elem_id="txt2img_tiling")
|
| 498 |
enable_hr = gr.Checkbox(label='Hires. fix', value=False, elem_id="txt2img_enable_hr")
|
|
@@ -586,7 +576,7 @@ def create_ui():
|
|
| 586 |
txt2img_prompt.submit(**txt2img_args)
|
| 587 |
submit.click(**txt2img_args)
|
| 588 |
|
| 589 |
-
res_switch_btn.click(lambda w, h: (h, w), inputs=[width, height], outputs=[width, height])
|
| 590 |
|
| 591 |
txt_prompt_img.change(
|
| 592 |
fn=modules.images.image_data,
|
|
@@ -757,7 +747,9 @@ def create_ui():
|
|
| 757 |
width = gr.Slider(minimum=64, maximum=2048, step=8, label="Width", value=512, elem_id="img2img_width")
|
| 758 |
height = gr.Slider(minimum=64, maximum=2048, step=8, label="Height", value=512, elem_id="img2img_height")
|
| 759 |
|
| 760 |
-
|
|
|
|
|
|
|
| 761 |
if opts.dimensions_and_batch_together:
|
| 762 |
with gr.Column(elem_id="img2img_column_batch"):
|
| 763 |
batch_count = gr.Slider(minimum=1, step=1, label='Batch count', value=1, elem_id="img2img_batch_count")
|
|
@@ -774,7 +766,7 @@ def create_ui():
|
|
| 774 |
seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w, seed_checkbox = create_seed_inputs('img2img')
|
| 775 |
|
| 776 |
elif category == "checkboxes":
|
| 777 |
-
with FormRow(
|
| 778 |
restore_faces = gr.Checkbox(label='Restore faces', value=False, visible=len(shared.face_restorers) > 1, elem_id="img2img_restore_faces")
|
| 779 |
tiling = gr.Checkbox(label='Tiling', value=False, elem_id="img2img_tiling")
|
| 780 |
|
|
@@ -904,7 +896,7 @@ def create_ui():
|
|
| 904 |
|
| 905 |
img2img_prompt.submit(**img2img_args)
|
| 906 |
submit.click(**img2img_args)
|
| 907 |
-
res_switch_btn.click(lambda w, h: (h, w), inputs=[width, height], outputs=[width, height])
|
| 908 |
|
| 909 |
img2img_interrogate.click(
|
| 910 |
fn=lambda *args: process_interrogate(interrogate, *args),
|
|
@@ -939,7 +931,7 @@ def create_ui():
|
|
| 939 |
)
|
| 940 |
|
| 941 |
token_button.click(fn=update_token_counter, inputs=[img2img_prompt, steps], outputs=[token_counter])
|
| 942 |
-
negative_token_button.click(fn=wrap_queued_call(update_token_counter), inputs=[
|
| 943 |
|
| 944 |
ui_extra_networks.setup_ui(extra_networks_ui_img2img, img2img_gallery)
|
| 945 |
|
|
@@ -986,16 +978,16 @@ def create_ui():
|
|
| 986 |
with gr.Row():
|
| 987 |
buttons = parameters_copypaste.create_buttons(["txt2img", "img2img", "inpaint", "extras"])
|
| 988 |
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
|
| 1000 |
def update_interp_description(value):
|
| 1001 |
interp_description_css = "<p style='margin-bottom: 2.5em'>{}</p>"
|
|
@@ -1491,11 +1483,33 @@ def create_ui():
|
|
| 1491 |
request_notifications = gr.Button(value='Request browser notifications', elem_id="request_notifications")
|
| 1492 |
download_localization = gr.Button(value='Download localization template', elem_id="download_localization")
|
| 1493 |
reload_script_bodies = gr.Button(value='Reload custom script bodies (No ui updates, No restart)', variant='secondary', elem_id="settings_reload_script_bodies")
|
|
|
|
|
|
|
|
|
|
| 1494 |
|
| 1495 |
with gr.TabItem("Licenses"):
|
| 1496 |
gr.HTML(shared.html("licenses.html"), elem_id="licenses")
|
| 1497 |
|
| 1498 |
gr.Button(value="Show all pages", elem_id="settings_show_all_pages")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1499 |
|
| 1500 |
request_notifications.click(
|
| 1501 |
fn=lambda: None,
|
|
@@ -1541,29 +1555,17 @@ def create_ui():
|
|
| 1541 |
(train_interface, "Train", "ti"),
|
| 1542 |
]
|
| 1543 |
|
| 1544 |
-
css = ""
|
| 1545 |
-
|
| 1546 |
-
for cssfile in modules.scripts.list_files_with_name("style.css"):
|
| 1547 |
-
if not os.path.isfile(cssfile):
|
| 1548 |
-
continue
|
| 1549 |
-
|
| 1550 |
-
with open(cssfile, "r", encoding="utf8") as file:
|
| 1551 |
-
css += file.read() + "\n"
|
| 1552 |
-
|
| 1553 |
-
if os.path.exists(os.path.join(data_path, "user.css")):
|
| 1554 |
-
with open(os.path.join(data_path, "user.css"), "r", encoding="utf8") as file:
|
| 1555 |
-
css += file.read() + "\n"
|
| 1556 |
-
|
| 1557 |
-
if not cmd_opts.no_progressbar_hiding:
|
| 1558 |
-
css += css_hide_progressbar
|
| 1559 |
-
|
| 1560 |
interfaces += script_callbacks.ui_tabs_callback()
|
| 1561 |
interfaces += [(settings_interface, "Settings", "settings")]
|
| 1562 |
|
| 1563 |
extensions_interface = ui_extensions.create_ui()
|
| 1564 |
interfaces += [(extensions_interface, "Extensions", "extensions")]
|
| 1565 |
|
| 1566 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1567 |
with gr.Row(elem_id="quicksettings", variant="compact"):
|
| 1568 |
for i, k, item in sorted(quicksettings_list, key=lambda x: quicksettings_names.get(x[1], x[0])):
|
| 1569 |
component = create_setting_component(k, is_quicksettings=True)
|
|
@@ -1573,6 +1575,8 @@ def create_ui():
|
|
| 1573 |
|
| 1574 |
with gr.Tabs(elem_id="tabs") as tabs:
|
| 1575 |
for interface, label, ifid in interfaces:
|
|
|
|
|
|
|
| 1576 |
with gr.TabItem(label, id=ifid, elem_id='tab_' + ifid):
|
| 1577 |
interface.render()
|
| 1578 |
|
|
@@ -1592,11 +1596,13 @@ def create_ui():
|
|
| 1592 |
|
| 1593 |
for i, k, item in quicksettings_list:
|
| 1594 |
component = component_dict[k]
|
|
|
|
| 1595 |
|
| 1596 |
component.change(
|
| 1597 |
fn=lambda value, k=k: run_settings_single(value, key=k),
|
| 1598 |
inputs=[component],
|
| 1599 |
outputs=[component, text_settings],
|
|
|
|
| 1600 |
)
|
| 1601 |
|
| 1602 |
text_settings.change(
|
|
@@ -1622,6 +1628,7 @@ def create_ui():
|
|
| 1622 |
fn=get_settings_values,
|
| 1623 |
inputs=[],
|
| 1624 |
outputs=[component_dict[k] for k in component_keys],
|
|
|
|
| 1625 |
)
|
| 1626 |
|
| 1627 |
def modelmerger(*args):
|
|
@@ -1744,21 +1751,60 @@ def create_ui():
|
|
| 1744 |
return demo
|
| 1745 |
|
| 1746 |
|
| 1747 |
-
def
|
| 1748 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1749 |
|
| 1750 |
inline = f"{localization.localization_js(shared.opts.localization)};"
|
| 1751 |
if cmd_opts.theme is not None:
|
| 1752 |
inline += f"set_theme('{cmd_opts.theme}');"
|
| 1753 |
|
| 1754 |
for script in modules.scripts.list_scripts("javascript", ".js"):
|
| 1755 |
-
head += f'<script type="text/javascript" src="
|
|
|
|
|
|
|
|
|
|
| 1756 |
|
| 1757 |
head += f'<script type="text/javascript">{inline}</script>\n'
|
| 1758 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1759 |
def template_response(*args, **kwargs):
|
| 1760 |
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
|
| 1761 |
-
res.body = res.body.replace(b'</head>', f'{
|
|
|
|
| 1762 |
res.init_headers()
|
| 1763 |
return res
|
| 1764 |
|
|
|
|
| 20 |
from modules.call_queue import wrap_gradio_gpu_call, wrap_queued_call, wrap_gradio_call
|
| 21 |
|
| 22 |
from modules import sd_hijack, sd_models, localization, script_callbacks, ui_extensions, deepbooru, sd_vae, extra_networks, postprocessing, ui_components, ui_common, ui_postprocessing
|
| 23 |
+
from modules.ui_components import FormRow, FormColumn, FormGroup, ToolButton, FormHTML
|
| 24 |
from modules.paths import script_path, data_path
|
| 25 |
|
| 26 |
from modules.shared import opts, cmd_opts, restricted_opts
|
|
|
|
| 70 |
sample_img2img = "assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
| 71 |
sample_img2img = sample_img2img if os.path.exists(sample_img2img) else None
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
# Using constants for these since the variation selector isn't visible.
|
| 74 |
# Important that they exactly match script.js for tooltip to work.
|
| 75 |
random_symbol = '\U0001f3b2\ufe0f' # 🎲️
|
|
|
|
| 78 |
refresh_symbol = '\U0001f504' # 🔄
|
| 79 |
save_style_symbol = '\U0001f4be' # 💾
|
| 80 |
apply_style_symbol = '\U0001f4cb' # 📋
|
| 81 |
+
clear_prompt_symbol = '\U0001f5d1\ufe0f' # 🗑️
|
| 82 |
extra_networks_symbol = '\U0001F3B4' # 🎴
|
| 83 |
switch_values_symbol = '\U000021C5' # ⇅
|
| 84 |
|
|
|
|
| 168 |
|
| 169 |
|
| 170 |
def create_seed_inputs(target_interface):
|
| 171 |
+
with FormRow(elem_id=target_interface + '_seed_row', variant="compact"):
|
| 172 |
seed = (gr.Textbox if cmd_opts.use_textbox_seed else gr.Number)(label='Seed', value=-1, elem_id=target_interface + '_seed')
|
| 173 |
seed.style(container=False)
|
| 174 |
+
random_seed = ToolButton(random_symbol, elem_id=target_interface + '_random_seed')
|
| 175 |
+
reuse_seed = ToolButton(reuse_symbol, elem_id=target_interface + '_reuse_seed')
|
| 176 |
|
| 177 |
+
seed_checkbox = gr.Checkbox(label='Extra', elem_id=target_interface + '_subseed_show', value=False)
|
|
|
|
| 178 |
|
| 179 |
# Components to show/hide based on the 'Extra' checkbox
|
| 180 |
seed_extras = []
|
|
|
|
| 183 |
seed_extras.append(seed_extra_row_1)
|
| 184 |
subseed = gr.Number(label='Variation seed', value=-1, elem_id=target_interface + '_subseed')
|
| 185 |
subseed.style(container=False)
|
| 186 |
+
random_subseed = ToolButton(random_symbol, elem_id=target_interface + '_random_subseed')
|
| 187 |
+
reuse_subseed = ToolButton(reuse_symbol, elem_id=target_interface + '_reuse_subseed')
|
| 188 |
subseed_strength = gr.Slider(label='Variation strength', value=0.0, minimum=0, maximum=1, step=0.01, elem_id=target_interface + '_subseed_strength')
|
| 189 |
|
| 190 |
with FormRow(visible=False) as seed_extra_row_2:
|
|
|
|
| 279 |
with gr.Row():
|
| 280 |
with gr.Column(scale=80):
|
| 281 |
with gr.Row():
|
| 282 |
+
negative_prompt = gr.Textbox(label="Negative prompt", elem_id=f"{id_part}_neg_prompt", show_label=False, lines=3, placeholder="Negative prompt (press Ctrl+Enter or Alt+Enter to generate)")
|
| 283 |
|
| 284 |
button_interrogate = None
|
| 285 |
button_deepbooru = None
|
| 286 |
if is_img2img:
|
| 287 |
+
with gr.Column(scale=1, elem_classes="interrogate-col"):
|
| 288 |
button_interrogate = gr.Button('Interrogate\nCLIP', elem_id="interrogate")
|
| 289 |
button_deepbooru = gr.Button('Interrogate\nDeepBooru', elem_id="deepbooru")
|
| 290 |
|
| 291 |
with gr.Column(scale=1, elem_id=f"{id_part}_actions_column"):
|
| 292 |
+
with gr.Row(elem_id=f"{id_part}_generate_box", elem_classes="generate-box"):
|
| 293 |
+
interrupt = gr.Button('Interrupt', elem_id=f"{id_part}_interrupt", elem_classes="generate-box-interrupt")
|
| 294 |
+
skip = gr.Button('Skip', elem_id=f"{id_part}_skip", elem_classes="generate-box-skip")
|
| 295 |
submit = gr.Button('Generate', elem_id=f"{id_part}_generate", variant='primary')
|
| 296 |
|
| 297 |
skip.click(
|
|
|
|
| 313 |
prompt_style_apply = ToolButton(value=apply_style_symbol, elem_id=f"{id_part}_style_apply")
|
| 314 |
save_style = ToolButton(value=save_style_symbol, elem_id=f"{id_part}_style_create")
|
| 315 |
|
| 316 |
+
token_counter = gr.HTML(value="<span>0/75</span>", elem_id=f"{id_part}_token_counter", elem_classes=["token-counter"])
|
| 317 |
token_button = gr.Button(visible=False, elem_id=f"{id_part}_token_button")
|
| 318 |
+
negative_token_counter = gr.HTML(value="<span>0/75</span>", elem_id=f"{id_part}_negative_token_counter", elem_classes=["token-counter"])
|
| 319 |
negative_token_button = gr.Button(visible=False, elem_id=f"{id_part}_negative_token_button")
|
| 320 |
|
| 321 |
clear_prompt_button.click(
|
|
|
|
| 467 |
width = gr.Slider(minimum=64, maximum=2048, step=8, label="Width", value=512, elem_id="txt2img_width")
|
| 468 |
height = gr.Slider(minimum=64, maximum=2048, step=8, label="Height", value=512, elem_id="txt2img_height")
|
| 469 |
|
| 470 |
+
with gr.Column(elem_id="txt2img_dimensions_row", scale=1, elem_classes="dimensions-tools"):
|
| 471 |
+
res_switch_btn = ToolButton(value=switch_values_symbol, elem_id="txt2img_res_switch_btn")
|
| 472 |
+
|
| 473 |
if opts.dimensions_and_batch_together:
|
| 474 |
with gr.Column(elem_id="txt2img_column_batch"):
|
| 475 |
batch_count = gr.Slider(minimum=1, step=1, label='Batch count', value=1, elem_id="txt2img_batch_count")
|
|
|
|
| 482 |
seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w, seed_checkbox = create_seed_inputs('txt2img')
|
| 483 |
|
| 484 |
elif category == "checkboxes":
|
| 485 |
+
with FormRow(elem_classes="checkboxes-row", variant="compact"):
|
| 486 |
restore_faces = gr.Checkbox(label='Restore faces', value=False, visible=len(shared.face_restorers) > 1, elem_id="txt2img_restore_faces")
|
| 487 |
tiling = gr.Checkbox(label='Tiling', value=False, elem_id="txt2img_tiling")
|
| 488 |
enable_hr = gr.Checkbox(label='Hires. fix', value=False, elem_id="txt2img_enable_hr")
|
|
|
|
| 576 |
txt2img_prompt.submit(**txt2img_args)
|
| 577 |
submit.click(**txt2img_args)
|
| 578 |
|
| 579 |
+
res_switch_btn.click(lambda w, h: (h, w), inputs=[width, height], outputs=[width, height], show_progress=False)
|
| 580 |
|
| 581 |
txt_prompt_img.change(
|
| 582 |
fn=modules.images.image_data,
|
|
|
|
| 747 |
width = gr.Slider(minimum=64, maximum=2048, step=8, label="Width", value=512, elem_id="img2img_width")
|
| 748 |
height = gr.Slider(minimum=64, maximum=2048, step=8, label="Height", value=512, elem_id="img2img_height")
|
| 749 |
|
| 750 |
+
with gr.Column(elem_id="img2img_dimensions_row", scale=1, elem_classes="dimensions-tools"):
|
| 751 |
+
res_switch_btn = ToolButton(value=switch_values_symbol, elem_id="img2img_res_switch_btn")
|
| 752 |
+
|
| 753 |
if opts.dimensions_and_batch_together:
|
| 754 |
with gr.Column(elem_id="img2img_column_batch"):
|
| 755 |
batch_count = gr.Slider(minimum=1, step=1, label='Batch count', value=1, elem_id="img2img_batch_count")
|
|
|
|
| 766 |
seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w, seed_checkbox = create_seed_inputs('img2img')
|
| 767 |
|
| 768 |
elif category == "checkboxes":
|
| 769 |
+
with FormRow(elem_classes="checkboxes-row", variant="compact"):
|
| 770 |
restore_faces = gr.Checkbox(label='Restore faces', value=False, visible=len(shared.face_restorers) > 1, elem_id="img2img_restore_faces")
|
| 771 |
tiling = gr.Checkbox(label='Tiling', value=False, elem_id="img2img_tiling")
|
| 772 |
|
|
|
|
| 896 |
|
| 897 |
img2img_prompt.submit(**img2img_args)
|
| 898 |
submit.click(**img2img_args)
|
| 899 |
+
res_switch_btn.click(lambda w, h: (h, w), inputs=[width, height], outputs=[width, height], show_progress=False)
|
| 900 |
|
| 901 |
img2img_interrogate.click(
|
| 902 |
fn=lambda *args: process_interrogate(interrogate, *args),
|
|
|
|
| 931 |
)
|
| 932 |
|
| 933 |
token_button.click(fn=update_token_counter, inputs=[img2img_prompt, steps], outputs=[token_counter])
|
| 934 |
+
negative_token_button.click(fn=wrap_queued_call(update_token_counter), inputs=[img2img_negative_prompt, steps], outputs=[negative_token_counter])
|
| 935 |
|
| 936 |
ui_extra_networks.setup_ui(extra_networks_ui_img2img, img2img_gallery)
|
| 937 |
|
|
|
|
| 978 |
with gr.Row():
|
| 979 |
buttons = parameters_copypaste.create_buttons(["txt2img", "img2img", "inpaint", "extras"])
|
| 980 |
|
| 981 |
+
for tabname, button in buttons.items():
|
| 982 |
+
parameters_copypaste.register_paste_params_button(parameters_copypaste.ParamBinding(
|
| 983 |
+
paste_button=button, tabname=tabname, source_text_component=generation_info, source_image_component=image,
|
| 984 |
+
))
|
| 985 |
+
|
| 986 |
+
image.change(
|
| 987 |
+
fn=wrap_gradio_call(modules.extras.run_pnginfo),
|
| 988 |
+
inputs=[image],
|
| 989 |
+
outputs=[html, generation_info, html2],
|
| 990 |
+
)
|
| 991 |
|
| 992 |
def update_interp_description(value):
|
| 993 |
interp_description_css = "<p style='margin-bottom: 2.5em'>{}</p>"
|
|
|
|
| 1483 |
request_notifications = gr.Button(value='Request browser notifications', elem_id="request_notifications")
|
| 1484 |
download_localization = gr.Button(value='Download localization template', elem_id="download_localization")
|
| 1485 |
reload_script_bodies = gr.Button(value='Reload custom script bodies (No ui updates, No restart)', variant='secondary', elem_id="settings_reload_script_bodies")
|
| 1486 |
+
with gr.Row():
|
| 1487 |
+
unload_sd_model = gr.Button(value='Unload SD checkpoint to free VRAM', elem_id="sett_unload_sd_model")
|
| 1488 |
+
reload_sd_model = gr.Button(value='Reload the last SD checkpoint back into VRAM', elem_id="sett_reload_sd_model")
|
| 1489 |
|
| 1490 |
with gr.TabItem("Licenses"):
|
| 1491 |
gr.HTML(shared.html("licenses.html"), elem_id="licenses")
|
| 1492 |
|
| 1493 |
gr.Button(value="Show all pages", elem_id="settings_show_all_pages")
|
| 1494 |
+
|
| 1495 |
+
|
| 1496 |
+
def unload_sd_weights():
|
| 1497 |
+
modules.sd_models.unload_model_weights()
|
| 1498 |
+
|
| 1499 |
+
def reload_sd_weights():
|
| 1500 |
+
modules.sd_models.reload_model_weights()
|
| 1501 |
+
|
| 1502 |
+
unload_sd_model.click(
|
| 1503 |
+
fn=unload_sd_weights,
|
| 1504 |
+
inputs=[],
|
| 1505 |
+
outputs=[]
|
| 1506 |
+
)
|
| 1507 |
+
|
| 1508 |
+
reload_sd_model.click(
|
| 1509 |
+
fn=reload_sd_weights,
|
| 1510 |
+
inputs=[],
|
| 1511 |
+
outputs=[]
|
| 1512 |
+
)
|
| 1513 |
|
| 1514 |
request_notifications.click(
|
| 1515 |
fn=lambda: None,
|
|
|
|
| 1555 |
(train_interface, "Train", "ti"),
|
| 1556 |
]
|
| 1557 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1558 |
interfaces += script_callbacks.ui_tabs_callback()
|
| 1559 |
interfaces += [(settings_interface, "Settings", "settings")]
|
| 1560 |
|
| 1561 |
extensions_interface = ui_extensions.create_ui()
|
| 1562 |
interfaces += [(extensions_interface, "Extensions", "extensions")]
|
| 1563 |
|
| 1564 |
+
shared.tab_names = []
|
| 1565 |
+
for _interface, label, _ifid in interfaces:
|
| 1566 |
+
shared.tab_names.append(label)
|
| 1567 |
+
|
| 1568 |
+
with gr.Blocks(analytics_enabled=False, title="Stable Diffusion") as demo:
|
| 1569 |
with gr.Row(elem_id="quicksettings", variant="compact"):
|
| 1570 |
for i, k, item in sorted(quicksettings_list, key=lambda x: quicksettings_names.get(x[1], x[0])):
|
| 1571 |
component = create_setting_component(k, is_quicksettings=True)
|
|
|
|
| 1575 |
|
| 1576 |
with gr.Tabs(elem_id="tabs") as tabs:
|
| 1577 |
for interface, label, ifid in interfaces:
|
| 1578 |
+
if label in shared.opts.hidden_tabs:
|
| 1579 |
+
continue
|
| 1580 |
with gr.TabItem(label, id=ifid, elem_id='tab_' + ifid):
|
| 1581 |
interface.render()
|
| 1582 |
|
|
|
|
| 1596 |
|
| 1597 |
for i, k, item in quicksettings_list:
|
| 1598 |
component = component_dict[k]
|
| 1599 |
+
info = opts.data_labels[k]
|
| 1600 |
|
| 1601 |
component.change(
|
| 1602 |
fn=lambda value, k=k: run_settings_single(value, key=k),
|
| 1603 |
inputs=[component],
|
| 1604 |
outputs=[component, text_settings],
|
| 1605 |
+
show_progress=info.refresh is not None,
|
| 1606 |
)
|
| 1607 |
|
| 1608 |
text_settings.change(
|
|
|
|
| 1628 |
fn=get_settings_values,
|
| 1629 |
inputs=[],
|
| 1630 |
outputs=[component_dict[k] for k in component_keys],
|
| 1631 |
+
queue=False,
|
| 1632 |
)
|
| 1633 |
|
| 1634 |
def modelmerger(*args):
|
|
|
|
| 1751 |
return demo
|
| 1752 |
|
| 1753 |
|
| 1754 |
+
def webpath(fn):
|
| 1755 |
+
if fn.startswith(script_path):
|
| 1756 |
+
web_path = os.path.relpath(fn, script_path).replace('\\', '/')
|
| 1757 |
+
else:
|
| 1758 |
+
web_path = os.path.abspath(fn)
|
| 1759 |
+
|
| 1760 |
+
return f'file={web_path}?{os.path.getmtime(fn)}'
|
| 1761 |
+
|
| 1762 |
+
|
| 1763 |
+
def javascript_html():
|
| 1764 |
+
script_js = os.path.join(script_path, "script.js")
|
| 1765 |
+
head = f'<script type="text/javascript" src="{webpath(script_js)}"></script>\n'
|
| 1766 |
|
| 1767 |
inline = f"{localization.localization_js(shared.opts.localization)};"
|
| 1768 |
if cmd_opts.theme is not None:
|
| 1769 |
inline += f"set_theme('{cmd_opts.theme}');"
|
| 1770 |
|
| 1771 |
for script in modules.scripts.list_scripts("javascript", ".js"):
|
| 1772 |
+
head += f'<script type="text/javascript" src="{webpath(script.path)}"></script>\n'
|
| 1773 |
+
|
| 1774 |
+
for script in modules.scripts.list_scripts("javascript", ".mjs"):
|
| 1775 |
+
head += f'<script type="module" src="{webpath(script.path)}"></script>\n'
|
| 1776 |
|
| 1777 |
head += f'<script type="text/javascript">{inline}</script>\n'
|
| 1778 |
|
| 1779 |
+
return head
|
| 1780 |
+
|
| 1781 |
+
|
| 1782 |
+
def css_html():
|
| 1783 |
+
head = ""
|
| 1784 |
+
|
| 1785 |
+
def stylesheet(fn):
|
| 1786 |
+
return f'<link rel="stylesheet" property="stylesheet" href="{webpath(fn)}">'
|
| 1787 |
+
|
| 1788 |
+
for cssfile in modules.scripts.list_files_with_name("style.css"):
|
| 1789 |
+
if not os.path.isfile(cssfile):
|
| 1790 |
+
continue
|
| 1791 |
+
|
| 1792 |
+
head += stylesheet(cssfile)
|
| 1793 |
+
|
| 1794 |
+
if os.path.exists(os.path.join(data_path, "user.css")):
|
| 1795 |
+
head += stylesheet(os.path.join(data_path, "user.css"))
|
| 1796 |
+
|
| 1797 |
+
return head
|
| 1798 |
+
|
| 1799 |
+
|
| 1800 |
+
def reload_javascript():
|
| 1801 |
+
js = javascript_html()
|
| 1802 |
+
css = css_html()
|
| 1803 |
+
|
| 1804 |
def template_response(*args, **kwargs):
|
| 1805 |
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
|
| 1806 |
+
res.body = res.body.replace(b'</head>', f'{js}</head>'.encode("utf8"))
|
| 1807 |
+
res.body = res.body.replace(b'</body>', f'{css}</body>'.encode("utf8"))
|
| 1808 |
res.init_headers()
|
| 1809 |
return res
|
| 1810 |
|