Merge pull request #13189 from AUTOMATIC1111/make-InputAccordion-work-with-ui-config

make InputAccordion work with ui-config
This commit is contained in:
AUTOMATIC1111 2023-09-30 09:46:55 +03:00 committed by GitHub
commit 4e5d2526cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,7 @@ import os
import gradio as gr import gradio as gr
from modules import errors from modules import errors
from modules.ui_components import ToolButton from modules.ui_components import ToolButton, InputAccordion
def radio_choices(comp): # gradio 3.41 changes choices from list of values to list of pairs def radio_choices(comp): # gradio 3.41 changes choices from list of values to list of pairs
@ -32,8 +32,6 @@ class UiLoadsave:
self.error_loading = True self.error_loading = True
errors.display(e, "loading settings") errors.display(e, "loading settings")
def add_component(self, path, x): def add_component(self, path, x):
"""adds component to the registry of tracked components""" """adds component to the registry of tracked components"""
@ -49,14 +47,18 @@ class UiLoadsave:
return return
saved_value = self.ui_settings.get(key, None) saved_value = self.ui_settings.get(key, None)
if isinstance(obj, gr.Accordion) and isinstance(x, InputAccordion) and field == 'value':
field = 'open'
if saved_value is None: if saved_value is None:
self.ui_settings[key] = getattr(obj, field) self.ui_settings[key] = getattr(obj, field)
elif condition and not condition(saved_value): elif condition and not condition(saved_value):
pass pass
else: else:
if isinstance(x, gr.Textbox) and field == 'value': # due to an undesirable behavior of gr.Textbox, if you give it an int value instead of str, everything dies if isinstance(obj, gr.Textbox) and field == 'value': # due to an undesirable behavior of gr.Textbox, if you give it an int value instead of str, everything dies
saved_value = str(saved_value) saved_value = str(saved_value)
elif isinstance(x, gr.Number) and field == 'value': elif isinstance(obj, gr.Number) and field == 'value':
try: try:
saved_value = float(saved_value) saved_value = float(saved_value)
except ValueError: except ValueError:
@ -67,7 +69,7 @@ class UiLoadsave:
init_field(saved_value) init_field(saved_value)
if field == 'value' and key not in self.component_mapping: if field == 'value' and key not in self.component_mapping:
self.component_mapping[key] = x self.component_mapping[key] = obj
if type(x) in [gr.Slider, gr.Radio, gr.Checkbox, gr.Textbox, gr.Number, gr.Dropdown, ToolButton, gr.Button] and x.visible: 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') apply_field(x, 'visible')
@ -100,6 +102,12 @@ class UiLoadsave:
apply_field(x, 'value', check_dropdown, getattr(x, 'init_field', None)) apply_field(x, 'value', check_dropdown, getattr(x, 'init_field', None))
if type(x) == InputAccordion:
if x.accordion.visible:
apply_field(x.accordion, 'visible')
apply_field(x, 'value')
apply_field(x.accordion, 'value')
def check_tab_id(tab_id): def check_tab_id(tab_id):
tab_items = list(filter(lambda e: isinstance(e, gr.TabItem), x.children)) tab_items = list(filter(lambda e: isinstance(e, gr.TabItem), x.children))
if type(tab_id) == str: if type(tab_id) == str: