Skip to content

Commit 492114f

Browse files
author
legionfu
committed
refiner bug修复
图片保存逻辑优化 tab编号错误bug修复
1 parent 7ee2755 commit 492114f

File tree

7 files changed

+328
-315
lines changed

7 files changed

+328
-315
lines changed

ChangeLog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## 2.1.2
2+
3+
### Features:
4+
* UI组件增加elem_id。
5+
* flow文件导出时,支持自定义名称。
6+
7+
### Bug Fixes:
8+
* 图片组件保存功能优化,支持所有带elem_id的图片组件。
9+
因为gradio组件bug影响,目前暂时不支持不带elem_id的组件保存功能。目前新版本似乎已经修复,但秋叶启动器的gradio版本似乎还是旧版?
10+
issue链接: https://github.com/gradio-app/gradio/issues/5548
11+
* refiner参数保存bug修复。
12+
* 插件含tab的组件保存编号错误bug修复。
13+
114
## 2.1.1
215

316
### Bug Fixes:

javascript/state.core.js

Lines changed: 87 additions & 40 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,81 @@ 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=[];
108145

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

113183
function init() {
@@ -119,30 +189,7 @@ state.core = (function () {
119189
sd_versions = data
120190
});
121191

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-
192+
get_imgs_elem_key()
146193

147194
}
148195

@@ -671,36 +718,36 @@ state.core = (function () {
671718
startImportImage: function (index){
672719
index = Number(index)
673720

721+
console.log(`-------startImportImage--'${index}'---------------`)
674722
if(index+1 < img_elem_keys.length){
675723
//console.log(`---------${img_elem_keys}---------------`)
676-
//console.log(`---------${index}-----${img_elem_keys.length}-----------`)
724+
console.log(`---------'${index}'-----'${img_elem_keys.length}'-----------`)
677725
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)"
726+
"img2img_invisible_img2img_image": "switch_to_img2img()",
727+
"img2img_invisible_img2img_sketch": "switch_to_sketch()",
728+
"img2img_invisible_img2maskimg": "switch_to_inpaint()",
729+
"img2img_invisible_inpaint_sketch": "switch_to_inpaint_sketch()",
730+
"img2img_invisible_img_inpaint_base": "state.utils.switch_to_img_inpaint()",
731+
"img2img_invisible_img_inpaint_mask": "state.utils.switch_to_img_inpaint()",
732+
"img2img_invisible_txt2img_controlnet_ControlNet_input_image": "state.utils.switch_to_txt2img_ControlNet(0)",
733+
"img2img_invisible_img2img_controlnet_ControlNet_input_image": "state.utils.switch_to_img2img_ControlNet(0)"
686734
}
687735

688736
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})`
737+
switch_tab_dict[`img2img_invisible_txt2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_txt2img_ControlNet(${i})`
738+
switch_tab_dict[`img2img_invisible_img2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_img2img_ControlNet(${i})`
691739
}
692740

693741
state.utils.sleep(300).then(() => {
694742
try{
695-
key = "txt2img_invisible_"+img_elem_keys[index+1]
743+
key = "img2img_invisible_"+img_elem_keys[index+1]
696744
eval( switch_tab_dict[key] ) // 跳转界面
697745
const button = gradioApp().getElementById(key);
698746
button.click();
699747
} catch (error) {
700748
console.warn('[startImportImage]: Error:', error);
701749
if(index+1 < img_elem_keys.length){
702750
// 图片组件设置出错了,但是需要继续后续的流程
703-
704751
index = img_elem_keys.length-1
705752
}
706753
}
@@ -736,7 +783,7 @@ state.core = (function () {
736783
},
737784
output_log: function (msg, msg_style=""){
738785
fetch(`/lightdiffusionflow/local/output_log?msg=${msg}&style=${msg_style}`).then(() => {
739-
gradioApp().getElementById("txt2img_invisible_refresh_log").click();
786+
gradioApp().getElementById("img2img_invisible_refresh_log").click();
740787
});
741788
},
742789
output_warning: function (msg, msg_style="color:Orange;"){

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) {

javascript/state.utils.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ state.utils = {
211211
}
212212
},
213213

214+
onAccordionChange: function onAccordionChange(targetNode, func) {
215+
if(targetNode) {
216+
const observer = new MutationObserver((mutationsList, observer) => {
217+
for (const mutation of mutationsList) {
218+
if (mutation.type === 'attributes' ) {
219+
func(targetNode);
220+
}
221+
}
222+
});
223+
observer.observe(targetNode, {
224+
attributes: true,
225+
});
226+
}
227+
},
228+
214229
getCurSeed: function getCurSeed(tab) {
215230
const elements = gradioApp().getElementById(`html_info_${tab}`).querySelectorAll(`#html_info_${tab}`);
216231
if (! elements || ! elements.length || !elements[0].innerText) {
@@ -252,7 +267,7 @@ state.utils = {
252267
} catch (error) {
253268
console.warn('[state]: Error:', error);
254269
}
255-
270+
console.log(`image changed ${id}`)
256271
fetch(`/lightdiffusionflow/local/imgs_callback`, data)
257272
});
258273
}, 150);
@@ -333,20 +348,20 @@ state.utils = {
333348
let child = accordion.querySelector('div.cursor-pointer, .label-wrap');
334349
if (value) {
335350
//for(child of children){
336-
let span = child.querySelector('.transition, .icon');
337-
if(span.style.transform !== 'rotate(90deg)'){
338-
//if(child.className.split(' ').pop() != "open"){
351+
//let span = child.querySelector('.transition, .icon');
352+
//if(span.style.transform !== 'rotate(90deg)'){
353+
if(child.className.split(' ').pop() != "open"){
339354
state.utils.triggerMouseEvent(child, 'click')
340355
}
341356
//}
342357
}
343358

344359
setTimeout(() => {
345-
state.utils.onContentChange(child, function (el) {
346-
//store.set(id, el.className.split(' ').pop() == "open");
360+
state.utils.onAccordionChange(child, function (el) {
361+
store.set(id, el.className.split(' ').pop() == "open");
347362
//console.log(`accordion on change ${id}`)
348-
let span = el.querySelector('.transition, .icon');
349-
store.set(id, span.style.transform !== 'rotate(90deg)');
363+
//let span = el.querySelector('.transition, .icon');
364+
//store.set(id, span.style.transform !== 'rotate(90deg)');
350365
});
351366
}, 150);
352367

@@ -551,6 +566,14 @@ state.utils = {
551566
const link = document.createElement('a');
552567
link.href = url;
553568
link.download = fileName;
569+
570+
// // 创建一个<input type="file">元素,并设置其webkitdirectory属性为下载路径
571+
// var fileInput = document.createElement('input');
572+
// fileInput.type = 'file';
573+
// fileInput.style.display = 'none';
574+
// fileInput.webkitdirectory = path;
575+
576+
// document.body.appendChild(fileInput);
554577
document.body.appendChild(link);
555578
link.click();
556579
link.parentNode.removeChild(link);

scripts/lightdiffusionflow_config.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,29 @@ def init():
5454
] # 只保存图片组件id,其他参数js里搞定
5555

5656

57-
# init number of controlnet
58-
try:
59-
webui_settings = {}
60-
with open(shared.cmd_opts.ui_settings_file, mode='r') as f:
61-
json_str = f.read()
62-
webui_settings = json.loads(json_str)
57+
# # init number of controlnet
58+
# try:
59+
# webui_settings = {}
60+
# with open(shared.cmd_opts.ui_settings_file, mode='r') as f:
61+
# json_str = f.read()
62+
# webui_settings = json.loads(json_str)
6363

64-
Multi_ControlNet = webui_settings.get("control_net_unit_count", None) # controlnet数量,新版名字
65-
if(Multi_ControlNet == None):
66-
Multi_ControlNet = webui_settings.get("control_net_max_models_num", 0)
67-
print(f"Multi_ControlNet = {Multi_ControlNet}")
68-
if(Multi_ControlNet == 1):
69-
Image_Components_Key.append(f"txt2img_controlnet_ControlNet_input_image")
70-
Image_Components_Key.append(f"img2img_controlnet_ControlNet_input_image")
71-
else:
72-
for i in range(Multi_ControlNet):
73-
Image_Components_Key.append(f"txt2img_controlnet_ControlNet-{i}_input_image")
74-
Image_Components_Key.append(f"img2img_controlnet_ControlNet-{i}_input_image")
64+
# Multi_ControlNet = webui_settings.get("control_net_unit_count", None) # controlnet数量,新版名字
65+
# if(Multi_ControlNet == None):
66+
# Multi_ControlNet = webui_settings.get("control_net_max_models_num", 0)
67+
# print(f"Multi_ControlNet = {Multi_ControlNet}")
68+
# if(Multi_ControlNet == 1):
69+
# Image_Components_Key.append(f"txt2img_controlnet_ControlNet_input_image")
70+
# Image_Components_Key.append(f"img2img_controlnet_ControlNet_input_image")
71+
# else:
72+
# for i in range(Multi_ControlNet):
73+
# Image_Components_Key.append(f"txt2img_controlnet_ControlNet-{i}_input_image")
74+
# Image_Components_Key.append(f"img2img_controlnet_ControlNet-{i}_input_image")
7575

76-
except:
77-
pass
76+
# except:
77+
# pass
7878

79-
# Segment Anything images
80-
Image_Components_Key.extend(["txt2img_sam_input_image","img2img_sam_input_image"])
79+
# # Segment Anything images
80+
# Image_Components_Key.extend(["txt2img_sam_input_image","img2img_sam_input_image"])
8181

8282
init()

0 commit comments

Comments
 (0)