Skip to content

Commit 3d181a1

Browse files
author
legionfu
committed
导入导出筛去默认值的参数
1 parent afabf28 commit 3d181a1

File tree

4 files changed

+66
-64
lines changed

4 files changed

+66
-64
lines changed

javascript/state.core.js

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,6 @@ state.core = (function () {
714714
},
715715
importLightDiffusionFlow: function (inputData){
716716

717-
718717
forEachElement_WithoutTabs(IMAGES_WITHOUT_PREFIX, (image_id) => {
719718
state.utils.clearImage(getElement(image_id));
720719
});
@@ -726,39 +725,47 @@ state.core = (function () {
726725
return;
727726
}
728727

729-
// 缺少的插件
730-
console.log(ext_list)
731-
missing_ext_list = []
732-
for (let key in json_obj){
733-
ext_name = key.match(/ext-(\S+)-(txt2img|img2img)/)
734-
console.log(key)
735-
if(ext_name != null){
736-
ext_name = ext_name[1]
737-
console.log(ext_name)
738-
if(ext_list.indexOf(ext_name) === -1){
739-
if(missing_ext_list.indexOf(ext_name) === -1){
740-
missing_ext_list.push(ext_name)
728+
// 筛选掉默认值参数
729+
let data = {
730+
method: 'POST',
731+
headers: { 'Content-Type': 'application/json' },
732+
body: JSON.stringify({
733+
"config_data":json_obj
734+
})
735+
}
736+
fetch(`/lightdiffusionflow/local/useless_config_filter`, data)
737+
.then(response => response.json())
738+
.then(data => {
739+
json_obj = data
740+
console.log(ext_list)
741+
// 缺少的插件
742+
missing_ext_list = []
743+
for (let key in json_obj){
744+
ext_name = key.match(/ext-(\S+)-(txt2img|img2img)/)
745+
console.log(key)
746+
if(ext_name != null){
747+
ext_name = ext_name[1]
748+
console.log(ext_name)
749+
if(ext_list.indexOf(ext_name) === -1){
750+
if(missing_ext_list.indexOf(ext_name) === -1){
751+
missing_ext_list.push(ext_name)
752+
}
741753
}
742754
}
743755
}
744-
}
745756

746-
if(missing_ext_list.length > 0){
747-
// error_str = "Error: <b style='color:Red;'>Found missing extensions.</b></p>"
748-
// for (ext of missing_ext_list){
749-
// error_str+="<p>- <b style='color:Red;'>"+ext+"</b></p>"
750-
// }
751-
// actions.output_log(error_str)
752-
actions.preset_output_log("missing_exts","",missing_ext_list.join(';'))
753-
}
757+
if(missing_ext_list.length > 0){
758+
actions.preset_output_log("missing_exts","",missing_ext_list.join(';'))
759+
}
754760

755-
forEachElement_WithoutTabs(IMAGES_WITHOUT_PREFIX, (image_id) => {
756-
json_obj[image_id] = ""
761+
forEachElement_WithoutTabs(IMAGES_WITHOUT_PREFIX, (image_id) => {
762+
json_obj[image_id] = ""
763+
});
764+
// webui主界面 没有localization相关的兼容问题 所以不用管
765+
store.clear();
766+
store.load(json_obj);
767+
actions.applyState();
757768
});
758-
// webui主界面 没有localization相关的兼容问题 所以不用管
759-
store.clear();
760-
store.load(json_obj);
761-
actions.applyState();
762769
return;
763770
},
764771
startImportImage: function (index){

javascript/state.utils.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ state.utils = {
88
//console.log(state.extensions)
99
// const button = gradioApp().getElementById("lightdiffusionflow_set_elements");
1010
// button.click();
11-
12-
ext_name = "state-ext-control-net-img2img_2-presets".match(/ext-([a-zA-z0-9\-]+)-txt2img/)
13-
console.log(ext_name)
1411
},
1512

1613
target_is_newer_version: function(cur_version, target_version){

scripts/lightdiffusionflow_config.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ def import_completed():
1919
return "<b style='color:LimeGreen;'>import completed!</b>"
2020

2121
def alternative_option(target_value, new_value):
22-
return f'''Note: '<b style='color:Orange;'>{target_value}</b>' not found.\
22+
return f'''Note: '<b style='color:Orange;'>{target_value}</b>' not found,<br>\
2323
An approximate match '<b style='color:Orange;'>{new_value}</b>' has been automatically selected as replacement.'''
2424

2525
def no_option(option_name, value):
26-
return f'''Error: '<b style='color:Red;'>{option_name}</b>' import failed!\
26+
return f'''Error: '<b style='color:Red;'>{option_name}</b>' import failed!<br>\
2727
The option '<b style='color:Red;'>{value}</b>' was not found!'''
2828

2929
def missing_extensions(ext_list:[]):
30-
error_str = "Error: <b style='color:Red;'>Found missing extensions.</b></p>"
30+
error_str = "Note: <b style='color:Orange;'>Found missing extensions.</b></p>"
3131
for ext in ext_list:
32-
error_str+="<p>- <b style='color:Red;'>"+ext+"</b></p> "
32+
error_str+="<p>- <b style='color:Orange;'>"+ext+"</b></p> "
3333
return error_str
3434

3535
def click_to_download(file_name, file_url):
@@ -52,19 +52,19 @@ def import_completed():
5252
return "<b style='color:LimeGreen;'>导入完成!</b>"
5353

5454
def alternative_option(target_value, new_value):
55-
return f'''注意: 未找到选项'<b style='color:Orange;'>{target_value}</b>'.\
55+
return f'''注意: 未找到选项'<b style='color:Orange;'>{target_value}</b>',<br>\
5656
已使用近似选项'<b style='color:Orange;'>{new_value}</b>'代替.'''
5757

5858
def no_option(option_name, value):
5959
if(option_name == "stable diffusion checkpoint"):
6060
return f'''未找到大模型'<b style='color:Orange;'>{value}</b>'!'''
61-
return f'''错误: '<b style='color:Red;'>{option_name}</b>'导入失败!\
61+
return f'''错误: '<b style='color:Red;'>{option_name}</b>'导入失败!<br>\
6262
未找到选项'<b style='color:Red;'>{value}</b>'!'''
6363

6464
def missing_extensions(ext_list:[]):
65-
error_str = "错误, <b style='color:Red;'>发现缺失的插件:</b></p>"
65+
error_str = "注意, <b style='color:Orange;'>发现缺失的插件:</b></p>"
6666
for ext in ext_list:
67-
error_str+="<p>- <b style='color:Red;'>"+ext+"</b></p> "
67+
error_str+="<p>- <b style='color:Orange;'>"+ext+"</b></p> "
6868
return error_str
6969

7070
def click_to_download(file_name, file_url):

scripts/state_api.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,13 @@
4848

4949
def test_func():
5050
global extensions_conponents, extensions_id_conponents
51+
global Output_Log
5152
print("test_func")
52-
# res = re.search(r"(\[[0-9A-Fa-f]{8,10}\])", "control_v11p_sd15_scribble [d4ba51aafd]")
53-
# print(res)
53+
print(Output_Log)
54+
5455
#from scripts.processor import preprocessor_filters
5556
#print(preprocessor_filters)
5657

57-
cn_model_name = "control_v1p_sd15_qrco1de_monster [5e5778cb]"
58-
59-
cn_type_list = ['canny','depth','normalmap','openpose','mlsd','lineart_anime','lineart','softedge','scribble',
60-
'seg','shuffle','tile','inpaint','ip2p','brightness','illumination','qrcode_monster','qrcode','normalbae']
61-
62-
type_pattern = "("+"|".join(cn_type_list)+")"
63-
print(type_pattern)
64-
res = re.search(type_pattern,cn_model_name)
65-
if(res != None):
66-
print(res.group())
67-
6858
#print(extensions_id_conponents["dropdown"]["state-ext-control-net-txt2img_0-model"].get_config())
6959

7060
# print(parameters_copypaste.paste_fields)
@@ -150,16 +140,6 @@ def cn_get_model_type(cn_model_name):
150140
if(res != None):
151141
return res.group()
152142

153-
# #cn_model_name = "control_v1p_sd15_qrcode_monster [5e5778cb]"
154-
# res = re.search(r"(\[[0-9A-Fa-f]{8,10}\])", cn_model_name)
155-
# if(res != None):
156-
# cn_model_hash_val = res.group(1)
157-
# cn_model_no_hash = cn_model_name.replace(cn_model_hash_val,"").rstrip().lower()
158-
# else:
159-
# cn_model_no_hash = cn_model_name.rstrip().lower()
160-
# model_type = cn_model_no_hash.split("_")[-1]
161-
# print(model_type)
162-
# return model_type
163143
return None
164144

165145
def set_dropdowns():
@@ -508,6 +488,9 @@ def fn_import_workflow(workflow_file):
508488
# return tuple(return_vals)
509489
return str(temp_index)#, Output_Log, Output_Log
510490

491+
class config_params(BaseModel):
492+
config_data:dict
493+
511494
class imgs_callback_params(BaseModel):
512495
id:str
513496
img:str
@@ -529,7 +512,7 @@ def add_api_route(self, path: str, endpoint, **kwargs):
529512
return self.app.add_api_route(self.get_path(path), endpoint, **kwargs)
530513

531514
def start(self, _: gr.Blocks, app: FastAPI):
532-
print("-----------------state_api start------------------")
515+
print("----------------- light_diffusion_flow api start------------------")
533516

534517
self.app = app
535518
# 读取本地的config.json
@@ -542,6 +525,7 @@ def start(self, _: gr.Blocks, app: FastAPI):
542525
self.add_api_route('/local/get_ext_list', self.get_ext_list, methods=['GET'])
543526
# 用户设置了新图片 触发回调保存到 workflow_json
544527
self.add_api_route('/local/imgs_callback', self.imgs_callback, methods=['POST'])
528+
self.add_api_route('/local/useless_config_filter', self.useless_config_filter, methods=['POST'])
545529
# 刷新页面之后触发
546530
self.add_api_route('/local/refresh_ui', self.refresh_ui, methods=['GET'])
547531
self.add_api_route('/local/output_log', add_output_log, methods=['GET'])
@@ -565,6 +549,20 @@ def get_ext_list(self):
565549
pass
566550
return ext_str
567551

552+
def useless_config_filter(self, config:config_params):
553+
global extensions_id_conponents
554+
new_config = config.config_data
555+
for comp_type in extensions_id_conponents.keys():
556+
for comp_id in extensions_id_conponents[comp_type].keys():
557+
try:
558+
# 筛掉python相关组件的默认值选项
559+
default_val = extensions_id_conponents[comp_type][comp_id].get_config()["value"]
560+
if(default_val == new_config[comp_id]):
561+
del new_config[comp_id]
562+
except KeyError as e:
563+
pass
564+
return new_config
565+
568566
def get_lightdiffusionflow_config(self, onlyimg:bool = False):
569567
global workflow_json, extensions_id_conponents, extensions_id_conponents_value
570568
temp_json = {}
@@ -963,7 +961,7 @@ def custom_ui(self):
963961
State_Comps["background_import"] = gr.File(label="LightDiffusionFlow File",file_count="single",
964962
file_types=[File_extension],visible=False)
965963
State_Comps["json2js"] = gr.Textbox(label="json2js",visible=False)
966-
State_Comps["test_button"] = gr.Button(value='测试',elem_id='test_button',visible=True)
964+
State_Comps["test_button"] = gr.Button(value='测试',elem_id='test_button',visible=False)
967965
State_Comps["refresh_log"] = gr.Button(value='刷新日志',elem_id='img2img_invisible_refresh_log',visible=False)
968966
State_Comps["set_dropdowns"] = gr.Button(value='设置部分参数',elem_id='lightdiffusionflow_set_dropdowns',visible=False)
969967
State_Comps["set_js_params"] = gr.Button(value='设置剩下的js参数',elem_id='lightdiffusionflow_set_js_params',visible=False)

0 commit comments

Comments
 (0)