mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-12-29 19:05:05 +08:00
simplify code for #15244
This commit is contained in:
parent
afb9296e0d
commit
63c3c4dbc3
@ -101,7 +101,7 @@ options_templates.update(options_section(('upscaling', "Upscaling", "postprocess
|
|||||||
"DAT_tile": OptionInfo(192, "Tile size for DAT upscalers.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}).info("0 = no tiling"),
|
"DAT_tile": OptionInfo(192, "Tile size for DAT upscalers.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}).info("0 = no tiling"),
|
||||||
"DAT_tile_overlap": OptionInfo(8, "Tile overlap for DAT upscalers.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}).info("Low values = visible seam"),
|
"DAT_tile_overlap": OptionInfo(8, "Tile overlap for DAT upscalers.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}).info("Low values = visible seam"),
|
||||||
"upscaler_for_img2img": OptionInfo(None, "Upscaler for img2img", gr.Dropdown, lambda: {"choices": [x.name for x in shared.sd_upscalers]}),
|
"upscaler_for_img2img": OptionInfo(None, "Upscaler for img2img", gr.Dropdown, lambda: {"choices": [x.name for x in shared.sd_upscalers]}),
|
||||||
"scaleBy_from_upscaler": OptionInfo(False, "Automatically set the Scale by factor based on the name of the selected Upscaler.").info("Will not change the value when no matching pattern is found."),
|
"set_scale_by_when_changing_upscaler": OptionInfo(False, "Automatically set the Scale by factor based on the name of the selected Upscaler."),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
options_templates.update(options_section(('face-restoration', "Face restoration", "postprocessing"), {
|
options_templates.update(options_section(('face-restoration', "Face restoration", "postprocessing"), {
|
||||||
|
@ -4,36 +4,6 @@ import modules.infotext_utils as parameters_copypaste
|
|||||||
from modules.ui_components import ResizeHandleRow
|
from modules.ui_components import ResizeHandleRow
|
||||||
|
|
||||||
|
|
||||||
def hook_scale_update(inputs):
|
|
||||||
import re
|
|
||||||
pattern = r'(\d)[xX]|[xX](\d)'
|
|
||||||
|
|
||||||
resize = upscaler = None
|
|
||||||
for script in inputs:
|
|
||||||
if script.label == "Resize":
|
|
||||||
resize = script
|
|
||||||
elif script.label == "Upscaler 1":
|
|
||||||
upscaler = script
|
|
||||||
elif resize and upscaler:
|
|
||||||
break
|
|
||||||
|
|
||||||
def update_scale(upscaler: str, slider: float):
|
|
||||||
match = re.search(pattern, upscaler)
|
|
||||||
|
|
||||||
if match:
|
|
||||||
if match.group(1):
|
|
||||||
return gr.update(value=int(match.group(1)))
|
|
||||||
|
|
||||||
else:
|
|
||||||
return gr.update(value=int(match.group(2)))
|
|
||||||
|
|
||||||
else:
|
|
||||||
return gr.update(value=slider)
|
|
||||||
|
|
||||||
if resize and upscaler:
|
|
||||||
upscaler.input(update_scale, inputs=[upscaler, resize], outputs=[resize])
|
|
||||||
|
|
||||||
|
|
||||||
def create_ui():
|
def create_ui():
|
||||||
dummy_component = gr.Label(visible=False)
|
dummy_component = gr.Label(visible=False)
|
||||||
tab_index = gr.Number(value=0, visible=False)
|
tab_index = gr.Number(value=0, visible=False)
|
||||||
@ -53,8 +23,6 @@ def create_ui():
|
|||||||
show_extras_results = gr.Checkbox(label='Show result images', value=True, elem_id="extras_show_extras_results")
|
show_extras_results = gr.Checkbox(label='Show result images', value=True, elem_id="extras_show_extras_results")
|
||||||
|
|
||||||
script_inputs = scripts.scripts_postproc.setup_ui()
|
script_inputs = scripts.scripts_postproc.setup_ui()
|
||||||
if getattr(shared.opts, 'scaleBy_from_upscaler', False):
|
|
||||||
hook_scale_update(script_inputs)
|
|
||||||
|
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
toprow = ui_toprow.Toprow(is_compact=True, is_img2img=False, id_part="extras")
|
toprow = ui_toprow.Toprow(is_compact=True, is_img2img=False, id_part="extras")
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@ -39,10 +41,22 @@ class ScriptPostprocessingUpscale(scripts_postprocessing.ScriptPostprocessing):
|
|||||||
extras_upscaler_2 = gr.Dropdown(label='Upscaler 2', elem_id="extras_upscaler_2", choices=[x.name for x in shared.sd_upscalers], value=shared.sd_upscalers[0].name)
|
extras_upscaler_2 = gr.Dropdown(label='Upscaler 2', elem_id="extras_upscaler_2", choices=[x.name for x in shared.sd_upscalers], value=shared.sd_upscalers[0].name)
|
||||||
extras_upscaler_2_visibility = gr.Slider(minimum=0.0, maximum=1.0, step=0.001, label="Upscaler 2 visibility", value=0.0, elem_id="extras_upscaler_2_visibility")
|
extras_upscaler_2_visibility = gr.Slider(minimum=0.0, maximum=1.0, step=0.001, label="Upscaler 2 visibility", value=0.0, elem_id="extras_upscaler_2_visibility")
|
||||||
|
|
||||||
|
def on_selected_upscale_method(upscale_method):
|
||||||
|
if not shared.opts.set_scale_by_when_changing_upscaler:
|
||||||
|
return gr.update()
|
||||||
|
|
||||||
|
match = re.search(r'(\d)[xX]|[xX](\d)', upscale_method)
|
||||||
|
if not match:
|
||||||
|
return gr.update()
|
||||||
|
|
||||||
|
return gr.update(value=int(match.group(1) or match.group(2)))
|
||||||
|
|
||||||
upscaling_res_switch_btn.click(lambda w, h: (h, w), inputs=[upscaling_resize_w, upscaling_resize_h], outputs=[upscaling_resize_w, upscaling_resize_h], show_progress=False)
|
upscaling_res_switch_btn.click(lambda w, h: (h, w), inputs=[upscaling_resize_w, upscaling_resize_h], outputs=[upscaling_resize_w, upscaling_resize_h], show_progress=False)
|
||||||
tab_scale_by.select(fn=lambda: 0, inputs=[], outputs=[selected_tab])
|
tab_scale_by.select(fn=lambda: 0, inputs=[], outputs=[selected_tab])
|
||||||
tab_scale_to.select(fn=lambda: 1, inputs=[], outputs=[selected_tab])
|
tab_scale_to.select(fn=lambda: 1, inputs=[], outputs=[selected_tab])
|
||||||
|
|
||||||
|
extras_upscaler_1.change(on_selected_upscale_method, inputs=[extras_upscaler_1], outputs=[upscaling_resize], show_progress="hidden")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"upscale_mode": selected_tab,
|
"upscale_mode": selected_tab,
|
||||||
"upscale_by": upscaling_resize,
|
"upscale_by": upscaling_resize,
|
||||||
|
Loading…
Reference in New Issue
Block a user