Skip to content

Commit 9a4eda5

Browse files
author
legionfu
committed
Merge remote-tracking branch 'remotes/tencent/dev_fix_cpn_id' into Branch_dev
2 parents 8bee6c4 + 37e8113 commit 9a4eda5

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

scripts/state_api.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,13 +651,49 @@ class Script(scripts.Script):
651651

652652
def __init__(self) -> None:
653653
super().__init__()
654+
#记录无id元素的id
655+
self.new_ids={}
654656

655657
def title(self):
656658
return "lightdiffusionflow plugin"
657659

658660
def show(self, is_img2img):
659661
return scripts.AlwaysVisible
660662

663+
def after_component(self, component, **kwargs):
664+
#当前模式
665+
teb_mode="img2img" if self.is_img2img else "txt2img"
666+
#空id补全方法
667+
def in_zone(dom,id=""):
668+
if dom:
669+
if dom.elem_id:
670+
id+="-"+dom.elem_id
671+
return in_zone(dom.parent,id)
672+
elif dom.elem_classes and dom.elem_classes[0]!='gradio-blocks':
673+
if dom.elem_classes[0]=='gradio-accordion':
674+
id+='-'+dom.label+"?"
675+
return in_zone(dom.parent,id)
676+
if re.search('2img_(textual|hypernetworks|checkpoints|lora)_',id):
677+
return False
678+
else:
679+
id=re.sub(r'\?[^\?]+$|[ \?]','',id)
680+
if id in self.new_ids:
681+
self.new_ids[id]+=1
682+
else:
683+
self.new_ids[id]=1
684+
return id+'-'+str(self.new_ids[id])
685+
686+
#记录组件
687+
try:
688+
#拉取id
689+
id=component.elem_id
690+
#若没有就重构
691+
if id==None:
692+
id=component.elem_id==in_zone(component.parent,teb_mode)
693+
Webui_Comps[id] = component
694+
except BaseException as e:
695+
pass
696+
661697
def ui(self, is_img2img):
662698
global File_extension
663699
print("----------------------ui---------------------------")
@@ -720,4 +756,4 @@ def on_before_reload():
720756
api = StateApi()
721757
script_callbacks.on_app_started(api.start)
722758
script_callbacks.on_after_component(on_after_component)
723-
script_callbacks.on_before_reload(on_before_reload)
759+
script_callbacks.on_before_reload(on_before_reload)

0 commit comments

Comments
 (0)