@@ -188,6 +188,11 @@ def set_dropdowns():
188188 if (option == new_value ):
189189 matching_successed = True
190190 break
191+
192+ # 去掉模型的多余路径?
193+ # if(os.path.split(option)[-1] == os.path.split(new_value)[-1]):
194+ # matching_successed = True
195+ # break
191196
192197 # 没有完全匹配
193198 if (not matching_successed ):
@@ -358,7 +363,7 @@ def get_lora_from_prompt(prompt):
358363 #print(available_loras)
359364
360365 missing_loras = []
361- re_lora_prompt = re .compile ("<lora:([\w_\s.]+):([\d.]+)>" , re .IGNORECASE )
366+ re_lora_prompt = re .compile ("<lora:([\w_\s.]+):([ \d.]+)>" , re .IGNORECASE )
362367 results = re .findall (re_lora_prompt , prompt )
363368 # print("使用到的lora:")
364369 # print(results)
@@ -494,6 +499,72 @@ def func_for_invisiblebutton():
494499 return Webui_Comps_Cur_Val [temp_index ], next_index , Output_Log , Output_Log
495500
496501
502+ def config_filter (config ):
503+ global extensions_id_conponents
504+ new_config = config
505+ for comp_type in extensions_id_conponents .keys ():
506+ for comp_id in extensions_id_conponents [comp_type ].keys ():
507+ try :
508+ # 筛掉python相关组件的默认值选项
509+ default_val = extensions_id_conponents [comp_type ][comp_id ].get_config ()["value" ]
510+ if (default_val == new_config [comp_id ]):
511+ del new_config [comp_id ]
512+ except KeyError as e :
513+ pass
514+
515+ # 处理旧版插件保存的错误参数问题
516+ #print("-------处理错误-------")
517+ #print(new_config)
518+ print ("-------处理错误-------" )
519+ found_tabs = []
520+ fixed_config = {}
521+ for param in new_config .keys ():
522+ res = re .match ("state-ext-control-net-txt2img_([0-9]+)-(.+)" ,param )
523+ if (res != None ):
524+ if (res .group (2 ) not in ["presets" ,"preprocessor" ,"model" ]):
525+ try :
526+ found_tabs .index (res .group (1 ))
527+ except ValueError :
528+ found_tabs .append (res .group (1 ))
529+
530+ for param in new_config .keys ():
531+
532+ # 缝缝补补。。。 js保存的参数因为是汉语反推回英文,所以就会有 model->模型->models 的情况。
533+ res = re .search ("[-_](model|models|checkpoint|checkpoints)$" ,param )
534+ if (res != None ):
535+ for key in ["model" ,"models" ,"checkpoint" ,"checkpoints" ]:
536+ target_word = str (res .group ()).replace (res .group (1 ),key )
537+ new_param = re .sub ("[-_](model|models|checkpoint|checkpoints)($|[_-])" , target_word , param )
538+ fixed_config [new_param ] = new_config [param ]
539+
540+ # 纠正编号
541+ res = re .match ("state-ext-control-net-txt2img_([0-9]+)-(.+)" ,param )
542+ if (res != None ):
543+ if (res .group (1 ) != "0" and res .group (2 ) not in ["presets" ,"preprocessor" ,"model" ]):
544+ tab_num = int (res .group (1 ))
545+ if (tab_num % 3 == 0 ):
546+ try :
547+ found_tabs .index (str (tab_num / 3 ))
548+ # 如果是9 如果发现3的位置有参数,就还需要检查一下1
549+ if (tab_num == 9 ):
550+ found_tabs .index ("1" )
551+ except ValueError :
552+ new_key = f"state-ext-control-net-txt2img_{ int (tab_num / 3 )} -{ res .group (2 )} "
553+ fixed_config [new_key ] = new_config [param ]
554+ print (f" { param } 改为 { new_key } " )
555+ continue
556+
557+ # 其余参数照搬
558+ fixed_config [param ] = new_config [param ]
559+
560+ #print("-------处理错误-------")
561+ #print(fixed_config)
562+ print ("-------处理错误-------" )
563+
564+ new_config = fixed_config
565+ return new_config
566+
567+
497568def fn_import_workflow (workflow_file ):
498569 global workflow_json , Output_Log
499570 global extensions_id_conponents , Webui_Comps_Cur_Val , temp_index , next_index
@@ -516,6 +587,8 @@ def fn_import_workflow(workflow_file):
516587 else :
517588 print ("invalid file!" )
518589
590+ workflow_json = config_filter (workflow_json )
591+
519592 Webui_Comps_Cur_Val = []
520593 for key in extensions_id_conponents ["image" ].keys ():
521594 #for key in lf_config.Image_Components_Key:
@@ -561,8 +634,9 @@ def fn_import_workflow(workflow_file):
561634 # for short_hash in loras_info.keys():
562635 # if(loras_info[short_hash].name == lora_name or loras_info[short_hash].alias == lora_name):
563636 # pass
564- except KeyError :
637+ except KeyError as e :
565638 pass
639+ #print(f"except missing loras error: {e}")
566640
567641 #print(Webui_Comps_Cur_Val)
568642 #set_elements()
@@ -632,18 +706,7 @@ def get_ext_list(self):
632706 return ext_str
633707
634708 def useless_config_filter (self , config :config_params ):
635- global extensions_id_conponents
636- new_config = config .config_data
637- for comp_type in extensions_id_conponents .keys ():
638- for comp_id in extensions_id_conponents [comp_type ].keys ():
639- try :
640- # 筛掉python相关组件的默认值选项
641- default_val = extensions_id_conponents [comp_type ][comp_id ].get_config ()["value" ]
642- if (default_val == new_config [comp_id ]):
643- del new_config [comp_id ]
644- except KeyError as e :
645- pass
646- return new_config
709+ return config_filter (config .config_data )
647710
648711 def get_lightdiffusionflow_config (self , onlyimg :bool = False ):
649712 global workflow_json , extensions_id_conponents , extensions_id_conponents_value
@@ -884,7 +947,7 @@ def after_component(self, component, **kwargs):
884947 get_script_container (component )
885948
886949 if (isinstance (component , gr .Button ) and kwargs ["elem_id" ] == "img2img_generation_info_button" ): # 加载到最后一个组件了。 兼容旧版,暂时不使用“img2img_preview_filename”
887-
950+
888951 searching_extensions_title ()
889952 #print(extensions_conponents)
890953
@@ -929,7 +992,7 @@ def after_component(self, component, **kwargs):
929992 except KeyError as e :
930993 pass
931994
932- #print(extensions_conponents) # 整理好的第三方插件用到的组件
995+ # print(extensions_conponents) # 整理好的第三方插件用到的组件
933996 # --------------------------------------组件分类--------------------------------------------------
934997
935998 if (self .is_img2img ):
@@ -1065,11 +1128,26 @@ def custom_ui(self):
10651128 invisible_buttons [elem_id ] = gr .Button (value = elem_id , elem_id = elem_id , visible = False )
10661129
10671130
1131+
1132+ def on_after_component (component , ** kwargs ):
1133+ global Webui_Comps
1134+
1135+ # img2img和txt2img面板以外的组件信息只能在这里获取
1136+ # 如果希望python里控制这些组件,还需要把部分代码移到这里实现
1137+ try :
1138+ if (Webui_Comps .get (kwargs ["elem_id" ], None ) == None ):
1139+ Webui_Comps [kwargs ["elem_id" ]] = component
1140+ #if( kwargs["elem_id"] == "setting_sd_model_checkpoint"):
1141+ # print("--------------setting_sd_model_checkpoint---------------")
1142+ except KeyError :
1143+ pass
1144+
1145+
10681146def on_before_reload ():
10691147 lightdiffusionflow_config .init ()
10701148
10711149# add callbacks
10721150api = StateApi ()
10731151script_callbacks .on_app_started (api .start )
1074- # script_callbacks.on_after_component(on_after_component)
1152+ script_callbacks .on_after_component (on_after_component )
10751153script_callbacks .on_before_reload (on_before_reload )
0 commit comments