From c149363224498709568694cb6b138612751a95d8 Mon Sep 17 00:00:00 2001 From: Connum Date: Tue, 27 Sep 2022 10:09:17 +0200 Subject: [PATCH] force Euler method for the "img2img alternative test" script --- javascript/ui.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/javascript/ui.js b/javascript/ui.js index 7db4db48..4d13b515 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -183,3 +183,40 @@ onUiUpdate(function(){ json_elem.parentElement.style.display="none" }) + +/** + * force Euler method for the "img2img alternative test" script + */ +let prev_sampling_method; +onUiTabChange(function() { + const currentTab = get_uiCurrentTab(); + if ( ! currentTab || currentTab?.textContent.trim() !== 'img2img' ) { + return; + } + + const altScriptName = 'img2img alternative test'; + const scriptSelect = gradioApp().querySelector('#component-223 select'); + const methodRadios = gradioApp().querySelectorAll('[name="radio-component-182"]'); + scriptSelect.addEventListener( 'change', function() { + if( scriptSelect.value === altScriptName) { + prev_sampling_method = gradioApp().querySelector('[name="radio-component-182"]:checked'); + methodRadios.forEach(radio => { + const isEuler = radio.value === 'Euler'; + const label = radio.closest('label'); + radio.disabled = !isEuler; + radio.checked = isEuler; + label.classList[isEuler ? 'remove' : 'add']('!cursor-not-allowed'); + label.title = !isEuler ? `${altScriptName} only works with the Euler method` : ''; + }); + } else { + // reset to previous method + methodRadios.forEach(radio => { + const label = radio.closest('label'); + radio.disabled = false; + radio.checked = radio === prev_sampling_method; + label.classList.remove('!cursor-not-allowed'); + label.title = ''; + }); + } + }); +}) \ No newline at end of file