From 68999d0b15d612965e7bc7feb62d6b4d55e112fa Mon Sep 17 00:00:00 2001
From: space-nuko <24979496+space-nuko@users.noreply.github.com>
Date: Sat, 25 Mar 2023 12:52:14 -0400
Subject: Add upscale slider to img2img
---
modules/ui.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 65 insertions(+), 2 deletions(-)
(limited to 'modules/ui.py')
diff --git a/modules/ui.py b/modules/ui.py
index af8546c2..bb548f92 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -15,6 +15,7 @@ import warnings
import gradio as gr
import gradio.routes
import gradio.utils
+from gradio.events import Releaseable
import numpy as np
from PIL import Image, PngImagePlugin
from modules.call_queue import wrap_gradio_gpu_call, wrap_queued_call, wrap_gradio_call
@@ -138,6 +139,26 @@ def calc_resolution_hires(enable, width, height, hr_scale, hr_resize_x, hr_resiz
return f"resize: from {p.width}x{p.height} to {p.hr_resize_x or p.hr_upscale_to_x}x{p.hr_resize_y or p.hr_upscale_to_y}"
+def calc_resolution_img2img(mode, scale, resize_x, resize_y, resize_mode, *i2i_images):
+ init_img = None
+ if mode in {0, 1, 3, 4}:
+ init_img = i2i_images[mode]
+ elif mode == 2:
+ init_img = i2i_images[mode]["image"]
+
+ if not init_img:
+ return ""
+
+ if scale > 1:
+ width = int(init_img.width * scale)
+ height = int(init_img.height * scale)
+ else:
+ width = resize_x
+ height = resize_y
+
+ return f"resize: from {init_img.width}x{init_img.height} to {width}x{height}"
+
+
def apply_styles(prompt, prompt_neg, styles):
prompt = shared.prompt_styles.apply_styles_to_prompt(prompt, styles)
prompt_neg = shared.prompt_styles.apply_negative_styles_to_prompt(prompt_neg, styles)
@@ -755,8 +776,13 @@ def create_ui():
elif category == "dimensions":
with FormRow():
with gr.Column(elem_id="img2img_column_size", scale=4):
- width = gr.Slider(minimum=64, maximum=2048, step=8, label="Width", value=512, elem_id="img2img_width")
- height = gr.Slider(minimum=64, maximum=2048, step=8, label="Height", value=512, elem_id="img2img_height")
+ with FormRow(variant="compact"):
+ final_resolution = FormHTML(value="", elem_id="img2img_finalres", label="Upscaled resolution", interactive=False)
+ with FormRow(variant="compact"):
+ scale = gr.Slider(minimum=1.0, maximum=4.0, step=0.05, label="Upscale by", value=1.0, elem_id="img2img_scale")
+ with FormRow(variant="compact"):
+ width = gr.Slider(minimum=64, maximum=2048, step=8, label="Width", value=512, elem_id="img2img_width")
+ height = gr.Slider(minimum=64, maximum=2048, step=8, label="Height", value=512, elem_id="img2img_height")
with gr.Column(elem_id="img2img_dimensions_row", scale=1, elem_classes="dimensions-tools"):
res_switch_btn = ToolButton(value=switch_values_symbol, elem_id="img2img_res_switch_btn")
@@ -824,6 +850,41 @@ def create_ui():
outputs=[inpaint_controls, mask_alpha],
)
+ img2img_resolution_preview_inputs = [dummy_component, # filled in by selected img2img tab index in _js
+ scale, width, height, resize_mode,
+ init_img, sketch, init_img_with_mask, inpaint_color_sketch, init_img_inpaint]
+ for input in img2img_resolution_preview_inputs:
+ if isinstance(input, Releaseable):
+ input.release(
+ fn=calc_resolution_img2img,
+ _js="get_img2img_tab_index_for_res_preview",
+ inputs=img2img_resolution_preview_inputs,
+ outputs=[final_resolution],
+ show_progress=False,
+ )
+ input.release(
+ None,
+ _js="onCalcResolutionImg2Img",
+ inputs=img2img_resolution_preview_inputs,
+ outputs=[],
+ show_progress=False,
+ )
+ else:
+ input.change(
+ fn=calc_resolution_img2img,
+ _js="get_img2img_tab_index_for_res_preview",
+ inputs=img2img_resolution_preview_inputs,
+ outputs=[final_resolution],
+ show_progress=False,
+ )
+ input.change(
+ None,
+ _js="onCalcResolutionImg2Img",
+ inputs=img2img_resolution_preview_inputs,
+ outputs=[],
+ show_progress=False,
+ )
+
img2img_gallery, generation_info, html_info, html_log = create_output_panel("img2img", opts.outdir_img2img_samples)
connect_reuse_seed(seed, reuse_seed, generation_info, dummy_component, is_subseed=False)
@@ -872,6 +933,7 @@ def create_ui():
subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w, seed_checkbox,
height,
width,
+ scale,
resize_mode,
inpaint_full_res,
inpaint_full_res_padding,
@@ -957,6 +1019,7 @@ def create_ui():
(seed, "Seed"),
(width, "Size-1"),
(height, "Size-2"),
+ (scale, "Img2Img Upscale"),
(batch_size, "Batch size"),
(subseed, "Variation seed"),
(subseed_strength, "Variation seed strength"),
--
cgit v1.2.3
From 7ea5d395c44be208f654b07ec7993aa2952f2510 Mon Sep 17 00:00:00 2001
From: space-nuko <24979496+space-nuko@users.noreply.github.com>
Date: Sun, 19 Feb 2023 03:45:43 -0800
Subject: Add upscaler to img2img
---
modules/ui.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
(limited to 'modules/ui.py')
diff --git a/modules/ui.py b/modules/ui.py
index bb548f92..24ab0af7 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -767,7 +767,7 @@ def create_ui():
)
with FormRow():
- resize_mode = gr.Radio(label="Resize mode", elem_id="resize_mode", choices=["Just resize", "Crop and resize", "Resize and fill", "Just resize (latent upscale)"], type="index", value="Just resize")
+ resize_mode = gr.Radio(label="Resize mode", elem_id="resize_mode", choices=["Just resize", "Crop and resize", "Resize and fill"], type="index", value="Just resize")
for category in ordered_ui_categories():
if category == "sampler":
@@ -797,7 +797,9 @@ def create_ui():
with FormRow():
cfg_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.5, label='CFG Scale', value=7.0, elem_id="img2img_cfg_scale")
image_cfg_scale = gr.Slider(minimum=0, maximum=3.0, step=0.05, label='Image CFG Scale', value=1.5, elem_id="img2img_image_cfg_scale", visible=shared.sd_model and shared.sd_model.cond_stage_key == "edit")
- denoising_strength = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='Denoising strength', value=0.75, elem_id="img2img_denoising_strength")
+ with FormRow():
+ upscaler = gr.Dropdown(label="Upscaler", elem_id="img2img_upscaler", choices=[*shared.latent_upscale_modes, *[x.name for x in shared.sd_upscalers]], value=shared.latent_upscale_default_mode)
+ denoising_strength = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='Denoising strength', value=0.75, elem_id="img2img_denoising_strength")
elif category == "seed":
seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w, seed_checkbox = create_seed_inputs('img2img')
@@ -934,6 +936,7 @@ def create_ui():
height,
width,
scale,
+ upscaler,
resize_mode,
inpaint_full_res,
inpaint_full_res_padding,
@@ -1019,7 +1022,8 @@ def create_ui():
(seed, "Seed"),
(width, "Size-1"),
(height, "Size-2"),
- (scale, "Img2Img Upscale"),
+ (scale, "Img2Img upscale"),
+ (upscaler, "Img2Img upscaler"),
(batch_size, "Batch size"),
(subseed, "Variation seed"),
(subseed_strength, "Variation seed strength"),
--
cgit v1.2.3
From c5f9f7c23759f9a74fa2b563451569c8926604ba Mon Sep 17 00:00:00 2001
From: space-nuko <24979496+space-nuko@users.noreply.github.com>
Date: Sat, 25 Mar 2023 14:26:36 -0400
Subject: Use .success() callback on img2img preview inputs change
---
modules/ui.py | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
(limited to 'modules/ui.py')
diff --git a/modules/ui.py b/modules/ui.py
index 24ab0af7..40dd76f2 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -855,7 +855,7 @@ def create_ui():
img2img_resolution_preview_inputs = [dummy_component, # filled in by selected img2img tab index in _js
scale, width, height, resize_mode,
init_img, sketch, init_img_with_mask, inpaint_color_sketch, init_img_inpaint]
- for input in img2img_resolution_preview_inputs:
+ for input in img2img_resolution_preview_inputs[1:]:
if isinstance(input, Releaseable):
input.release(
fn=calc_resolution_img2img,
@@ -863,8 +863,7 @@ def create_ui():
inputs=img2img_resolution_preview_inputs,
outputs=[final_resolution],
show_progress=False,
- )
- input.release(
+ ).success(
None,
_js="onCalcResolutionImg2Img",
inputs=img2img_resolution_preview_inputs,
@@ -878,8 +877,7 @@ def create_ui():
inputs=img2img_resolution_preview_inputs,
outputs=[final_resolution],
show_progress=False,
- )
- input.change(
+ ).success(
None,
_js="onCalcResolutionImg2Img",
inputs=img2img_resolution_preview_inputs,
--
cgit v1.2.3
From c9647c8d23efa8c939c6af39878784e246082122 Mon Sep 17 00:00:00 2001
From: space-nuko <24979496+space-nuko@users.noreply.github.com>
Date: Sat, 25 Mar 2023 16:11:41 -0400
Subject: Support Gradio's theme API
---
modules/ui.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'modules/ui.py')
diff --git a/modules/ui.py b/modules/ui.py
index af8546c2..6e049881 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -1592,7 +1592,7 @@ def create_ui():
for _interface, label, _ifid in interfaces:
shared.tab_names.append(label)
- with gr.Blocks(css=css, analytics_enabled=False, title="Stable Diffusion") as demo:
+ with gr.Blocks(css=css, theme=shared.gradio_theme, analytics_enabled=False, title="Stable Diffusion") as demo:
with gr.Row(elem_id="quicksettings", variant="compact"):
for i, k, item in sorted(quicksettings_list, key=lambda x: quicksettings_names.get(x[1], x[0])):
component = create_setting_component(k, is_quicksettings=True)
--
cgit v1.2.3
From 77f9db3b080fafbc39c1b188777a93b5a1ab0f9e Mon Sep 17 00:00:00 2001
From: AUTOMATIC <16777216c@gmail.com>
Date: Mon, 27 Mar 2023 12:59:12 +0300
Subject: serve css as independent files
---
modules/ui.py | 74 +++++++++++++++++++++++++++++++++--------------------------
1 file changed, 41 insertions(+), 33 deletions(-)
(limited to 'modules/ui.py')
diff --git a/modules/ui.py b/modules/ui.py
index af8546c2..eb5fcd3f 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -70,17 +70,6 @@ def gr_show(visible=True):
sample_img2img = "assets/stable-samples/img2img/sketch-mountains-input.jpg"
sample_img2img = sample_img2img if os.path.exists(sample_img2img) else None
-css_hide_progressbar = """
-.wrap .m-12 svg { display:none!important; }
-.wrap .m-12::before { content:"Loading..." }
-.wrap .z-20 svg { display:none!important; }
-.wrap .z-20::before { content:"Loading..." }
-.wrap.cover-bg .z-20::before { content:"" }
-.progress-bar { display:none!important; }
-.meta-text { display:none!important; }
-.meta-text-center { display:none!important; }
-"""
-
# Using constants for these since the variation selector isn't visible.
# Important that they exactly match script.js for tooltip to work.
random_symbol = '\U0001f3b2\ufe0f' # 🎲️
@@ -1566,22 +1555,6 @@ def create_ui():
(train_interface, "Train", "ti"),
]
- css = ""
-
- for cssfile in modules.scripts.list_files_with_name("style.css"):
- if not os.path.isfile(cssfile):
- continue
-
- with open(cssfile, "r", encoding="utf8") as file:
- css += file.read() + "\n"
-
- if os.path.exists(os.path.join(data_path, "user.css")):
- with open(os.path.join(data_path, "user.css"), "r", encoding="utf8") as file:
- css += file.read() + "\n"
-
- if not cmd_opts.no_progressbar_hiding:
- css += css_hide_progressbar
-
interfaces += script_callbacks.ui_tabs_callback()
interfaces += [(settings_interface, "Settings", "settings")]
@@ -1592,7 +1565,7 @@ def create_ui():
for _interface, label, _ifid in interfaces:
shared.tab_names.append(label)
- with gr.Blocks(css=css, analytics_enabled=False, title="Stable Diffusion") as demo:
+ with gr.Blocks(analytics_enabled=False, title="Stable Diffusion") as demo:
with gr.Row(elem_id="quicksettings", variant="compact"):
for i, k, item in sorted(quicksettings_list, key=lambda x: quicksettings_names.get(x[1], x[0])):
component = create_setting_component(k, is_quicksettings=True)
@@ -1777,25 +1750,60 @@ def create_ui():
return demo
-def reload_javascript():
+def webpath(fn):
+ if fn.startswith(script_path):
+ web_path = os.path.relpath(fn, script_path).replace('\\', '/')
+ else:
+ web_path = os.path.abspath(fn)
+
+ return f'file={web_path}?{os.path.getmtime(fn)}'
+
+
+def javascript_html():
script_js = os.path.join(script_path, "script.js")
- head = f'\n'
+ head = f'\n'
inline = f"{localization.localization_js(shared.opts.localization)};"
if cmd_opts.theme is not None:
inline += f"set_theme('{cmd_opts.theme}');"
for script in modules.scripts.list_scripts("javascript", ".js"):
- head += f'\n'
+ head += f'\n'
for script in modules.scripts.list_scripts("javascript", ".mjs"):
- head += f'\n'
+ head += f'\n'
head += f'\n'
+ return head
+
+
+def css_html():
+ head = ""
+
+ def stylesheet(fn):
+ return f''
+
+ for cssfile in modules.scripts.list_files_with_name("style.css"):
+ if not os.path.isfile(cssfile):
+ continue
+
+ head += stylesheet(cssfile)
+
+ if os.path.exists(os.path.join(data_path, "user.css")):
+ head += stylesheet(os.path.join(data_path, "user.css"))
+
+ return head
+
+
+def reload_javascript():
+ js = javascript_html()
+ css = css_html()
+
def template_response(*args, **kwargs):
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
- res.body = res.body.replace(b'', f'{head}'.encode("utf8"))
+ res.body = res.body.replace(b'', f'{js}'.encode("utf8"))
+ res.body = res.body.replace(b'