Skip to content

Commit 0444531

Browse files
authored
Merge pull request #5 from Tencent/Branch_dev
Branch dev
2 parents e16cab6 + 89d1403 commit 0444531

File tree

3 files changed

+94
-17
lines changed

3 files changed

+94
-17
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* py实现与js一样的创建组件编号,优化导入逻辑,部分dropdown组件改由py处理,降低UI面板无限转圈概率。
55
* 修复了一些已知的问题。
66

7+
### Features:
8+
* UI面板挪到右侧,图片信息栏下方。
9+
710
## 2.0.4
811

912
### Bug Fixes:

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ Use **Install from URL** option with this repo url.
2828
*None at all.*
2929

3030
### Usage
31-
* I don't think I need to explain it in detail, right? :)
31+
* Export Parameters:
32+
In the SD Web UI, configure the desired options, and click the "Export" button to export a flow file that records the current parameters.
33+
34+
* Import Parameters:
35+
In the SD Web UI, click the "FileBox", select the corresponding flow file, and import the parameters from the file.
36+
You can also directly drag and drop the flow file into the "FileBox" for importing.
3237

3338
### Contributing
3439

scripts/state_api.py

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@
4646
File_extension = ".flow"
4747

4848
def test_func():
49-
global extensions_conponents
49+
global extensions_conponents, extensions_id_conponents
5050
print("test_func")
51+
res = re.search(r"(\[[0-9A-Fa-f]{8,10}\])", "control_v11p_sd15_scribble [d4ba51aafd]")
52+
print(res)
53+
#print(extensions_id_conponents["dropdown"]["state-ext-control-net-txt2img_0-model"].get_config())
5154

5255
# print(parameters_copypaste.paste_fields)
5356

@@ -56,9 +59,15 @@ def add_output_log(msg:str="", style:str=""):
5659
if(msg != ""):
5760
#print(f"Output_Log: {msg}")
5861
Output_Log += f'<p style="{style}">{msg}</p>'
59-
6062
return Output_Log, Output_Log
6163

64+
def add_output_warning(msg:str=""):
65+
add_output_log(msg, style="color:Orange;")
66+
67+
def add_output_error(msg:str=""):
68+
add_output_log(msg, style="color:Tomato;")
69+
70+
6271
def find_checkpoint_from_name(name:str):
6372

6473
for checkpoint in checkpoints_list.keys():
@@ -73,7 +82,7 @@ def find_checkpoint_from_name(name:str):
7382
def find_checkpoint_from_hash(hash:str):
7483

7584
for checkpoint in checkpoints_list.keys():
76-
res = re.search(r"\[([0-9a-fA-F]{10})\]", checkpoint)
85+
res = re.search(r"\[([0-9a-fA-F]{8,10})\]", checkpoint)
7786
try:
7887
if(res.group(1) == hash):
7988
return checkpoint
@@ -106,16 +115,73 @@ def set_dropdowns():
106115
return_vals = []
107116
for comp_id in extensions_id_conponents["dropdown"].keys():
108117
value = None
118+
new_value = None
109119
try:
110120
value = workflow_json.get(comp_id, None)
111-
# 判断hash
112121
if(value == None):
113-
value = extensions_id_conponents["dropdown"][comp_id].get_config()["value"]
122+
new_value = extensions_id_conponents["dropdown"][comp_id].get_config()["value"]
123+
else:
124+
new_value = value
125+
matching_successed = False
126+
options = extensions_id_conponents["dropdown"][comp_id].get_config()["choices"]
127+
for option in options:
128+
if(option == new_value):
129+
matching_successed = True
130+
break
131+
132+
# 没有完全匹配
133+
if(not matching_successed):
134+
# 寻找哈希值
135+
value_hash_val = None
136+
value_no_hash = None
137+
res = re.search(r"(\[[0-9A-Fa-f]{8,10}\])", new_value)
138+
if(res != None):
139+
value_hash_val = res.group(1)
140+
value_no_hash = new_value.replace(value_hash_val,"").rstrip()
141+
142+
for option in options:
143+
option_hash_val = None
144+
option_no_hash = None
145+
res = re.search(r"(\[[0-9A-Fa-f]{8,10}\])", option)
146+
if(res != None): # 选项有哈希
147+
option_hash_val = res.group(1)
148+
option_no_hash = option.replace(option_hash_val,"").rstrip()
149+
if(value_hash_val == None): # 值没有哈希
150+
if(new_value.rstrip() == option_no_hash):
151+
new_value = option
152+
matching_successed = True
153+
break
154+
else: # 值有哈希
155+
if(value_hash_val == option_hash_val or option_no_hash == value_no_hash):
156+
new_value = option
157+
matching_successed = True
158+
break
159+
else: # 选项没有哈希
160+
if(value_hash_val == None): # 值没有哈希
161+
if(new_value.rstrip() == option.rstrip()):
162+
new_value = option
163+
matching_successed = True
164+
break
165+
else: # 值有哈希
166+
if(value_no_hash == option.rstrip()):
167+
new_value = option
168+
matching_successed = True
169+
break
170+
171+
if(matching_successed):
172+
add_output_warning(f"The option '{value}' was not found, and has been replaced with '{new_value}'!")
173+
else:
174+
add_output_error(f"'{comp_id}' import failed! The option '{value}' was not found!")
175+
new_value = extensions_id_conponents["dropdown"][comp_id].get_config()["value"]
176+
177+
114178
except KeyError as e:
115179
pass
116-
return_vals.append(value)
180+
return_vals.append(new_value)
117181

118182
return_vals.append(temp_index) # 给json2js
183+
return_vals.append(Output_Log)
184+
return_vals.append(Output_Log)
119185
return tuple(return_vals)
120186

121187
def set_js_params():
@@ -715,8 +781,13 @@ def after_component(self, component, **kwargs):
715781
conponents_originlist.append((component, 'img2img' if self.is_img2img else 'txt2img'))
716782
#print(f"after_component {component} {kwargs.get('elem_id', None)} {'img2img' if self.is_img2img else 'txt2img'} ")
717783
try:
784+
785+
if kwargs["elem_id"] == "txt2img_generation_info_button" or kwargs["elem_id"] == "img2img_generation_info_button":
786+
self.custom_ui()
787+
718788
if(Webui_Comps.get(kwargs["elem_id"], None) == None):
719789
Webui_Comps[kwargs["elem_id"]] = component
790+
720791
except BaseException as e:
721792
pass
722793

@@ -801,6 +872,8 @@ def after_component(self, component, **kwargs):
801872

802873
temp_dropdown_outputs = list(extensions_id_conponents["dropdown"].values())
803874
temp_dropdown_outputs.append(State_Comps["json2js"]) # json2js触发完成事件
875+
temp_dropdown_outputs.append(State_Comps["outlog"][0]) # 输出日志
876+
temp_dropdown_outputs.append(State_Comps["outlog"][1]) # 输出日志
804877
State_Comps["set_dropdowns"].click(set_dropdowns,inputs=[],outputs=temp_dropdown_outputs)
805878

806879
State_Comps["set_js_params"].click(set_js_params,inputs=[],outputs=State_Comps["json2js"])
@@ -826,8 +899,10 @@ def after_component(self, component, **kwargs):
826899
except KeyError:
827900
print(f"No such component: {comp_name}")
828901

829-
830902
def ui(self, is_img2img):
903+
pass
904+
905+
def custom_ui(self):
831906
global File_extension
832907
try:
833908
State_Comps["import"]
@@ -838,7 +913,7 @@ def ui(self, is_img2img):
838913
State_Comps["export"] = []
839914
State_Comps["outlog"] = []
840915

841-
with gr.Accordion('LightDiffusionFlow '+lightdiffusionflow_version.lightdiffusionflow_version, open=False, visible=True):
916+
with gr.Accordion('LightDiffusionFlow '+lightdiffusionflow_version.lightdiffusionflow_version, open=True, visible=True):
842917
with gr.Row():
843918
lightdiffusionflow_file = gr.File(label="LightDiffusionFlow File",file_count="single", file_types=[File_extension])
844919
State_Comps["import"].append(lightdiffusionflow_file)
@@ -856,21 +931,15 @@ def ui(self, is_img2img):
856931
export_config = gr.Button(value='Export')
857932
State_Comps["export"].append(export_config)
858933

859-
if(not is_img2img):
934+
if(not self.is_img2img):
860935

861936
State_Comps["background_import"] = gr.File(label="LightDiffusionFlow File",file_count="single",
862937
file_types=[File_extension],visible=False)
863-
864938
State_Comps["json2js"] = gr.Textbox(label="json2js",visible=False)
865-
866939
State_Comps["test_button"] = gr.Button(value='测试',elem_id='test_button',visible=False)
867-
868940
State_Comps["refresh_log"] = gr.Button(value='刷新日志',elem_id='txt2img_invisible_refresh_log',visible=False)
869-
870941
State_Comps["set_dropdowns"] = gr.Button(value='设置部分参数',elem_id='lightdiffusionflow_set_dropdowns',visible=False)
871-
872942
State_Comps["set_js_params"] = gr.Button(value='设置剩下的js参数',elem_id='lightdiffusionflow_set_js_params',visible=False)
873-
874943
State_Comps["set_file_button"] = gr.Button(value='设置文件',elem_id='set_lightdiffusionflow_file',visible=False)
875944
State_Comps["preload_button"] = gr.Button(value='预加载',elem_id='preload_button',visible=False)
876945

@@ -879,7 +948,7 @@ def ui(self, is_img2img):
879948
gr.Textbox(value='useless_Textbox', elem_id='useless_Textbox', visible=False)
880949

881950
for key in lf_config.Image_Components_Key:
882-
elem_id = ("img2img_" if is_img2img else "txt2img_") + "invisible_" + key
951+
elem_id = ("img2img_" if self.is_img2img else "txt2img_") + "invisible_" + key
883952
invisible_buttons[elem_id] = gr.Button(value=elem_id, elem_id=elem_id, visible=False)
884953

885954

0 commit comments

Comments
 (0)