Skip to content

Commit 5714e8b

Browse files
authored
Merge pull request #15 from Tencent/Branch_dev
Branch dev
2 parents 81ba1be + c50f431 commit 5714e8b

File tree

8 files changed

+629
-407
lines changed

8 files changed

+629
-407
lines changed

ChangeLog.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
## 2.1.2
2+
3+
### Features:
4+
* UI组件增加elem_id。
5+
* flow文件导出时,支持自定义名称。
6+
* ControlNet模型支持模糊匹配。
7+
* 如本地没有ControlNet模型,会提供下载链接。
8+
* 缺失插件提示。
9+
* 插件增加中英文切换。
10+
11+
### Bug Fixes:
12+
* 图片组件保存功能优化,支持所有带elem_id的图片组件。
13+
因为gradio组件bug影响,目前暂时不支持不带elem_id的组件保存功能。
14+
目前新版本似乎已经修复,但秋叶启动器的gradio版本似乎还是旧版?待跟进。
15+
issue链接: https://github.com/gradio-app/gradio/issues/5548
16+
* refiner参数保存bug修复。
17+
* 插件含tab的组件保存编号错误bug修复。
18+
* 插件导入提示优化。
19+
* 参数保存逻辑优化。
20+
* 之前版本会保存多余参数,当前版本已修改,但注意缺失插件的提示,不一定是真的需要。
21+
122
## 2.1.1
223

324
### Bug Fixes:

javascript/state.core.js

Lines changed: 155 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ state.core = (function () {
7474

7575
let store = null;
7676
let timer = null;
77+
let inited = false
7778
let sd_versions = "0.0.0"
7879

7980
function hasSetting(id, tab) {
@@ -84,7 +85,8 @@ state.core = (function () {
8485

8586
function fn_timer(){
8687

87-
fetch('/lightdiffusionflow/local/need_preload')
88+
// if(inited){
89+
fetch('/lightdiffusionflow/local/need_preload')
8890
.then(response => response.json())
8991
.then(data => {
9092
//console.log(`fn_timer`)
@@ -101,13 +103,88 @@ state.core = (function () {
101103
clearInterval(timer)
102104
console.log("Oops, error");
103105
});
106+
// }
107+
// else{
108+
109+
// fetch('/lightdiffusionflow/local/get_imgs_elem_key') //初始化部分图片组件id, 后续设置onchanged事件
110+
// .then(response => response.json())
111+
// .then(data => {
112+
// console.log('-----------------------------')
113+
// console.log(data)
114+
// console.log('-----------------------------')
115+
// if(data != ""){
116+
117+
// img_elem_keys = data.split(",")
118+
// img_elem_keys.forEach(key => {
119+
// IMAGES_WITHOUT_PREFIX[key] = key
120+
// });
121+
122+
// // 等上面的组件ID同步过来后 再加载其他配置
123+
// fetch('/lightdiffusionflow/local/config.json?_=' + (+new Date()))
124+
// .then(response => response.json())
125+
// .then(config => {
126+
// try {
127+
// store = new state.Store();
128+
// store.clearAll();
129+
// load(config);
130+
// inited = true
131+
// } catch (error) {
132+
// console.error('[state]: Error:', error);
133+
// }
134+
// })
135+
// .catch(error => console.error('[state]: Error getting JSON file:', error));
136+
// }
137+
// });
138+
104139

140+
// }
141+
105142
}
106143

107144
let img_elem_keys=[];
145+
let ext_list=[];
108146

109147
function get_imgs_elem_key(){
110-
return img_elem_keys;
148+
149+
fetch('/lightdiffusionflow/local/get_imgs_elem_key') //初始化部分图片组件id, 后续设置onchanged事件
150+
.then(response => response.json())
151+
.then(data => {
152+
console.log(data)
153+
if(data == ''){
154+
console.log('-----------------------------')
155+
setTimeout(() => {
156+
get_imgs_elem_key()
157+
}, 500);
158+
}
159+
else{
160+
img_elem_keys = data.split(",")
161+
img_elem_keys.forEach(key => {
162+
IMAGES_WITHOUT_PREFIX[key] = key
163+
});
164+
165+
fetch('/lightdiffusionflow/local/get_ext_list')
166+
.then(response => response.json())
167+
.then(data => {
168+
ext_list = data.split(",")
169+
});
170+
171+
// 等上面的组件ID同步过来后 再加载其他配置
172+
fetch('/lightdiffusionflow/local/config.json?_=' + (+new Date()))
173+
.then(response => response.json())
174+
.then(config => {
175+
try {
176+
store = new state.Store();
177+
store.clearAll();
178+
load(config);
179+
timer = window.setInterval(fn_timer,1000); // 初始化页面完成后再启动timer读取文件
180+
} catch (error) {
181+
console.error('[state]: Error:', error);
182+
}
183+
})
184+
.catch(error => console.error('[state]: Error getting JSON file:', error));
185+
}
186+
});
187+
111188
}
112189

113190
function init() {
@@ -119,30 +196,7 @@ state.core = (function () {
119196
sd_versions = data
120197
});
121198

122-
fetch('/lightdiffusionflow/local/get_imgs_elem_key') //初始化部分图片组件id, 后续设置onchanged事件
123-
.then(response => response.json())
124-
.then(data => {
125-
img_elem_keys = data.split(",")
126-
img_elem_keys.forEach(key => {
127-
IMAGES_WITHOUT_PREFIX[key] = key
128-
});
129-
130-
// 等上面的组件ID同步过来后 再加载其他配置
131-
fetch('/lightdiffusionflow/local/config.json?_=' + (+new Date()))
132-
.then(response => response.json())
133-
.then(config => {
134-
try {
135-
store = new state.Store();
136-
store.clearAll();
137-
load(config);
138-
timer = window.setInterval(fn_timer,1000); // 初始化页面完成后再启动timer读取文件
139-
} catch (error) {
140-
console.error('[state]: Error:', error);
141-
}
142-
})
143-
.catch(error => console.error('[state]: Error getting JSON file:', error));
144-
});
145-
199+
get_imgs_elem_key()
146200

147201
}
148202

@@ -555,6 +609,13 @@ state.core = (function () {
555609
}
556610
}
557611

612+
for (let key in stored_config){
613+
if(key.indexOf("allow-preview") !== -1 && key.indexOf("ext-control-net") !== -1)
614+
{
615+
stored_config[key] = "false"
616+
}
617+
}
618+
558619
var checkTime = function (i) {
559620
if (i < 10) { i = "0" + i; }
560621
return i;
@@ -575,6 +636,8 @@ state.core = (function () {
575636
filename += ".flow";
576637
}
577638
if(filename != ".flow"){
639+
// const handle = window.showDirectoryPicker();
640+
// console.log(handle)
578641
state.utils.saveFile(filename, stored_config);
579642
}
580643

@@ -585,14 +648,16 @@ state.core = (function () {
585648
},
586649

587650
handleLightDiffusionFlow: function (fileInput){
588-
actions.output_log("Start parsing settings...")
651+
actions.preset_output_log("start")
652+
//actions.output_log("<hr style='margin-top:10px;margin-bottom:10px'>Start parsing settings...")
589653
console.log(fileInput)
590654
let temp_fileInput = undefined
591655
try{temp_fileInput = fileInput[0]} catch(error){}
592656
if ( !temp_fileInput ) {temp_fileInput = fileInput}
593657
if ( !temp_fileInput ) {
594658
//alert('Please select a JSON file!');
595-
actions.output_log("Please select a valid lightdiffusionflow or image file!")
659+
actions.preset_output_log("invalid")
660+
//actions.output_log("Please select a valid lightdiffusionflow or image file!")
596661
return;
597662
}
598663

@@ -655,52 +720,87 @@ state.core = (function () {
655720

656721
let json_obj = {}
657722
try { json_obj = JSON.parse(inputData) } catch (error) {
658-
actions.output_log("Please select a valid lightdiffusionflow or image file!")
723+
actions.preset_output_log("invalid")
724+
//actions.output_log("Please select a valid lightdiffusionflow or image file!")
659725
return;
660726
}
661727

662-
forEachElement_WithoutTabs(IMAGES_WITHOUT_PREFIX, (image_id) => {
663-
json_obj[image_id] = ""
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+
}
753+
}
754+
}
755+
}
756+
757+
if(missing_ext_list.length > 0){
758+
actions.preset_output_log("missing_exts","",missing_ext_list.join(';'))
759+
}
760+
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();
664768
});
665-
// webui主界面 没有localization相关的兼容问题 所以不用管
666-
store.clear();
667-
store.load(json_obj);
668-
actions.applyState();
669769
return;
670770
},
671771
startImportImage: function (index){
672772
index = Number(index)
673773

774+
//console.log(`-------startImportImage--'${index}'---------------`)
674775
if(index+1 < img_elem_keys.length){
675776
//console.log(`---------${img_elem_keys}---------------`)
676-
//console.log(`---------${index}-----${img_elem_keys.length}-----------`)
777+
//console.log(`---------'${index}'-----'${img_elem_keys.length}'-----------`)
677778
switch_tab_dict = {
678-
"txt2img_invisible_img2img_image": "switch_to_img2img()",
679-
"txt2img_invisible_img2img_sketch": "switch_to_sketch()",
680-
"txt2img_invisible_img2maskimg": "switch_to_inpaint()",
681-
"txt2img_invisible_inpaint_sketch": "switch_to_inpaint_sketch()",
682-
"txt2img_invisible_img_inpaint_base": "state.utils.switch_to_img_inpaint()",
683-
"txt2img_invisible_img_inpaint_mask": "state.utils.switch_to_img_inpaint()",
684-
"txt2img_invisible_txt2img_controlnet_ControlNet_input_image": "state.utils.switch_to_txt2img_ControlNet(0)",
685-
"txt2img_invisible_img2img_controlnet_ControlNet_input_image": "state.utils.switch_to_img2img_ControlNet(0)"
779+
"img2img_invisible_img2img_image": "switch_to_img2img()",
780+
"img2img_invisible_img2img_sketch": "switch_to_sketch()",
781+
"img2img_invisible_img2maskimg": "switch_to_inpaint()",
782+
"img2img_invisible_inpaint_sketch": "switch_to_inpaint_sketch()",
783+
"img2img_invisible_img_inpaint_base": "state.utils.switch_to_img_inpaint()",
784+
"img2img_invisible_img_inpaint_mask": "state.utils.switch_to_img_inpaint()",
785+
"img2img_invisible_txt2img_controlnet_ControlNet_input_image": "state.utils.switch_to_txt2img_ControlNet(0)",
786+
"img2img_invisible_img2img_controlnet_ControlNet_input_image": "state.utils.switch_to_img2img_ControlNet(0)"
686787
}
687788

688789
for (let i = 0; i < 10; i++) {
689-
switch_tab_dict[`txt2img_invisible_txt2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_txt2img_ControlNet(${i})`
690-
switch_tab_dict[`txt2img_invisible_img2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_img2img_ControlNet(${i})`
790+
switch_tab_dict[`img2img_invisible_txt2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_txt2img_ControlNet(${i})`
791+
switch_tab_dict[`img2img_invisible_img2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_img2img_ControlNet(${i})`
691792
}
692793

693794
state.utils.sleep(300).then(() => {
694795
try{
695-
key = "txt2img_invisible_"+img_elem_keys[index+1]
796+
key = "img2img_invisible_"+img_elem_keys[index+1]
696797
eval( switch_tab_dict[key] ) // 跳转界面
697798
const button = gradioApp().getElementById(key);
698799
button.click();
699800
} catch (error) {
700801
console.warn('[startImportImage]: Error:', error);
701802
if(index+1 < img_elem_keys.length){
702803
// 图片组件设置出错了,但是需要继续后续的流程
703-
704804
index = img_elem_keys.length-1
705805
}
706806
}
@@ -732,17 +832,21 @@ state.core = (function () {
732832
// });
733833
// break
734834
}
735-
835+
},
836+
preset_output_log: function (preset, key="", value=""){
837+
fetch(`/lightdiffusionflow/local/preset_output_log?preset=${preset}&key=${key}&value=${value}`).then(() => {
838+
gradioApp().getElementById("img2img_invisible_refresh_log").click();
839+
});
736840
},
737841
output_log: function (msg, msg_style=""){
738842
fetch(`/lightdiffusionflow/local/output_log?msg=${msg}&style=${msg_style}`).then(() => {
739-
gradioApp().getElementById("txt2img_invisible_refresh_log").click();
843+
gradioApp().getElementById("img2img_invisible_refresh_log").click();
740844
});
741845
},
742846
output_warning: function (msg, msg_style="color:Orange;"){
743847
actions.output_log(msg,msg_style)
744848
},
745-
output_error: function (msg, msg_style="color:Tomato;"){
849+
output_error: function (msg, msg_style="color:Red;"){
746850
actions.output_log(msg,msg_style)
747851
},
748852
get_sd_version: function (){

javascript/state.ext.general.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,11 @@ function general_ext(tab_name, extension_name, root_container) {
365365
return;
366366
}
367367

368-
let tabs = container.querySelectorAll('.tabitem');
369-
//console.log(tabs)
368+
let tabnav = container.getElementsByClassName('tabs');
369+
let tabs = []
370+
if(tabnav.length > 0 ){
371+
tabs = Array.from(tabnav[0].childNodes).filter(item => item.className && item.className.indexOf("tabitem") !== -1)
372+
}
370373

371374
cnTabs = [];
372375
if (tabs.length) {

0 commit comments

Comments
 (0)