mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-06-07 21:20:49 +00:00
use re instead of hardcoding
Now supports all natively provided upscaler as well
This commit is contained in:
parent
d18eb10ecd
commit
fd71b761ff
@ -5,6 +5,9 @@ from modules.ui_components import ResizeHandleRow
|
|||||||
|
|
||||||
|
|
||||||
def hook_scale_update(inputs):
|
def hook_scale_update(inputs):
|
||||||
|
import re
|
||||||
|
pattern = r'(\d)[xX]|[xX](\d)'
|
||||||
|
|
||||||
resize = upscaler = None
|
resize = upscaler = None
|
||||||
for script in inputs:
|
for script in inputs:
|
||||||
if script.label == "Resize":
|
if script.label == "Resize":
|
||||||
@ -15,13 +18,16 @@ def hook_scale_update(inputs):
|
|||||||
break
|
break
|
||||||
|
|
||||||
def update_scale(upscaler: str, slider: float):
|
def update_scale(upscaler: str, slider: float):
|
||||||
if upscaler[1] in ('x', 'X'):
|
match = re.search(pattern, upscaler)
|
||||||
try:
|
|
||||||
scale = int(upscaler[0])
|
|
||||||
return gr.update(value=scale)
|
|
||||||
except ValueError:
|
|
||||||
return gr.update(value=slider)
|
|
||||||
|
|
||||||
|
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)
|
return gr.update(value=slider)
|
||||||
|
|
||||||
if resize and upscaler:
|
if resize and upscaler:
|
||||||
|
Loading…
Reference in New Issue
Block a user