Fixed Upscaler state

pull/66/head
ilian.iliev 2024-05-03 23:51:35 +03:00
parent 02f52b9dc1
commit e31f6d1fe3
2 changed files with 62 additions and 4 deletions

View File

@ -4,6 +4,7 @@ state = window.state;
state.core = (function () {
const TABS = ['txt2img', 'img2img'];
const ELEMENTS = {
'prompt': 'prompt',
'negative_prompt': 'neg_prompt',
@ -29,6 +30,21 @@ state.core = (function () {
'resize_mode': 'resize_mode',
};
const ELEMENTS_WITH_DUPLICATE_IDS = {
INPUTS: {
'upscaler_2_visibility': 'extras_upscaler_2_visibility',
'upscaler_scale_by_resize': 'extras_upscaling_resize',
'upscaler_scale_by_max_side_length': 'extras_upscale_max_side_length',
'upscaler_scale_to_w': 'extras_upscaling_resize_w',
'upscaler_scale_to_h': 'extras_upscaling_resize_h',
'upscaler_scale_to_crop': 'extras_upscaling_crop',
},
SELECTS: {
'upscaler_1': 'extras_upscaler_1',
'upscaler_2': 'extras_upscaler_2',
}
};
const SELECTS = {
'sampling': 'sampling',
'scheduler': 'scheduler',
@ -105,6 +121,14 @@ state.core = (function () {
handleToggleButton(`${tab}_${element}`);
});
forEachElement(ELEMENTS_WITH_DUPLICATE_IDS.INPUTS, config, (element, tab) => {
handleSavedInput(`${element}`, true);
});
forEachElement(ELEMENTS_WITH_DUPLICATE_IDS.SELECTS, config, (element, tab) => {
handleSavedSelects(`${element}`, true);
});
handleExtensions(config);
handleSettingsPage();
}
@ -213,9 +237,16 @@ state.core = (function () {
return gradioApp().getElementById(id);
}
function handleSavedInput(id) {
function handleSavedInput(id, duplicateIds) {
let elements = null;
if (duplicateIds) {
elements = gradioApp().querySelectorAll(`[id="${id}"] textarea, [id="${id}"] input`);
} else {
elements = gradioApp().querySelectorAll(`#${id} textarea, #${id} input`);
}
const elements = gradioApp().querySelectorAll(`#${id} textarea, #${id} input`);
const events = ['change', 'input'];
if (! elements || ! elements.length) {
@ -264,9 +295,20 @@ state.core = (function () {
});
}
function handleSavedSelects(id) {
function handleSavedSelects(id, duplicateIds) {
if (duplicateIds) {
const elements = gradioApp().querySelectorAll(`[id="${id}"]`);
if (! elements || ! elements.length) {
state.logging.warn(`Select not found: ${id}`);
return;
}
elements.forEach(function (element) {
state.utils.handleSelect(element, id, store);
});
} else {
state.utils.handleSelect(getElement(id), id, store);
}
}
function handleSavedMultiSelects(id) {
const select = gradioApp().getElementById(`${id}`);

View File

@ -40,6 +40,14 @@ def on_ui_settings():
"refiner",
"refiner_checkpoint",
"refiner_switch",
'upscaler_scale_by_resize',
'upscaler_scale_by_max_side_length',
'upscaler_scale_to_w',
'upscaler_scale_to_h',
'upscaler_scale_to_crop',
'upscaler_1',
'upscaler_2',
'upscaler_2_visibility',
"script"
]
}, section=section))
@ -53,6 +61,14 @@ def on_ui_settings():
"refiner",
"refiner_checkpoint",
"refiner_switch",
'upscaler_scale_by_resize',
'upscaler_scale_by_max_side_length',
'upscaler_scale_to_w',
'upscaler_scale_to_h',
'upscaler_scale_to_crop',
'upscaler_1',
'upscaler_2',
'upscaler_2_visibility',
"sampling",
"scheduler",
"resize_mode",