mirror of https://github.com/vladmandic/automatic
fix gradio radio controls
parent
594f0331fd
commit
2e75ce2610
|
|
@ -808,8 +808,6 @@ def create_ui(startup_timer = None):
|
|||
button.click(
|
||||
fn=add_style,
|
||||
_js="ask_for_style_name",
|
||||
# Have to pass empty dummy component here, because the JavaScript and Python function have to accept
|
||||
# the same number of parameters, but we only know the style-name after the JavaScript prompt
|
||||
inputs=[dummy_component, prompt, negative_prompt],
|
||||
outputs=[txt2img_prompt_styles, img2img_prompt_styles],
|
||||
)
|
||||
|
|
@ -1059,31 +1057,10 @@ def create_ui(startup_timer = None):
|
|||
def reload_sd_weights():
|
||||
modules.sd_models.reload_model_weights()
|
||||
|
||||
unload_sd_model.click(
|
||||
fn=unload_sd_weights,
|
||||
inputs=[],
|
||||
outputs=[]
|
||||
)
|
||||
|
||||
reload_sd_model.click(
|
||||
fn=reload_sd_weights,
|
||||
inputs=[],
|
||||
outputs=[]
|
||||
)
|
||||
|
||||
request_notifications.click(
|
||||
fn=lambda: None,
|
||||
inputs=[],
|
||||
outputs=[],
|
||||
_js='function(){}'
|
||||
)
|
||||
|
||||
preview_theme.click(
|
||||
fn=None,
|
||||
_js='preview_theme',
|
||||
inputs=[dummy_component],
|
||||
outputs=[dummy_component]
|
||||
)
|
||||
unload_sd_model.click(fn=unload_sd_weights, inputs=[], outputs=[])
|
||||
reload_sd_model.click(fn=reload_sd_weights, inputs=[], outputs=[])
|
||||
request_notifications.click(fn=lambda: None, inputs=[], outputs=[], _js='function(){}')
|
||||
preview_theme.click(fn=None, _js='preview_theme', inputs=[dummy_component], outputs=[dummy_component])
|
||||
|
||||
startup_timer.record("ui-settings")
|
||||
|
||||
|
|
@ -1140,7 +1117,6 @@ def create_ui(startup_timer = None):
|
|||
for _i, k, _item in quicksettings_list:
|
||||
component = component_dict[k]
|
||||
info = opts.data_labels[k]
|
||||
|
||||
change_handler = component.release if hasattr(component, 'release') else component.change
|
||||
change_handler(
|
||||
fn=lambda value, k=k: run_settings_single(value, key=k),
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class UiLoadsave:
|
|||
def add_component(self, path, x):
|
||||
"""adds component to the registry of tracked components"""
|
||||
assert not self.finalized_ui
|
||||
|
||||
def apply_field(obj, field, condition=None, init_field=None):
|
||||
key = f"{path}/{field}"
|
||||
if getattr(obj, 'custom_script_source', None) is not None:
|
||||
|
|
@ -40,6 +41,7 @@ class UiLoadsave:
|
|||
init_field(saved_value)
|
||||
if field == 'value' and key not in self.component_mapping:
|
||||
self.component_mapping[key] = x
|
||||
|
||||
if type(x) in [gr.Slider, gr.Radio, gr.Checkbox, gr.Textbox, gr.Number, gr.Dropdown, ToolButton, gr.Button] and x.visible:
|
||||
apply_field(x, 'visible')
|
||||
if type(x) == gr.Slider:
|
||||
|
|
@ -48,7 +50,14 @@ class UiLoadsave:
|
|||
apply_field(x, 'maximum')
|
||||
apply_field(x, 'step')
|
||||
if type(x) == gr.Radio:
|
||||
apply_field(x, 'value', lambda val: val in x.choices)
|
||||
def check_choices(val):
|
||||
for choice in x.choices:
|
||||
if type(choice) == tuple:
|
||||
choice = choice[0]
|
||||
if choice == val:
|
||||
return True
|
||||
return False
|
||||
apply_field(x, 'value', check_choices)
|
||||
if type(x) == gr.Checkbox:
|
||||
apply_field(x, 'value')
|
||||
if type(x) == gr.Textbox:
|
||||
|
|
@ -80,8 +89,7 @@ class UiLoadsave:
|
|||
"""adds all components inside a gradio block x to the registry of tracked components"""
|
||||
if hasattr(x, 'children'):
|
||||
if isinstance(x, gr.Tabs) and x.elem_id is not None:
|
||||
# Tabs element can't have a label, have to use elem_id instead
|
||||
self.add_component(f"{path}/Tabs@{x.elem_id}", x)
|
||||
self.add_component(f"{path}/Tabs@{x.elem_id}", x) # Tabs element dont have a label, have to use elem_id instead
|
||||
for c in x.children:
|
||||
self.add_block(c, path)
|
||||
elif x.label is not None:
|
||||
|
|
@ -114,6 +122,9 @@ class UiLoadsave:
|
|||
for i, name in enumerate(self.component_mapping):
|
||||
component = self.component_mapping[name]
|
||||
choices = getattr(component, 'choices', None)
|
||||
if type(choices) is list and len(choices) > 0: # fix gradio radio button choices being tuples
|
||||
if type(choices[0]) is tuple:
|
||||
choices = [c[0] for c in choices]
|
||||
new_value = values[i]
|
||||
if isinstance(new_value, int) and choices:
|
||||
if new_value >= len(choices):
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ accelerate==0.20.3
|
|||
opencv-python-headless==4.7.0.72
|
||||
diffusers==0.20.0
|
||||
einops==0.4.1
|
||||
gradio==3.41.1
|
||||
gradio==3.41.2
|
||||
huggingface_hub==0.16.4
|
||||
numexpr==2.8.4
|
||||
numpy==1.24.4
|
||||
|
|
|
|||
Loading…
Reference in New Issue