4
4
import gradio as gr
5
5
6
6
from modules import errors
7
- from modules .ui_components import ToolButton
7
+ from modules .ui_components import ToolButton , InputAccordion
8
8
9
9
10
10
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):
32
32
self .error_loading = True
33
33
errors .display (e , "loading settings" )
34
34
35
-
36
-
37
35
def add_component (self , path , x ):
38
36
"""adds component to the registry of tracked components"""
39
37
@@ -43,20 +41,24 @@ def apply_field(obj, field, condition=None, init_field=None):
43
41
key = f"{ path } /{ field } "
44
42
45
43
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 } "
47
45
48
46
if getattr (obj , 'do_not_save_to_config' , False ):
49
47
return
50
48
51
49
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
+
52
54
if saved_value is None :
53
55
self .ui_settings [key ] = getattr (obj , field )
54
56
elif condition and not condition (saved_value ):
55
57
pass
56
58
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
58
60
saved_value = str (saved_value )
59
- elif isinstance (x , gr .Number ) and field == 'value' :
61
+ elif isinstance (obj , gr .Number ) and field == 'value' :
60
62
try :
61
63
saved_value = float (saved_value )
62
64
except ValueError :
@@ -67,7 +69,7 @@ def apply_field(obj, field, condition=None, init_field=None):
67
69
init_field (saved_value )
68
70
69
71
if field == 'value' and key not in self .component_mapping :
70
- self .component_mapping [key ] = x
72
+ self .component_mapping [key ] = obj
71
73
72
74
if type (x ) in [gr .Slider , gr .Radio , gr .Checkbox , gr .Textbox , gr .Number , gr .Dropdown , ToolButton , gr .Button ] and x .visible :
73
75
apply_field (x , 'visible' )
@@ -100,6 +102,12 @@ def check_dropdown(val):
100
102
101
103
apply_field (x , 'value' , check_dropdown , getattr (x , 'init_field' , None ))
102
104
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
+
103
111
def check_tab_id (tab_id ):
104
112
tab_items = list (filter (lambda e : isinstance (e , gr .TabItem ), x .children ))
105
113
if type (tab_id ) == str :
0 commit comments