Skip to content

Commit 7b498b3

Browse files
author
legionfu
committed
sd webui 1.6以前的版本兼容问题解决
1 parent 4e62b11 commit 7b498b3

File tree

6 files changed

+121
-54
lines changed

6 files changed

+121
-54
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.1.1
2+
3+
### Bug Fixes:
4+
* sd webui v1.6.0 之前的版本兼容问题解决。
5+
16
## 2.1.0
27

38
### Bug Fixes:

javascript/state.core.js

Lines changed: 8 additions & 0 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 sd_versions = "0.0.0"
7778

7879
function hasSetting(id, tab) {
7980
return true // 需要默认保存全部选项 不需要判断
@@ -113,6 +114,10 @@ state.core = (function () {
113114

114115
//console.log(window.localization)
115116
fetch('/lightdiffusionflow/local/refresh_ui') // 刷新页面触发python重置图片数据
117+
.then(response => response.json())
118+
.then(data => {
119+
sd_versions = data
120+
});
116121

117122
fetch('/lightdiffusionflow/local/get_imgs_elem_key') //初始化部分图片组件id, 后续设置onchanged事件
118123
.then(response => response.json())
@@ -730,6 +735,9 @@ state.core = (function () {
730735
},
731736
output_error: function (msg, msg_style="color:Tomato;"){
732737
actions.output_log(msg,msg_style)
738+
},
739+
get_sd_version: function (){
740+
return sd_versions
733741
}
734742
};
735743

javascript/state.ext.general.js

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -154,46 +154,73 @@ function general_ext(tab_name, extension_name, root_container) {
154154

155155
}
156156

157-
function handleSelect(select, index, store) {
157+
function handleSelect(select, store) {
158158
let translations = state.utils.reverseTranslation(select.querySelector('label').firstChild.textContent)
159-
// for (var text of translations){
160-
// var id = state.utils.txtToId(text);
161-
// var value = store.get(id);
162-
// if (value) {break}
163-
// }
159+
for (var text of translations){
160+
var id = state.utils.txtToId(text);
161+
var value = store.get(id);
162+
if (value) {break}
163+
}
164164
//id = state.utils.txtToId(translations[0]);
165165
//if (value) { //前面不需要判断是否有值,因为需要执行handleSelect绑定onchange事件
166-
//state.utils.handleSelect(select, id, store, force=true);
166+
state.utils.handleSelect(select, id, store, force=true);
167167
//}
168168

169-
let id = state.constants.LS_PREFIX+LS_PREFIX+"dropdown_"+index
170-
state.utils.onContentChange(select, function (el) {
171-
console.log(`onContentChange ${id}`)
172-
let selected = el.querySelector('span.single-select');
173-
if (selected) {
174-
store.setWithNoPrefix(id, selected.textContent);
175-
} else {
176-
// new gradio version...
177-
let input = el.querySelector('input');
178-
if (input) {
179-
store.setWithNoPrefix(id, input.value);
180-
}
181-
}
182-
183-
});
169+
// let id = state.constants.LS_PREFIX+LS_PREFIX+"dropdown_"+index
170+
// state.utils.onContentChange(select, function (el) {
171+
// console.log(`onContentChange ${id}`)
172+
// let selected = el.querySelector('span.single-select');
173+
// if (selected) {
174+
// store.setWithNoPrefix(id, selected.textContent);
175+
// } else {
176+
// // new gradio version...
177+
// let input = el.querySelector('input');
178+
// if (input) {
179+
// store.setWithNoPrefix(id, input.value);
180+
// }
181+
// }
182+
// });
184183

185184
if (id === 'preprocessor' && value && value.toLowerCase() !== 'none') {
186185
state.utils.onNextUiUpdates(handleSliders); // update new sliders if needed
187186
}
188187
}
189188
function handleSelects() {
190-
//let select_index = 0
189+
// let root_selects = root_not_tabs.container.querySelectorAll('.gradio-dropdown');
190+
// root_selects.forEach(function (root_select) {
191+
// if(cnTabs.length == 0){
192+
// handleSelect(root_select, global_dropdown_index[ext_name], root_not_tabs.store)
193+
// global_dropdown_index[ext_name] += 1
194+
// console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
195+
// }
196+
// else{
197+
// let needsHandle = true
198+
// for(let tab of cnTabs){
199+
// if(tab.container.contains(root_select)){
200+
// needsHandle = false
201+
// break
202+
// }
203+
// }
204+
// if(needsHandle){
205+
// handleSelect(root_select, global_dropdown_index[ext_name], root_not_tabs.store)
206+
// global_dropdown_index[ext_name] += 1
207+
// console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
208+
// }
209+
// } // else
210+
// });
211+
212+
// cnTabs.forEach(({ container, store }) => {
213+
// container.querySelectorAll('.gradio-dropdown').forEach(select => {
214+
// handleSelect(select, global_dropdown_index[ext_name], store)
215+
// global_dropdown_index[ext_name] += 1
216+
// console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
217+
// });
218+
// });
219+
191220
let root_selects = root_not_tabs.container.querySelectorAll('.gradio-dropdown');
192221
root_selects.forEach(function (root_select) {
193222
if(cnTabs.length == 0){
194-
handleSelect(root_select, global_dropdown_index[ext_name], root_not_tabs.store)
195-
global_dropdown_index[ext_name] += 1
196-
console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
223+
handleSelect(root_select, root_not_tabs.store)
197224
}
198225
else{
199226
let needsHandle = true
@@ -203,19 +230,13 @@ function general_ext(tab_name, extension_name, root_container) {
203230
break
204231
}
205232
}
206-
if(needsHandle){
207-
handleSelect(root_select, global_dropdown_index[ext_name], root_not_tabs.store)
208-
global_dropdown_index[ext_name] += 1
209-
console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
210-
}
233+
if(needsHandle){handleSelect(root_select, root_not_tabs.store)}
211234
} // else
212235
});
213236

214237
cnTabs.forEach(({ container, store }) => {
215238
container.querySelectorAll('.gradio-dropdown').forEach(select => {
216-
handleSelect(select, global_dropdown_index[ext_name], store)
217-
global_dropdown_index[ext_name] += 1
218-
console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
239+
handleSelect(select, store)
219240
});
220241
});
221242

@@ -327,7 +348,10 @@ function general_ext(tab_name, extension_name, root_container) {
327348
handleTabs();
328349
handleCheckboxes();
329350
handleTextAreas();
330-
//handleSelects();
351+
if(state.utils.target_is_newer_version(state.core.actions.get_sd_version(), "v1.6.0")){
352+
console.log("-----------general handleSelects-------")
353+
handleSelects();
354+
}
331355
handleSliders();
332356
handleRadioButtons();
333357
}, 500);
@@ -423,17 +447,17 @@ function general_ext_main(tab){
423447
let ext_name = title.replace(" ","-").toLowerCase()
424448
console.log(ext_name)
425449

426-
if(!global_dropdown_index[ext_name]){
427-
global_dropdown_index[ext_name] = 0
428-
}
450+
// if(!global_dropdown_index[ext_name]){
451+
// global_dropdown_index[ext_name] = 0
452+
// }
429453
general_ext(cur_tab_name, ext_name, root_container).init();
430454
}
431455

432456
}
433457
return {init}
434458
}
435459

436-
global_dropdown_index = {} // py里是不分txt2img和img2img的,但是这里是需要区分的。。
460+
//global_dropdown_index = {} // py里是不分txt2img和img2img的,但是这里是需要区分的。。
437461

438462
const TABS = ['txt2img', 'img2img'];
439463
for (tab of TABS){

javascript/state.utils.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,33 @@ state.utils = {
1010
// button.click();
1111
},
1212

13+
target_is_newer_version: function(cur_version, target_version){
14+
15+
let cur = cur_version.replace("v","")
16+
cur = cur.split(".")
17+
18+
let target = target_version.replace("v","")
19+
target = target.split(".")
20+
let version_len = Math.min(cur.length, target.length)
21+
22+
// 逐个版本号比较 v1.2.3 和 v1.2比较时,只比较前面两个数字
23+
for (let i=0; i < version_len; i++){
24+
if(Number(cur[i]) > Number(target[i])){
25+
return false
26+
}
27+
else if(Number(cur[i]) < Number(target[i])){
28+
return true
29+
}
30+
}
31+
32+
// 前面的版本号一样,再看谁的版本号更长
33+
if(cur.length >= target.length){
34+
return false
35+
}
36+
37+
return true
38+
},
39+
1340
searchCheckPointByHash: async function searchCheckPointByHash(hash){
1441
let downloadUrl = undefined
1542
hash_str = hash.replace("[","").replace("]","").replace(/^\s+|\s+$/g,"")
@@ -353,26 +380,28 @@ state.utils = {
353380
}
354381
}
355382

356-
let hash_pos = localized_value.search(/\[[0-9A-Fa-f]{10}\]/)
383+
let hash_res = localized_value.match(/\[[0-9A-Fa-f]{8,10}\]/)
357384
if(!successed){ // && hash_pos != -1 找不到对应选项 并且选项里有10位哈希值
358385
for (li of items){
359386

360387
// 去掉Hash比较
361388
let text = li.lastChild.wholeText.trim()
362-
let localized_value_no_hash = localized_value.replace(/\[[0-9A-Fa-f]{10}\]/,"").replace(/^\s+|\s+$/g,"")
363-
let text_no_hash = text.replace(/\[[0-9A-Fa-f]{10}\]/, "").replace(/^\s+|\s+$/g,"")
389+
let localized_value_no_hash = localized_value.replace(/\[[0-9A-Fa-f]{8,10}\]/,"").replace(/^\s+|\s+$/g,"")
390+
let text_no_hash = text.replace(/\[[0-9A-Fa-f]{8,10}\]/, "").replace(/^\s+|\s+$/g,"")
364391

365392
if (localized_value_no_hash === text_no_hash) {
366393
successed = true
367394
}
368395

369396
// 只比较Hash
370-
if(!successed){
371-
let hash_str = localized_value.substring(hash_pos,hash_pos+12).replace(/^\s+|\s+$/g,"")
372-
let text_hash_pos = text.search(/\[[0-9A-Fa-f]{10}\]/)
373-
let text_hash = text.substring(text_hash_pos, text_hash_pos+12).replace(/^\s+|\s+$/g,"")
374-
if (hash_str === text_hash) {
375-
successed = true
397+
if(!successed && hash_res != null){
398+
let hash_str = hash_res[0].replace(/^\s+|\s+$/g,"")
399+
let text_hash_res = text.match(/\[[0-9A-Fa-f]{8,10}\]/)
400+
if(text_hash_res != null){
401+
let text_hash = text_hash_res[0].replace(/^\s+|\s+$/g,"")
402+
if (hash_str === text_hash) {
403+
successed = true
404+
}
376405
}
377406
}
378407

@@ -395,9 +424,9 @@ state.utils = {
395424
else{
396425
state.core.actions.output_error(`\'${option_name}\' import failed! The option \'${value}\' was not found!`)
397426
}
398-
if(hash_pos != -1){
427+
if(hash_res != null){
399428
let model_name = value
400-
let hash_str = localized_value.substring(hash_pos,hash_pos+12)
429+
let hash_str = hash_res[0]
401430
state.utils.searchCheckPointByHash(hash_str).then( downloadUrl => {
402431
if(downloadUrl != undefined){
403432
let warning_str = encodeURIComponent(`click to download \
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lightdiffusionflow_version = "v2.1.0"
1+
lightdiffusionflow_version = "v2.1.1"

scripts/state_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import modules.generation_parameters_copypaste as parameters_copypaste
2020
from modules.generation_parameters_copypaste import paste_fields, registered_param_bindings, parse_generation_parameters
2121
from modules.sd_models import checkpoints_list
22-
22+
import launch
2323

2424
from scripts import lightdiffusionflow_version, lightdiffusionflow_config
2525
import scripts.lightdiffusionflow_config as lf_config
@@ -681,7 +681,9 @@ def refresh_ui(self):
681681
global workflow_json, Output_Log
682682
workflow_json = {}
683683
Output_Log = ""
684-
print("refresh_ui")
684+
print("refresh_ui")
685+
tag = launch.git_tag()
686+
return tag
685687

686688
def set_preload(self, params:file_params):
687689
global Need_Preload,Preload_File
@@ -799,7 +801,6 @@ def after_component(self, component, **kwargs):
799801

800802
if (isinstance(component, gr.Button) and kwargs["elem_id"] == "img2img_generation_info_button"): # 加载到最后一个组件了。 兼容旧版,暂时不使用“img2img_preview_filename”
801803

802-
803804
searching_extensions_title()
804805
#print(extensions_conponents)
805806

0 commit comments

Comments
 (0)