diff --git a/README.md b/README.md index 333abcd..384feab 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,8 @@ Done. # How to Use ## Update Your SD Webui -* v1.6.x works with SD webui version from 2023-03-25 or later, which uses gradio version 3.23.0 -* v1.5.x works with SD webui version from 2023-02-06 - 2023-03-24. - -**Check your SD webui Page's bottom, "gradio" version number** -* If it is v3.23.0 or later, install v1.6.x. -* If it is v3.16.x, install v1.5.7 from [Civitai](https://civitai.com/models/16768/civitai-helper-sd-webui-civitai-extension) - +This extension need to get extra network's cards id. Which is added since **2023-02-06**. +**If your SD webui is an earlier version, you need to update it!** ## Scanning Models Go to extension tab "Civitai Helper". There is a button called "Scan model". diff --git a/javascript/civitai_helper.js b/javascript/civitai_helper.js index b5eb664..2746ff2 100644 --- a/javascript/civitai_helper.js +++ b/javascript/civitai_helper.js @@ -12,6 +12,21 @@ function ch_img_node_str(path){ } +function ch_gradio_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"; + } + +} + // send msg to python side by filling a hidden text box // then will click a button to trigger an action @@ -317,11 +332,14 @@ 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 model_type_label_list = ["Textual Inversion", "Hypernetworks", "Checkpoints", "Lora"]; let cardid_suffix = "cards"; //get init py msg @@ -413,11 +431,20 @@ onUiLoaded(() => { if (!extra_tabs) {console.log("can not find extra_tabs: " + tab_prefix+"_extra_tabs");} //get tab buttons let extra_tab_btns = extra_tabs.firstChild.querySelectorAll("button"); - console.log("find buttons: " + extra_tab_btns.length); + console.log("found buttons: " + extra_tab_btns.length); for (let extra_tab_btn of extra_tab_btns) { console.log(extra_tab_btn.innerHTML); - if (extra_tab_btn.className.indexOf("selected") >= 0) { + + // use different if condition for different gradio version + let condition = false; + if (gradio_ver=="3.23.0") { + condition = (extra_tab_btn.className.indexOf("selected") >= 0); + } else { + condition = (extra_tab_btn.className.indexOf("border-transparent")<0) && model_type_label_list.includes(extra_tab_btn.innerHTML.trim()); + } + + if (condition) { console.log("found active tab: " + extra_tab_btn.innerHTML); switch (extra_tab_btn.innerHTML.trim()) {