diff --git a/javascript/active.js b/javascript/active.js deleted file mode 100644 index 0e8fcc3..0000000 --- a/javascript/active.js +++ /dev/null @@ -1,68 +0,0 @@ -let dynthres_update_enabled = function() { - return Array.from(arguments); -}; - -(function(){ - let accordions = {}; - let enabled = {}; - onUiUpdate(() => { - let accordion_id_prefix = "#dynthres_"; - let extension_checkbox_class = ".dynthres-enabled"; - - dynthres_update_enabled = function() { - let res = Array.from(arguments); - let tabname = res[1] ? "img2img" : "txt2img"; - - let checkbox = accordions[tabname]?.querySelector(extension_checkbox_class + ' input'); - checkbox?.dispatchEvent(new Event('change')); - - return res; - }; - - function attachEnabledButtonListener(checkbox, accordion) { - let span = accordion.querySelector('.label-wrap span'); - let badge = document.createElement('input'); - badge.type = "checkbox"; - badge.checked = checkbox.checked; - badge.addEventListener('click', (e) => { - checkbox.checked = !checkbox.checked; - badge.checked = checkbox.checked; - checkbox.dispatchEvent(new Event('change')); - e.stopPropagation(); - }); - - badge.className = checkbox.className; - badge.classList.add('primary'); - span.insertBefore(badge, span.firstChild); - let space = document.createElement('span'); - space.innerHTML = " "; - span.insertBefore(space, badge.nextSibling); - - checkbox.addEventListener('change', () => { - let badge = accordion.querySelector('.label-wrap span input'); - badge.checked = checkbox.checked; - }); - checkbox.parentNode.style.display = "none"; - } - - if (Object.keys(accordions).length < 2) { - let accordion = gradioApp().querySelector(accordion_id_prefix + 'txt2img'); - if (accordion) { - accordions.txt2img = accordion; - } - accordion = gradioApp().querySelector(accordion_id_prefix + 'img2img'); - if (accordion) { - accordions.img2img = accordion; - } - } - - if (Object.keys(accordions).length > 0 && accordions.txt2img && !enabled.txt2img) { - enabled.txt2img = accordions.txt2img.querySelector(extension_checkbox_class + ' input'); - attachEnabledButtonListener(enabled.txt2img, accordions.txt2img); - } - if (Object.keys(accordions).length > 0 && accordions.img2img && !enabled.img2img) { - enabled.img2img = accordions.img2img.querySelector(extension_checkbox_class + ' input'); - attachEnabledButtonListener(enabled.img2img, accordions.img2img); - } - }); -})(); diff --git a/scripts/dynamic_thresholding.py b/scripts/dynamic_thresholding.py index a989e17..8fcb8fe 100644 --- a/scripts/dynamic_thresholding.py +++ b/scripts/dynamic_thresholding.py @@ -14,6 +14,7 @@ import torch, traceback import dynthres_core from modules import scripts, script_callbacks, sd_samplers, sd_samplers_compvis, sd_samplers_common +from modules.ui_components import InputAccordion try: import dynthres_unipc except Exception as e: @@ -44,11 +45,7 @@ def ui(self, is_img2img): def vis_change(is_vis): return {"visible": is_vis, "__type__": "update"} # "Dynamic Thresholding (CFG Scale Fix)" - dtrue = gr.Checkbox(value=True, visible=False) - dfalse = gr.Checkbox(value=False, visible=False) - with gr.Accordion("Dynamic Thresholding (CFG Scale Fix)", open=False, elem_id="dynthres_" + ("img2img" if is_img2img else "txt2img")): - with gr.Row(): - enabled = gr.Checkbox(value=False, label="Enable Dynamic Thresholding (CFG Scale Fix)", elem_classes=["dynthres-enabled"], elem_id='dynthres_enabled') + with InputAccordion(label="Dynamic Thresholding (CFG Scale Fix)", value=False, elem_id="dynthres_" + ("img2img" if is_img2img else "txt2img")) as enabled: with gr.Group(): gr.HTML(value=f"View the wiki for usage tips.

", elem_id='dynthres_wiki_link') mimic_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.5, label='Mimic CFG Scale', value=7.0, elem_id='dynthres_mimic_scale') @@ -71,13 +68,8 @@ def should_show_scheduler_value(cfg_mode, mimic_mode): return vis_change(sched_vis), vis_change(mimic_mode != "Constant" or DISABLE_VISIBILITY), vis_change(cfg_mode != "Constant" or DISABLE_VISIBILITY) cfg_mode.change(should_show_scheduler_value, inputs=[cfg_mode, mimic_mode], outputs=[sched_val, mimic_scale_min, cfg_scale_min]) mimic_mode.change(should_show_scheduler_value, inputs=[cfg_mode, mimic_mode], outputs=[sched_val, mimic_scale_min, cfg_scale_min]) - enabled.change( - _js="dynthres_update_enabled", - fn=None, - inputs=[enabled, dtrue if is_img2img else dfalse], - show_progress = False) self.infotext_fields = ( - (enabled, lambda d: gr.Checkbox.update(value="Dynamic thresholding enabled" in d)), + (enabled, lambda d: gr.update(value="Dynamic thresholding enabled" in d)), (mimic_scale, "Mimic scale"), (separate_feature_channels, "Separate Feature Channels"), (scaling_startpoint, lambda d: gr.Radio.update(value=d.get("Scaling Startpoint", "MEAN"))),