handle path cases for linux
parent
222073d5f0
commit
302ba65cc4
|
|
@ -228,7 +228,10 @@ Since v1.5.5, we've already optimized the SHA256 function to the top. So the onl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Change Log
|
# Change Log3
|
||||||
|
## v1.10.1
|
||||||
|
* Handle model path cases for linux
|
||||||
|
|
||||||
## v1.10.0
|
## v1.10.0
|
||||||
* Support SD webui v1.8.x
|
* Support SD webui v1.8.x
|
||||||
* With SD webui v1.8.x, this extension's refresh function is added to Official Extra Network's refresh button. There is no need another green fresh button anymore.
|
* With SD webui v1.8.x, this extension's refresh function is added to Official Extra Network's refresh button. There is no need another green fresh button anymore.
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,8 @@ const get_new_ch_py_msg = (max_count=5) => new Promise((resolve, reject) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getActiveTabType() {
|
function getActiveTabType() {
|
||||||
const currentTab = get_uiCurrentTabContent();
|
const currentTab = get_uiCurrentTabContent();
|
||||||
switch (currentTab.id) {
|
switch (currentTab.id) {
|
||||||
|
|
@ -381,12 +383,28 @@ async function remove_card(event, model_type, search_term){
|
||||||
let active_tab = getActiveTabType();
|
let active_tab = getActiveTabType();
|
||||||
console.log("get active tab id: " + active_tab);
|
console.log("get active tab id: " + active_tab);
|
||||||
if (active_tab){
|
if (active_tab){
|
||||||
let refresh_btn_id = active_tab + "_extra_refresh";
|
let refresh_btn_id = "";
|
||||||
let refresh_btn = gradioApp().getElementById(refresh_btn_id);
|
let refresh_btn = null;
|
||||||
|
|
||||||
|
//check sd version
|
||||||
|
let sd_version = ch_sd_version();
|
||||||
|
console.log(`sd version is: ${sd_version}`);
|
||||||
|
if (sd_version >= "1.8.0") {
|
||||||
|
let js_model_type = convertModelTypeFromPyToJS(model_type);
|
||||||
|
if (!js_model_type){return;}
|
||||||
|
|
||||||
|
refresh_btn_id = active_tab + "_" + js_model_type + "_extra_refresh";
|
||||||
|
refresh_btn = gradioApp().getElementById(refresh_btn_id);
|
||||||
|
} else {
|
||||||
|
refresh_btn_id = active_tab + "_extra_refresh";
|
||||||
|
refresh_btn = gradioApp().getElementById(refresh_btn_id);
|
||||||
|
}
|
||||||
|
|
||||||
if (refresh_btn){
|
if (refresh_btn){
|
||||||
console.log("click button: "+refresh_btn_id);
|
console.log("click button: "+refresh_btn_id);
|
||||||
refresh_btn.click();
|
refresh_btn.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1030,12 +1048,10 @@ onUiLoaded(() => {
|
||||||
//from sd v1.8, need to replace all single '\' into '\\'
|
//from sd v1.8, need to replace all single '\' into '\\'
|
||||||
search_term = search_term.replaceAll("\\", "\\\\");
|
search_term = search_term.replaceAll("\\", "\\\\");
|
||||||
|
|
||||||
//from sd v1.8, search_term is changed, also added a `data-sort-path` to card node with model's full path
|
//`data-sort-path` convert all path to lowercase, which can not be used to find model on linux.
|
||||||
//so we can use this new path and give up search_term
|
//so this is not used and fall back to use search_term
|
||||||
console.log("card path: " + card.dataset.sortPath);
|
//console.log("card path: " + card.dataset.sortPath);
|
||||||
card_path = card.dataset.sortPath.replaceAll("\\", "\\\\");
|
//card_path = card.dataset.sortPath.replaceAll("\\", "\\\\");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log("adding buttons");
|
console.log("adding buttons");
|
||||||
// then we need to add 3 buttons to each ul node:
|
// then we need to add 3 buttons to each ul node:
|
||||||
|
|
@ -1045,7 +1061,7 @@ onUiLoaded(() => {
|
||||||
open_url_node.className = "card-button";
|
open_url_node.className = "card-button";
|
||||||
|
|
||||||
open_url_node.title = "Open this model's civitai url";
|
open_url_node.title = "Open this model's civitai url";
|
||||||
open_url_node.setAttribute("onclick","open_model_url_with_path(event, '"+model_type+"', '"+card_path+"')");
|
open_url_node.setAttribute("onclick","open_model_url(event, '"+model_type+"', '"+search_term+"')");
|
||||||
|
|
||||||
let add_trigger_words_node = document.createElement("a");
|
let add_trigger_words_node = document.createElement("a");
|
||||||
add_trigger_words_node.href = "#";
|
add_trigger_words_node.href = "#";
|
||||||
|
|
@ -1053,7 +1069,7 @@ onUiLoaded(() => {
|
||||||
add_trigger_words_node.className = "card-button";
|
add_trigger_words_node.className = "card-button";
|
||||||
|
|
||||||
add_trigger_words_node.title = "Add trigger words to prompt";
|
add_trigger_words_node.title = "Add trigger words to prompt";
|
||||||
add_trigger_words_node.setAttribute("onclick","add_trigger_words_with_path(event, '"+model_type+"', '"+card_path+"')");
|
add_trigger_words_node.setAttribute("onclick","add_trigger_words(event, '"+model_type+"', '"+search_term+"')");
|
||||||
|
|
||||||
let use_preview_prompt_node = document.createElement("a");
|
let use_preview_prompt_node = document.createElement("a");
|
||||||
use_preview_prompt_node.href = "#";
|
use_preview_prompt_node.href = "#";
|
||||||
|
|
@ -1061,7 +1077,7 @@ onUiLoaded(() => {
|
||||||
use_preview_prompt_node.className = "card-button";
|
use_preview_prompt_node.className = "card-button";
|
||||||
|
|
||||||
use_preview_prompt_node.title = "Use prompt from preview image";
|
use_preview_prompt_node.title = "Use prompt from preview image";
|
||||||
use_preview_prompt_node.setAttribute("onclick","use_preview_prompt_with_path(event, '"+model_type+"', '"+card_path+"')");
|
use_preview_prompt_node.setAttribute("onclick","use_preview_prompt(event, '"+model_type+"', '"+search_term+"')");
|
||||||
|
|
||||||
let remove_card_node = document.createElement("a");
|
let remove_card_node = document.createElement("a");
|
||||||
remove_card_node.href = "#";
|
remove_card_node.href = "#";
|
||||||
|
|
@ -1069,7 +1085,7 @@ onUiLoaded(() => {
|
||||||
remove_card_node.className = "card-button";
|
remove_card_node.className = "card-button";
|
||||||
|
|
||||||
remove_card_node.title = "Remove this model";
|
remove_card_node.title = "Remove this model";
|
||||||
remove_card_node.setAttribute("onclick","remove_card_with_path(event, '"+model_type+"', '"+card_path+"')");
|
remove_card_node.setAttribute("onclick","remove_card(event, '"+model_type+"', '"+search_term+"')");
|
||||||
|
|
||||||
//add to card
|
//add to card
|
||||||
button_row.appendChild(open_url_node);
|
button_row.appendChild(open_url_node);
|
||||||
|
|
|
||||||
|
|
@ -201,11 +201,41 @@ def load_model_info_by_search_term(model_type, search_term):
|
||||||
util.printD("unknow model type: " + model_type)
|
util.printD("unknow model type: " + model_type)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# with sd webui < 1.8.0
|
||||||
# search_term = subfolderpath + model name + ext. And it always start with a / even there is no sub folder
|
# search_term = subfolderpath + model name + ext. And it always start with a / even there is no sub folder
|
||||||
|
# with sd webui >= 1.8.0
|
||||||
|
# search_term = model type + subfolderpath + model name + ext. And it always start with a / even there is no sub folder
|
||||||
|
# this model type is based on sd webui's model folder name. ti is embeddings, ckp is Stable-diffusion, and so on
|
||||||
base, ext = os.path.splitext(search_term)
|
base, ext = os.path.splitext(search_term)
|
||||||
model_info_base = base
|
model_info_base = base
|
||||||
if base[:1] == "/":
|
|
||||||
model_info_base = base[1:]
|
if model_info_base[:1] == "/":
|
||||||
|
model_info_base = model_info_base[1:]
|
||||||
|
|
||||||
|
|
||||||
|
model_folder_name = "";
|
||||||
|
if model_type == "ti":
|
||||||
|
model_folder_name = "embeddings"
|
||||||
|
elif model_type == "hyper":
|
||||||
|
model_folder_name = "hypernetworks"
|
||||||
|
elif model_type == "ckp":
|
||||||
|
model_folder_name = "Stable-diffusion"
|
||||||
|
else:
|
||||||
|
model_folder_name = "Lora"
|
||||||
|
|
||||||
|
# check if model folder is already in search_term
|
||||||
|
if model_info_base.startswith(model_folder_name):
|
||||||
|
# this is sd webui v1.8.0+'s search_term
|
||||||
|
# need to remove this model_folder_name+"/" or "\\" from model_info_base
|
||||||
|
model_info_base = model_info_base[len(model_folder_name):]
|
||||||
|
|
||||||
|
# util.printD("cut model_info_base: " + model_info_base)
|
||||||
|
|
||||||
|
if model_info_base.startswith("/") or model_info_base.startswith("\\"):
|
||||||
|
model_info_base = model_info_base[1:]
|
||||||
|
|
||||||
|
# util.printD("final model_info_base: " + model_info_base)
|
||||||
|
|
||||||
|
|
||||||
model_folder = model.folders[model_type]
|
model_folder = model.folders[model_type]
|
||||||
model_info_filename = model_info_base + suffix + model.info_ext
|
model_info_filename = model_info_base + suffix + model.info_ext
|
||||||
|
|
|
||||||
|
|
@ -149,12 +149,31 @@ def get_model_path_by_search_term(model_type:str, search_term:str):
|
||||||
|
|
||||||
model_sub_path = model_sub_path.strip()
|
model_sub_path = model_sub_path.strip()
|
||||||
|
|
||||||
|
|
||||||
if model_sub_path[:1] == "/":
|
if model_sub_path[:1] == "/":
|
||||||
model_sub_path = model_sub_path[1:]
|
model_sub_path = model_sub_path[1:]
|
||||||
|
|
||||||
|
model_folder_name = "";
|
||||||
|
if model_type == "ti":
|
||||||
|
model_folder_name = "embeddings"
|
||||||
|
elif model_type == "hyper":
|
||||||
|
model_folder_name = "hypernetworks"
|
||||||
|
elif model_type == "ckp":
|
||||||
|
model_folder_name = "Stable-diffusion"
|
||||||
|
else:
|
||||||
|
model_folder_name = "Lora"
|
||||||
|
|
||||||
|
# check if model folder is already in search_term
|
||||||
|
if model_sub_path.startswith(model_folder_name):
|
||||||
|
# this is sd webui v1.8.0+'s search_term
|
||||||
|
# need to remove this model_folder_name+"/"or""\\" from model_sub_path
|
||||||
|
model_sub_path = model_sub_path[len(model_folder_name):]
|
||||||
|
|
||||||
|
if model_sub_path.startswith("/") or model_sub_path.startswith("\\"):
|
||||||
|
model_sub_path = model_sub_path[1:]
|
||||||
|
|
||||||
if model_type == "hyper":
|
if model_type == "hyper":
|
||||||
model_sub_path = model_sub_path+".pt"
|
if not model_sub_path.endswith(".pt"):
|
||||||
|
model_sub_path = model_sub_path+".pt"
|
||||||
|
|
||||||
model_folder = folders[model_type]
|
model_folder = folders[model_type]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import requests
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
version = "1.10.0"
|
version = "1.10.1"
|
||||||
|
|
||||||
def_headers = {'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
|
def_headers = {'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
|
||||||
"Authorization": ""}
|
"Authorization": ""}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue