Model switch fallback for older gradio versions

Fixes #149
This commit is contained in:
Dominik Reh
2023-03-28 20:49:09 +02:00
parent 296b9456cc
commit 811d4622e9

View File

@@ -254,6 +254,9 @@ function hideResults(textArea) {
// Function to check activation criteria
function isEnabled() {
if (CFG.activeIn.global) {
// Skip check if the current model was not correctly detected, since it could wrongly disable the script otherwise
if (!currentModelName || !currentModelHash) return true;
let modelList = CFG.activeIn.modelList
.split(",")
.map(x => x.trim())
@@ -822,8 +825,14 @@ async function setup() {
for (const mutation of mutationList) {
if (mutation.type === "attributes" && mutation.attributeName === "title") {
currentModelHash = mutation.target.title;
let modelDropdown = gradioApp().querySelector("#setting_sd_model_checkpoint span.single-select");
currentModelName = modelDropdown?.textContent;
let modelDropdown = gradioApp().querySelector("#setting_sd_model_checkpoint span.single-select")
if (modelDropdown) {
currentModelName = modelDropdown.textContent;
} else {
// Fallback for older versions
modelDropdown = gradioApp().querySelector("#setting_sd_model_checkpoint select");
currentModelName = modelDropdown.value;
}
}
}
});