Skip to content

Commit fdb0442

Browse files
authored
Update state_api.py
1 parent e9b61fd commit fdb0442

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

scripts/state_api.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,44 @@ def set_lightdiffusionflow_file():
8686
'''
8787
def on_after_component(component, **kwargs):
8888

89+
#当前模式
90+
teb_mode="img2img" if self.is_img2img else "txt2img"
91+
#空id补全方法
92+
def in_zone(dom,id=""):
93+
if dom:
94+
if dom.elem_id:
95+
id+="-"+dom.elem_id
96+
return in_zone(dom.parent,id)
97+
elif dom.elem_classes and dom.elem_classes[0]!='gradio-blocks':
98+
if dom.elem_classes[0]=='gradio-accordion':
99+
id+='-'+dom.label+"?"
100+
return in_zone(dom.parent,id)
101+
if re.search('2img_(textual|hypernetworks|checkpoints|lora)_',id):
102+
return False
103+
else:
104+
id=re.sub(r'\?[^\?]+$|[ \?]','',id)
105+
if id in self.new_ids:
106+
self.new_ids[id]+=1
107+
else:
108+
self.new_ids[id]=1
109+
return id+'-'+str(self.new_ids[id])
110+
111+
#记录组件
89112
try:
90-
if(Webui_Comps.get(kwargs["elem_id"], None) == None):
91-
Webui_Comps[kwargs["elem_id"]] = component
113+
#拉取id
114+
id=component.elem_id
115+
#若没有就重构
116+
if id==None:
117+
component.elem_id=kwargs["elem_id"]=in_zone(component.parent,teb_mode)
118+
Webui_Comps[kwargs["elem_id"]] = component
92119
except BaseException as e:
93120
pass
121+
122+
#try:
123+
#if(Webui_Comps.get(kwargs["elem_id"], None) == None):
124+
#Webui_Comps[kwargs["elem_id"]] = component
125+
#except BaseException as e:
126+
#pass
94127

95128
if (isinstance(component, gr.Button) and kwargs["elem_id"] == "change_checkpoint"): # 加载到最后一个组件了
96129
#print("LightDiffusionFlow绑定按钮")
@@ -486,4 +519,4 @@ def on_before_reload():
486519
api = StateApi()
487520
script_callbacks.on_app_started(api.start)
488521
script_callbacks.on_after_component(on_after_component)
489-
script_callbacks.on_before_reload(on_before_reload)
522+
script_callbacks.on_before_reload(on_before_reload)

0 commit comments

Comments
 (0)