support sd webui v1.8
parent
b35857270a
commit
5434f0c203
|
|
@ -229,6 +229,10 @@ Since v1.5.5, we've already optimized the SHA256 function to the top. So the onl
|
|||
|
||||
|
||||
# Change Log
|
||||
## v1.10.0
|
||||
* 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.
|
||||
|
||||
## v1.9.1
|
||||
* Ignore video preview from civitai
|
||||
|
||||
|
|
|
|||
|
|
@ -11,28 +11,28 @@ function ch_img_node_str(path){
|
|||
return `<img src='${ch_convert_file_path_to_url(path)}' style="width:24px"/>`;
|
||||
}
|
||||
|
||||
|
||||
function ch_gradio_version(){
|
||||
function ch_sd_version(){
|
||||
let foot = gradioApp().getElementById("footer");
|
||||
if (!foot){return null;}
|
||||
|
||||
let versions = foot.querySelector(".versions");
|
||||
if (!versions){return null;}
|
||||
|
||||
if (versions.innerHTML.indexOf("gradio: 3.16.2")>0) {
|
||||
return "3.16.2";
|
||||
} else {
|
||||
return "3.23.0";
|
||||
}
|
||||
let links = versions.getElementsByTagName("a");
|
||||
if (links == null || links.length == 0){return null;}
|
||||
|
||||
return links[0].innerHTML.substring(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send msg to python side by filling a hidden text box
|
||||
// then will click a button to trigger an action
|
||||
// msg is an object, not a string, will be stringify in this function
|
||||
function send_ch_py_msg(msg){
|
||||
console.log("run send_ch_py_msg")
|
||||
console.log("msg: " + JSON.stringify(msg));
|
||||
|
||||
let js_msg_txtbox = gradioApp().querySelector("#ch_js_msg_txtbox textarea");
|
||||
if (js_msg_txtbox && msg) {
|
||||
// fill to msg box
|
||||
|
|
@ -137,6 +137,48 @@ function getActiveNegativePrompt() {
|
|||
}
|
||||
|
||||
|
||||
//convert model type between js style and python style
|
||||
function convertModelTypeFromPyToJS(model_type) {
|
||||
let js_model_type = "";
|
||||
switch (model_type) {
|
||||
case "ti":
|
||||
js_model_type = "textual_inversion";
|
||||
break;
|
||||
case "hyper":
|
||||
js_model_type = "hypernetworks";
|
||||
break;
|
||||
case "ckp":
|
||||
js_model_type = "checkpoints";
|
||||
break;
|
||||
case "lora":
|
||||
js_model_type = "lora";
|
||||
break;
|
||||
}
|
||||
|
||||
return js_model_type;
|
||||
}
|
||||
|
||||
function convertModelTypeFromJsToPy(js_model_type) {
|
||||
let model_type = "";
|
||||
switch (js_model_type) {
|
||||
case "textual_inversion":
|
||||
model_type = "ti";
|
||||
break;
|
||||
case "hypernetworks":
|
||||
model_type = "hyper";
|
||||
break;
|
||||
case "checkpoints":
|
||||
model_type = "ckp";
|
||||
break;
|
||||
case "lora":
|
||||
model_type = "lora";
|
||||
break;
|
||||
}
|
||||
|
||||
return model_type;
|
||||
}
|
||||
|
||||
|
||||
//button's click function
|
||||
async function open_model_url(event, model_type, search_term){
|
||||
console.log("start open_model_url");
|
||||
|
|
@ -150,20 +192,13 @@ async function open_model_url(event, model_type, search_term){
|
|||
|
||||
//msg to python side
|
||||
let msg = {
|
||||
"action": "",
|
||||
"model_type": "",
|
||||
"search_term": "",
|
||||
"action": "open_url",
|
||||
"model_type": model_type,
|
||||
"search_term": search_term,
|
||||
"prompt": "",
|
||||
"neg_prompt": "",
|
||||
}
|
||||
|
||||
|
||||
msg["action"] = "open_url";
|
||||
msg["model_type"] = model_type;
|
||||
msg["search_term"] = search_term;
|
||||
msg["prompt"] = "";
|
||||
msg["neg_prompt"] = "";
|
||||
|
||||
// fill to msg box
|
||||
send_ch_py_msg(msg)
|
||||
|
||||
|
|
@ -203,7 +238,6 @@ async function open_model_url(event, model_type, search_term){
|
|||
|
||||
console.log("end open_model_url");
|
||||
|
||||
|
||||
}
|
||||
|
||||
function add_trigger_words(event, model_type, search_term){
|
||||
|
|
@ -218,17 +252,13 @@ function add_trigger_words(event, model_type, search_term){
|
|||
|
||||
//msg to python side
|
||||
let msg = {
|
||||
"action": "",
|
||||
"model_type": "",
|
||||
"search_term": "",
|
||||
"action": "add_trigger_words",
|
||||
"model_type": model_type,
|
||||
"search_term": search_term,
|
||||
"prompt": "",
|
||||
"neg_prompt": "",
|
||||
}
|
||||
|
||||
msg["action"] = "add_trigger_words";
|
||||
msg["model_type"] = model_type;
|
||||
msg["search_term"] = search_term;
|
||||
msg["neg_prompt"] = "";
|
||||
|
||||
// get active prompt
|
||||
let act_prompt = getActivePrompt();
|
||||
|
|
@ -259,17 +289,13 @@ function use_preview_prompt(event, model_type, search_term){
|
|||
|
||||
//msg to python side
|
||||
let msg = {
|
||||
"action": "",
|
||||
"model_type": "",
|
||||
"search_term": "",
|
||||
"action": "use_preview_prompt",
|
||||
"model_type": model_type,
|
||||
"search_term": search_term,
|
||||
"prompt": "",
|
||||
"neg_prompt": "",
|
||||
}
|
||||
|
||||
msg["action"] = "use_preview_prompt";
|
||||
msg["model_type"] = model_type;
|
||||
msg["search_term"] = search_term;
|
||||
|
||||
// get active prompt
|
||||
let act_prompt = getActivePrompt();
|
||||
msg["prompt"] = act_prompt.value;
|
||||
|
|
@ -310,18 +336,13 @@ async function remove_card(event, model_type, search_term){
|
|||
|
||||
//msg to python side
|
||||
let msg = {
|
||||
"action": "",
|
||||
"model_type": "",
|
||||
"search_term": "",
|
||||
"action": "remove_card",
|
||||
"model_type": model_type,
|
||||
"search_term": search_term,
|
||||
"prompt": "",
|
||||
"neg_prompt": "",
|
||||
}
|
||||
|
||||
|
||||
msg["action"] = "remove_card";
|
||||
msg["model_type"] = model_type;
|
||||
msg["search_term"] = search_term;
|
||||
msg["prompt"] = "";
|
||||
msg["neg_prompt"] = "";
|
||||
|
||||
// fill to msg box
|
||||
send_ch_py_msg(msg)
|
||||
|
||||
|
|
@ -375,6 +396,227 @@ async function remove_card(event, model_type, search_term){
|
|||
}
|
||||
|
||||
|
||||
//button's click function with model_path
|
||||
async function open_model_url_with_path(event, model_type, model_path){
|
||||
console.log("start open_model_url");
|
||||
|
||||
//get hidden components of extension
|
||||
let js_open_url_btn = gradioApp().getElementById("ch_js_open_url_btn");
|
||||
if (!js_open_url_btn) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
//msg to python side
|
||||
let msg = {
|
||||
"action": "open_url",
|
||||
"model_type": model_type,
|
||||
"model_path": model_path,
|
||||
"prompt": "",
|
||||
"neg_prompt": "",
|
||||
}
|
||||
|
||||
// fill to msg box
|
||||
send_ch_py_msg(msg)
|
||||
|
||||
//click hidden button
|
||||
js_open_url_btn.click();
|
||||
|
||||
// stop parent event
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
|
||||
//check response msg from python
|
||||
let new_py_msg = "";
|
||||
try {
|
||||
new_py_msg = await get_new_ch_py_msg();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
console.log("new_py_msg:");
|
||||
console.log(new_py_msg);
|
||||
|
||||
//check msg
|
||||
if (new_py_msg) {
|
||||
let py_msg_json = JSON.parse(new_py_msg);
|
||||
//check for url
|
||||
if (py_msg_json && py_msg_json.content) {
|
||||
if (py_msg_json.content.url) {
|
||||
window.open(py_msg_json.content.url, "_blank");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
console.log("end open_model_url");
|
||||
|
||||
}
|
||||
|
||||
function add_trigger_words_with_path(event, model_type, model_path){
|
||||
console.log("start add_trigger_words");
|
||||
|
||||
//get hidden components of extension
|
||||
let js_add_trigger_words_btn = gradioApp().getElementById("ch_js_add_trigger_words_btn");
|
||||
if (!js_add_trigger_words_btn) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
//msg to python side
|
||||
let msg = {
|
||||
"action": "add_trigger_words",
|
||||
"model_type": model_type,
|
||||
"model_path": model_path,
|
||||
"prompt": "",
|
||||
"neg_prompt": "",
|
||||
}
|
||||
|
||||
|
||||
// get active prompt
|
||||
let act_prompt = getActivePrompt();
|
||||
msg["prompt"] = act_prompt.value;
|
||||
|
||||
// fill to msg box
|
||||
send_ch_py_msg(msg)
|
||||
|
||||
//click hidden button
|
||||
js_add_trigger_words_btn.click();
|
||||
|
||||
console.log("end add_trigger_words");
|
||||
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
|
||||
|
||||
}
|
||||
|
||||
function use_preview_prompt_with_path(event, model_type, model_path){
|
||||
console.log("start use_preview_prompt");
|
||||
|
||||
//get hidden components of extension
|
||||
let js_use_preview_prompt_btn = gradioApp().getElementById("ch_js_use_preview_prompt_btn");
|
||||
if (!js_use_preview_prompt_btn) {
|
||||
return
|
||||
}
|
||||
|
||||
//msg to python side
|
||||
let msg = {
|
||||
"action": "use_preview_prompt",
|
||||
"model_type": model_type,
|
||||
"model_path": model_path,
|
||||
"prompt": "",
|
||||
"neg_prompt": "",
|
||||
}
|
||||
|
||||
// get active prompt
|
||||
let act_prompt = getActivePrompt();
|
||||
msg["prompt"] = act_prompt.value;
|
||||
|
||||
// get active neg prompt
|
||||
let neg_prompt = getActiveNegativePrompt();
|
||||
msg["neg_prompt"] = neg_prompt.value;
|
||||
|
||||
// fill to msg box
|
||||
send_ch_py_msg(msg)
|
||||
|
||||
//click hidden button
|
||||
js_use_preview_prompt_btn.click();
|
||||
|
||||
console.log("end use_preview_prompt");
|
||||
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function remove_card_with_path(event, model_type, model_path){
|
||||
console.log("start remove_card");
|
||||
|
||||
//get hidden components of extension
|
||||
let js_remove_card_btn = gradioApp().getElementById("ch_js_remove_card_btn");
|
||||
if (!js_remove_card_btn) {
|
||||
return
|
||||
}
|
||||
|
||||
// must confirm before removing
|
||||
let rm_confirm = "\nConfirm to remove this model.\n\nCheck console log for detail.";
|
||||
if (!confirm(rm_confirm)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
//msg to python side
|
||||
let msg = {
|
||||
"action": "remove_card",
|
||||
"model_type": model_type,
|
||||
"model_path": model_path,
|
||||
"prompt": "",
|
||||
"neg_prompt": "",
|
||||
}
|
||||
|
||||
// fill to msg box
|
||||
send_ch_py_msg(msg)
|
||||
|
||||
//click hidden button
|
||||
js_remove_card_btn.click();
|
||||
|
||||
// stop parent event
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
|
||||
//check response msg from python
|
||||
let new_py_msg = "";
|
||||
try {
|
||||
new_py_msg = await get_new_ch_py_msg();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
new_py_msg = error;
|
||||
}
|
||||
|
||||
console.log("new_py_msg:");
|
||||
console.log(new_py_msg);
|
||||
|
||||
//check msg
|
||||
let result = "Done";
|
||||
//check msg
|
||||
if (new_py_msg) {
|
||||
result = new_py_msg;
|
||||
}
|
||||
|
||||
// alert result
|
||||
alert(result);
|
||||
|
||||
if (result=="Done"){
|
||||
console.log("refresh card list");
|
||||
//refresh card list
|
||||
let active_tab = getActiveTabType();
|
||||
console.log("get active tab id: " + active_tab);
|
||||
if (active_tab){
|
||||
|
||||
let js_model_type = convertModelTypeFromPyToJS(model_type);
|
||||
if (!js_model_type){return;}
|
||||
|
||||
let refresh_btn_id = active_tab + "_" + js_model_type + "_extra_refresh";
|
||||
let refresh_btn = gradioApp().getElementById(refresh_btn_id);
|
||||
if (refresh_btn){
|
||||
console.log("click button: "+refresh_btn_id);
|
||||
refresh_btn.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("end remove_card");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// download model's new version into SD at python side
|
||||
function ch_dl_model_new_version(event, model_path, version_id, download_url){
|
||||
console.log("start ch_dl_model_new_version");
|
||||
|
|
@ -393,17 +635,12 @@ function ch_dl_model_new_version(event, model_path, version_id, download_url){
|
|||
|
||||
//msg to python side
|
||||
let msg = {
|
||||
"action": "",
|
||||
"model_path": "",
|
||||
"version_id": "",
|
||||
"download_url": "",
|
||||
"action": "dl_model_new_version",
|
||||
"model_path": model_path,
|
||||
"version_id": version_id,
|
||||
"download_url": download_url,
|
||||
}
|
||||
|
||||
msg["action"] = "dl_model_new_version";
|
||||
msg["model_path"] = model_path;
|
||||
msg["version_id"] = version_id;
|
||||
msg["download_url"] = download_url;
|
||||
|
||||
// fill to msg box
|
||||
send_ch_py_msg(msg)
|
||||
|
||||
|
|
@ -421,35 +658,11 @@ function ch_dl_model_new_version(event, model_path, version_id, download_url){
|
|||
|
||||
onUiLoaded(() => {
|
||||
|
||||
//get gradio version
|
||||
let gradio_ver = ch_gradio_version();
|
||||
console.log("gradio_ver:" + gradio_ver);
|
||||
|
||||
// get all extra network tabs
|
||||
let tab_prefix_list = ["txt2img", "img2img"];
|
||||
let model_type_list = ["textual_inversion", "hypernetworks", "checkpoints", "lora"];
|
||||
let cardid_suffix = "cards";
|
||||
|
||||
//get init py msg
|
||||
// let init_py_msg_str = get_ch_py_msg();
|
||||
// let extension_path = "";
|
||||
// if (!init_py_msg_str) {
|
||||
// console.log("Can not get init_py_msg");
|
||||
// } else {
|
||||
// init_py_msg = JSON.parse(init_py_msg_str);
|
||||
// if (init_py_msg) {
|
||||
// extension_path = init_py_msg.extension_path;
|
||||
// console.log("get extension path: " + extension_path);
|
||||
// }
|
||||
// }
|
||||
|
||||
// //icon image node as string
|
||||
// function icon(icon_name){
|
||||
// let icon_path = extension_path+"/icon/"+icon_name;
|
||||
// return ch_img_node_str(icon_path);
|
||||
// }
|
||||
|
||||
|
||||
// update extra network tab pages' cards
|
||||
// * replace "replace preview" text button into an icon
|
||||
// * add 3 button to each card:
|
||||
|
|
@ -654,11 +867,284 @@ onUiLoaded(() => {
|
|||
}
|
||||
|
||||
|
||||
|
||||
// for sd version 1.8.0+
|
||||
// update extra network tab pages' cards
|
||||
// * replace "replace preview" text button into an icon
|
||||
// * add 3 button to each card:
|
||||
// - open model url 🌐
|
||||
// - add trigger words 💡
|
||||
// - use preview image's prompt 🏷️
|
||||
// notice: javascript can not get response from python side
|
||||
// so, these buttons just sent request to python
|
||||
// then, python side gonna open url and update prompt text box, without telling js side.
|
||||
function update_card_for_civitai_with_sd1_8(){
|
||||
|
||||
console.log("start update_card_for_civitai_with_sd1_8");
|
||||
|
||||
//css
|
||||
let btn_margin = "0px 5px";
|
||||
let btn_fontSize = "200%";
|
||||
let btn_thumb_fontSize = "100%";
|
||||
let btn_thumb_display = "inline";
|
||||
let btn_thumb_pos = "static";
|
||||
let btn_thumb_backgroundImage = "none";
|
||||
let btn_thumb_background = "rgba(0, 0, 0, 0.8)";
|
||||
|
||||
let ch_btn_txts = ['🌐', '💡', '🏷️'];
|
||||
let replace_preview_text = getTranslation("replace preview");
|
||||
if (!replace_preview_text) {
|
||||
replace_preview_text = "replace preview";
|
||||
}
|
||||
|
||||
|
||||
//change all "replace preview" into an icon
|
||||
let extra_network_id = "";
|
||||
let extra_network_node = null;
|
||||
let button_row = null;
|
||||
let search_term_node = null;
|
||||
let search_term = "";
|
||||
let model_type = "";
|
||||
let cards = null;
|
||||
let need_to_add_buttons = false;
|
||||
let extra_tabs = null;
|
||||
let extra_tab = null;
|
||||
let active_extra_tab = null;
|
||||
let active_model_type = "";
|
||||
let active_extra_tab_type = "";
|
||||
let card_path = "";
|
||||
|
||||
//get current tab
|
||||
let active_tab_type = getActiveTabType();
|
||||
if (!active_tab_type){active_tab_type = "txt2img";}
|
||||
|
||||
for (const tab_prefix of tab_prefix_list) {
|
||||
if (tab_prefix != active_tab_type) {continue;}
|
||||
|
||||
|
||||
//find out current selected model type tab
|
||||
|
||||
extra_tabs = gradioApp().getElementById(tab_prefix+"_extra_tabs");
|
||||
if (!extra_tabs) {console.log("can not find extra_tabs: " + tab_prefix+"_extra_tabs");}
|
||||
|
||||
//get tab by id
|
||||
for (const js_model_type of model_type_list) {
|
||||
//get tab
|
||||
let extra_tab = gradioApp().getElementById(tab_prefix+"_"+js_model_type);
|
||||
if (extra_tab == null){
|
||||
console.log(`can not get extra_tab: ${tab_prefix}_${js_model_type}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
//check if tab is active
|
||||
if (extra_tab.style.display == "block"){
|
||||
active_extra_tab = extra_tab;
|
||||
active_model_type = js_model_type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
console.log("found active_model_type: " + active_model_type);
|
||||
|
||||
switch (active_model_type) {
|
||||
case "textual_inversion":
|
||||
active_extra_tab_type = "ti";
|
||||
model_type = "ti";
|
||||
break;
|
||||
case "hypernetworks":
|
||||
active_extra_tab_type = "hyper";
|
||||
model_type = "hyper";
|
||||
break;
|
||||
case "checkpoints":
|
||||
active_extra_tab_type = "ckp";
|
||||
model_type = "ckp";
|
||||
break;
|
||||
case "lora":
|
||||
active_extra_tab_type = "lora";
|
||||
model_type = "lora";
|
||||
break;
|
||||
}
|
||||
|
||||
//get model_type for python side
|
||||
if (!model_type) {
|
||||
console.log("can not get model_type with: " + active_model_type);
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log("handle active extra tab");
|
||||
|
||||
|
||||
extra_network_id = tab_prefix+"_"+active_model_type+"_"+cardid_suffix;
|
||||
// console.log("searching extra_network_node: " + extra_network_id);
|
||||
extra_network_node = gradioApp().getElementById(extra_network_id);
|
||||
|
||||
// console.log("find extra_network_node: " + extra_network_id);
|
||||
|
||||
// get all card nodes
|
||||
cards = extra_network_node.querySelectorAll(".card");
|
||||
console.log(`get cards: ${cards.length}`);
|
||||
for (let card of cards) {
|
||||
console.log(`current card: ${card.dataset.name}`);
|
||||
|
||||
//get button row
|
||||
button_row = card.querySelector(".button-row");
|
||||
|
||||
//set button_row's flex-wrap to wrap
|
||||
button_row.style.flexWrap = "wrap";
|
||||
|
||||
if (!button_row){
|
||||
console.log("can not find button_row");
|
||||
continue;
|
||||
}
|
||||
|
||||
let atags = button_row.querySelectorAll("a");
|
||||
if (atags && atags.length) {
|
||||
console.log("find atags: " + atags.length);
|
||||
} else {
|
||||
//console.log("no atags");
|
||||
need_to_add_buttons = true;
|
||||
}
|
||||
|
||||
if (!need_to_add_buttons) {
|
||||
console.log("no need to add buttons");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// search_term node
|
||||
// search_term = subfolder path + model name + ext
|
||||
search_term_node = card.querySelector(".actions .additional .search_terms");
|
||||
if (!search_term_node){
|
||||
console.log("can not find search_term node for cards in " + extra_network_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
// get search_term
|
||||
search_term = search_term_node.innerHTML.trim();
|
||||
if (!search_term) {
|
||||
console.log("search_term is empty for cards in " + extra_network_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
//from sd v1.8, need to replace all single '\' into '\\'
|
||||
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
|
||||
//so we can use this new path and give up search_term
|
||||
console.log("card path: " + card.dataset.sortPath);
|
||||
card_path = card.dataset.sortPath.replaceAll("\\", "\\\\");
|
||||
|
||||
|
||||
|
||||
console.log("adding buttons");
|
||||
// then we need to add 3 buttons to each ul node:
|
||||
let open_url_node = document.createElement("a");
|
||||
open_url_node.href = "#";
|
||||
open_url_node.innerHTML = "🌐";
|
||||
open_url_node.className = "card-button";
|
||||
|
||||
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+"')");
|
||||
|
||||
let add_trigger_words_node = document.createElement("a");
|
||||
add_trigger_words_node.href = "#";
|
||||
add_trigger_words_node.innerHTML = "💡";
|
||||
add_trigger_words_node.className = "card-button";
|
||||
|
||||
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+"')");
|
||||
|
||||
let use_preview_prompt_node = document.createElement("a");
|
||||
use_preview_prompt_node.href = "#";
|
||||
use_preview_prompt_node.innerHTML = "🏷️";
|
||||
use_preview_prompt_node.className = "card-button";
|
||||
|
||||
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+"')");
|
||||
|
||||
let remove_card_node = document.createElement("a");
|
||||
remove_card_node.href = "#";
|
||||
remove_card_node.innerHTML = "❌";
|
||||
remove_card_node.className = "card-button";
|
||||
|
||||
remove_card_node.title = "Remove this model";
|
||||
remove_card_node.setAttribute("onclick","remove_card_with_path(event, '"+model_type+"', '"+card_path+"')");
|
||||
|
||||
//add to card
|
||||
button_row.appendChild(open_url_node);
|
||||
button_row.appendChild(add_trigger_words_node);
|
||||
button_row.appendChild(use_preview_prompt_node);
|
||||
button_row.appendChild(remove_card_node);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
console.log("end update_card_for_civitai_with_sd1_8");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
let tab_id = ""
|
||||
let toolbar_id = "";
|
||||
let refresh_btn_id = "";
|
||||
let refresh_btn = null;
|
||||
let extra_tab = null;
|
||||
let extra_toolbar = null;
|
||||
let extra_network_refresh_btn = null;
|
||||
//add refresh button to extra network's toolbar
|
||||
|
||||
//from sd version 1.8.0, extra network's toolbar is fully rewrited. This extension need to re-write this part too.
|
||||
let sd_version = ch_sd_version();
|
||||
console.log(`sd version is: ${sd_version}`);
|
||||
if (sd_version >= "1.8.0"){
|
||||
|
||||
for (let prefix of tab_prefix_list) {
|
||||
toolbar_id = prefix + "_lora_controls";
|
||||
|
||||
//with sd 1.8.0, each model type has its own extra toolbar.
|
||||
//so here we need to get all toolbars
|
||||
for (const js_model_type of model_type_list) {
|
||||
|
||||
//get toolbar
|
||||
toolbar_id = prefix + "_" + js_model_type + "_controls";
|
||||
|
||||
//get toolbar
|
||||
extra_toolbar = gradioApp().getElementById(toolbar_id);
|
||||
|
||||
//get official refresh button
|
||||
refresh_btn_id = prefix + "_" + js_model_type + "_extra_refresh";
|
||||
refresh_btn = gradioApp().getElementById(refresh_btn_id);
|
||||
if (!refresh_btn) {
|
||||
console.log("can not find refresh_btn with id: " + refresh_btn_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// from sd v1.8.0, we add refresh function to official's refresh button
|
||||
refresh_btn.onclick = function(event){
|
||||
console.log("run refresh button on click");
|
||||
//official's refresh function
|
||||
extraNetworksControlRefreshOnClick(event, prefix, js_model_type);
|
||||
|
||||
update_card_for_civitai_with_sd1_8();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//run it once
|
||||
//update_card_for_civitai_with_sd1_8();
|
||||
|
||||
} else {
|
||||
for (let prefix of tab_prefix_list) {
|
||||
tab_id = prefix + "_extra_tabs";
|
||||
extra_tab = gradioApp().getElementById(tab_id);
|
||||
|
|
@ -685,9 +1171,15 @@ onUiLoaded(() => {
|
|||
|
||||
}
|
||||
|
||||
|
||||
//run it once
|
||||
update_card_for_civitai();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -218,6 +218,22 @@ def load_model_info_by_search_term(model_type, search_term):
|
|||
return model.load_model_info(model_info_filepath)
|
||||
|
||||
|
||||
# get model info file's content by model path
|
||||
# parameter: model_path
|
||||
# return: model_info
|
||||
def load_model_info_by_model_path(model_path):
|
||||
util.printD(f"Load model info of {model_path}")
|
||||
|
||||
# search_term = subfolderpath + model name + ext. And it always start with a / even there is no sub folder
|
||||
base, ext = os.path.splitext(model_path)
|
||||
model_info_filepath = base + suffix + model.info_ext
|
||||
|
||||
if not os.path.isfile(model_info_filepath):
|
||||
util.printD("Can not find model info file: " + model_info_filepath)
|
||||
return
|
||||
|
||||
return model.load_model_info(model_info_filepath)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,9 +25,20 @@ def open_model_url(msg, open_url_with_js):
|
|||
return
|
||||
|
||||
model_type = result["model_type"]
|
||||
search_term = result["search_term"]
|
||||
search_term = ""
|
||||
model_path = ""
|
||||
model_info = None
|
||||
|
||||
if "model_path" in result.keys():
|
||||
model_path = result["model_path"]
|
||||
util.printD(f"Open Url for {model_path}")
|
||||
model_info = civitai.load_model_info_by_model_path(model_path)
|
||||
else:
|
||||
search_term = result["search_term"]
|
||||
util.printD(f"Open Url for {search_term}")
|
||||
model_info = civitai.load_model_info_by_search_term(model_type, search_term)
|
||||
|
||||
|
||||
if not model_info:
|
||||
util.printD(f"Failed to get model info for {model_type} {search_term}")
|
||||
return ""
|
||||
|
|
@ -75,11 +86,20 @@ def add_trigger_words(msg):
|
|||
return
|
||||
|
||||
model_type = result["model_type"]
|
||||
search_term = result["search_term"]
|
||||
search_term = ""
|
||||
model_path = ""
|
||||
prompt = result["prompt"]
|
||||
model_info = None
|
||||
|
||||
|
||||
if "model_path" in result.keys():
|
||||
model_path = result["model_path"]
|
||||
util.printD(f"Add Trigger Words for {model_path}")
|
||||
model_info = civitai.load_model_info_by_model_path(model_path)
|
||||
else:
|
||||
search_term = result["search_term"]
|
||||
util.printD(f"Add Trigger Words for {search_term}")
|
||||
model_info = civitai.load_model_info_by_search_term(model_type, search_term)
|
||||
|
||||
if not model_info:
|
||||
util.printD(f"Failed to get model info for {model_type} {search_term}")
|
||||
return [prompt, prompt]
|
||||
|
|
@ -126,12 +146,21 @@ def use_preview_image_prompt(msg):
|
|||
return
|
||||
|
||||
model_type = result["model_type"]
|
||||
search_term = result["search_term"]
|
||||
search_term = ""
|
||||
model_path = ""
|
||||
prompt = result["prompt"]
|
||||
neg_prompt = result["neg_prompt"]
|
||||
model_info = None
|
||||
|
||||
|
||||
if "model_path" in result.keys():
|
||||
model_path = result["model_path"]
|
||||
util.printD(f"Add Trigger Words for {model_path}")
|
||||
model_info = civitai.load_model_info_by_model_path(model_path)
|
||||
else:
|
||||
search_term = result["search_term"]
|
||||
util.printD(f"Add Trigger Words for {search_term}")
|
||||
model_info = civitai.load_model_info_by_search_term(model_type, search_term)
|
||||
|
||||
if not model_info:
|
||||
util.printD(f"Failed to get model info for {model_type} {search_term}")
|
||||
return [prompt, neg_prompt, prompt, neg_prompt]
|
||||
|
|
@ -269,15 +298,21 @@ def remove_model_by_path(msg):
|
|||
return output
|
||||
|
||||
model_type = result["model_type"]
|
||||
search_term = result["search_term"]
|
||||
search_term = ""
|
||||
model_path = ""
|
||||
|
||||
|
||||
if "model_path" in result.keys():
|
||||
model_path = result["model_path"]
|
||||
else:
|
||||
search_term = result["search_term"]
|
||||
model_path = model.get_model_path_by_search_term(model_type, search_term)
|
||||
|
||||
if not model_path:
|
||||
output = f"Fail to get model for {model_type} {search_term}"
|
||||
util.printD(output)
|
||||
return output
|
||||
|
||||
|
||||
if not os.path.isfile(model_path):
|
||||
output = f"Model {model_type} {search_term} does not exist, no need to remove"
|
||||
util.printD(output)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ py_actions = ("open_url", "remove_card")
|
|||
# return: dict for result
|
||||
def parse_js_msg(msg):
|
||||
util.printD("Start parse js msg")
|
||||
util.printD(f"Msg: {msg}")
|
||||
|
||||
msg_dict = json.loads(msg)
|
||||
|
||||
# in case client side run JSON.stringify twice
|
||||
|
|
|
|||
Loading…
Reference in New Issue