Skip to content

Commit 4e5d252

Browse files
Merge pull request AUTOMATIC1111#13189 from AUTOMATIC1111/make-InputAccordion-work-with-ui-config
make InputAccordion work with ui-config
2 parents ab63054 + c485a7d commit 4e5d252

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

modules/ui_loadsave.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import gradio as gr
55

66
from modules import errors
7-
from modules.ui_components import ToolButton
7+
from modules.ui_components import ToolButton, InputAccordion
88

99

1010
def radio_choices(comp): # gradio 3.41 changes choices from list of values to list of pairs
@@ -32,8 +32,6 @@ def __init__(self, filename):
3232
self.error_loading = True
3333
errors.display(e, "loading settings")
3434

35-
36-
3735
def add_component(self, path, x):
3836
"""adds component to the registry of tracked components"""
3937

@@ -43,20 +41,24 @@ def apply_field(obj, field, condition=None, init_field=None):
4341
key = f"{path}/{field}"
4442

4543
if getattr(obj, 'custom_script_source', None) is not None:
46-
key = f"customscript/{obj.custom_script_source}/{key}"
44+
key = f"customscript/{obj.custom_script_source}/{key}"
4745

4846
if getattr(obj, 'do_not_save_to_config', False):
4947
return
5048

5149
saved_value = self.ui_settings.get(key, None)
50+
51+
if isinstance(obj, gr.Accordion) and isinstance(x, InputAccordion) and field == 'value':
52+
field = 'open'
53+
5254
if saved_value is None:
5355
self.ui_settings[key] = getattr(obj, field)
5456
elif condition and not condition(saved_value):
5557
pass
5658
else:
57-
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
59+
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
5860
saved_value = str(saved_value)
59-
elif isinstance(x, gr.Number) and field == 'value':
61+
elif isinstance(obj, gr.Number) and field == 'value':
6062
try:
6163
saved_value = float(saved_value)
6264
except ValueError:
@@ -67,7 +69,7 @@ def apply_field(obj, field, condition=None, init_field=None):
6769
init_field(saved_value)
6870

6971
if field == 'value' and key not in self.component_mapping:
70-
self.component_mapping[key] = x
72+
self.component_mapping[key] = obj
7173

7274
if type(x) in [gr.Slider, gr.Radio, gr.Checkbox, gr.Textbox, gr.Number, gr.Dropdown, ToolButton, gr.Button] and x.visible:
7375
apply_field(x, 'visible')
@@ -100,6 +102,12 @@ def check_dropdown(val):
100102

101103
apply_field(x, 'value', check_dropdown, getattr(x, 'init_field', None))
102104

105+
if type(x) == InputAccordion:
106+
if x.accordion.visible:
107+
apply_field(x.accordion, 'visible')
108+
apply_field(x, 'value')
109+
apply_field(x.accordion, 'value')
110+
103111
def check_tab_id(tab_id):
104112
tab_items = list(filter(lambda e: isinstance(e, gr.TabItem), x.children))
105113
if type(tab_id) == str:

0 commit comments

Comments
 (0)