From f90c0b875be5fff80108b9b73931f71f0172e8e0 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Tue, 14 May 2024 15:04:45 +0900 Subject: [PATCH 1/6] git ignore __pycache__ --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ From 3bb43896426f282742e951b28aac9bf5da0e725b Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Tue, 14 May 2024 18:59:58 +0900 Subject: [PATCH 2/6] remove unnecessary install script --- install.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 install.py diff --git a/install.py b/install.py deleted file mode 100644 index 778c8fd..0000000 --- a/install.py +++ /dev/null @@ -1,9 +0,0 @@ -import launch - -if not launch.is_installed("numpy"): - launch.run_pip("install numpy") - print("Installing numpy...") - -if not launch.is_installed("matplotlib"): - launch.run_pip("install matplotlib") - print("Installing matplotlib...") \ No newline at end of file From e85e0ab49d5f3e6d6be7edfca447036f4d0a0504 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Tue, 14 May 2024 16:20:14 +0900 Subject: [PATCH 3/6] remove unused Imports --- scripts/detail_daemon.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/detail_daemon.py b/scripts/detail_daemon.py index 1423cb3..cda3b93 100644 --- a/scripts/detail_daemon.py +++ b/scripts/detail_daemon.py @@ -1,8 +1,6 @@ import os import gradio as gr import numpy as np -import torch -import math from tqdm import tqdm import matplotlib From fbb3f4e74991e82cbf4cefdcf95b7160851016c0 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Tue, 14 May 2024 15:13:57 +0900 Subject: [PATCH 4/6] switch to InputAccordion --- scripts/detail_daemon.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/scripts/detail_daemon.py b/scripts/detail_daemon.py index cda3b93..dda5fb4 100644 --- a/scripts/detail_daemon.py +++ b/scripts/detail_daemon.py @@ -9,6 +9,7 @@ import matplotlib.pyplot as plt import modules.scripts as scripts from modules.script_callbacks import on_cfg_denoiser, remove_current_script_callbacks +from modules.ui_components import InputAccordion class Script(scripts.Script): @@ -20,9 +21,8 @@ class Script(scripts.Script): return scripts.AlwaysVisible def ui(self, is_img2img): - with gr.Accordion("Detail Daemon", elem_id="detail-daemon", open=True): - gr_enabled = gr.Checkbox(label='Enable', elem_id="detail-daemon-enabled", value=False, min_width=0) - with gr.Row(): + with InputAccordion(False, label="Detail Daemon", elem_id=self.elem_id('detail-daemon')) as gr_enabled: + with gr.Row(): with gr.Column(scale=2): gr_amount = gr.Slider(minimum=-1.00, maximum=1.00, step=.01, value=0.50, label="Amount ") gr_start = gr.Slider(minimum=0.0, maximum=1.0, step=.01, value=0.0, label="Start ") @@ -46,22 +46,10 @@ class Script(scripts.Script): vis_args = [gr_enabled, gr_start, gr_end, gr_bias, gr_amount, gr_exponent, gr_start_offset, gr_end_offset, gr_fade, gr_smooth] for vis_arg in vis_args: - if isinstance(vis_arg, gr.components.Slider): vis_arg.release(fn=self.visualize, show_progress=False, inputs=vis_args, outputs=[z_vis]) - else: vis_arg.change(fn=self.visualize, show_progress=False, inputs=vis_args, outputs=[z_vis]) - - js=""" - function toggleClass(x) { - var element = document.getElementById('detail-daemon'); - if (x) { - element.classList.add('dd-active'); - element.classList.remove('dd-inactive'); - } else { - element.classList.add('dd-inactive'); - element.classList.remove('dd-active'); - } - } - """ - gr_enabled.change(None, show_progress=False, inputs=gr_enabled, _js=js) + if isinstance(vis_arg, gr.components.Slider): + vis_arg.release(fn=self.visualize, show_progress=False, inputs=vis_args, outputs=[z_vis]) + else: + vis_arg.change(fn=self.visualize, show_progress=False, inputs=vis_args, outputs=[z_vis]) self.infotext_fields = [ (gr_enabled, lambda d: gr.Checkbox.update(value='DD_enabled' in d)), From 0fa632198ee84380ef29f3112f90f3cf9de28ab4 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Tue, 14 May 2024 16:19:28 +0900 Subject: [PATCH 5/6] use class for css remove unused rules CSS --- scripts/detail_daemon.py | 8 ++++---- style.css | 28 +++++++--------------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/scripts/detail_daemon.py b/scripts/detail_daemon.py index dda5fb4..ed750ed 100644 --- a/scripts/detail_daemon.py +++ b/scripts/detail_daemon.py @@ -30,8 +30,8 @@ class Script(scripts.Script): gr_bias = gr.Slider(minimum=0.0, maximum=1.0, step=.01, value=0.5, label="Bias ") with gr.Column(scale=1, min_width=275): preview = self.visualize(False, 0, 1, 0.5, 0.5, 1, 0, 0, 0, True) - z_vis = gr.Plot(value=preview, elem_id='detail-daemon-vis', show_label=False) - with gr.Accordion("More Knobs:", elem_id="detail-daemon-more-accordion", open=False): + z_vis = gr.Plot(value=preview, elem_classes=['detail-daemon-vis'], show_label=False) + with gr.Accordion("More Knobs:", elem_classes=['detail-daemon-more-accordion'], open=False): with gr.Row(): with gr.Column(scale=2): with gr.Row(): @@ -41,8 +41,8 @@ class Script(scripts.Script): gr_exponent = gr.Slider(minimum=0.0, maximum=10.0, step=.05, value=1.0, label="Exponent", min_width=0) gr_fade = gr.Slider(minimum=0.0, maximum=1.0, step=.05, value=0.0, label="Fade") with gr.Column(scale=1, min_width=275): - gr_smooth = gr.Checkbox(label="Smooth", value=True, min_width=0) - gr_help = gr.Markdown("## [Ⓗ Help](https://github.com/muerrilla/sd-webui-detail-daemon)", elem_id="detail-daemon-help") + gr_smooth = gr.Checkbox(label="Smooth", value=True, min_width=0, elem_classes=['detail-daemon-smooth']) + gr.Markdown("## [Ⓗ Help](https://github.com/muerrilla/sd-webui-detail-daemon)", elem_classes=['detail-daemon-help']) vis_args = [gr_enabled, gr_start, gr_end, gr_bias, gr_amount, gr_exponent, gr_start_offset, gr_end_offset, gr_fade, gr_smooth] for vis_arg in vis_args: diff --git a/style.css b/style.css index 75c8daa..93cf03d 100644 --- a/style.css +++ b/style.css @@ -1,30 +1,16 @@ -#detail-daemon-more-accordion { +.detail-daemon-more-accordion { box-shadow: 0px 1px 6px 2px #00000024 !important; - margin-top: 1em; + margin-top: 1em !important; } -#detail-daemon-more-accordion input[type="checkbox"]{ - margin-left: 3em; +.detail-daemon-smooth { + margin-left: 3em !important; } -#detail-daemon-vis { - margin: auto; +.detail-daemon-vis { + margin: auto !important; } -#detail-daemon-enabled { - margin-bottom: 0.75em; -} - -#detail-daemon-help { +.detail-daemon-help { margin: auto 1.5em !important; } - -#detail-daemon.dd-inactive > div > span { - color: unset; -} - -#detail-daemon.dd-active > div > span { - /*color: #79c700;*/ - /*color: #ffba00;*/ - color: #ff5500; -} \ No newline at end of file From ae7dcf78615d1b49951de4a4323cba220a5cbee0 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Tue, 14 May 2024 17:14:03 +0900 Subject: [PATCH 6/6] compact infotext with backwards compatibility --- scripts/detail_daemon.py | 60 +++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/scripts/detail_daemon.py b/scripts/detail_daemon.py index ed750ed..d41942c 100644 --- a/scripts/detail_daemon.py +++ b/scripts/detail_daemon.py @@ -8,10 +8,24 @@ matplotlib.use('Agg') import matplotlib.pyplot as plt import modules.scripts as scripts -from modules.script_callbacks import on_cfg_denoiser, remove_current_script_callbacks +from modules.script_callbacks import on_cfg_denoiser, remove_current_script_callbacks, on_infotext_pasted from modules.ui_components import InputAccordion +def pares_infotext(infotext, params): + try: + d = {} + for s in params['Detail Daemon'].split(','): + k, _, v = s.partition(':') + d[k.strip()] = v.strip() + params['Detail Daemon'] = d + except Exception: + pass + + +on_infotext_pasted(pares_infotext) + + class Script(scripts.Script): def title(self): @@ -51,22 +65,23 @@ class Script(scripts.Script): else: vis_arg.change(fn=self.visualize, show_progress=False, inputs=vis_args, outputs=[z_vis]) - self.infotext_fields = [ - (gr_enabled, lambda d: gr.Checkbox.update(value='DD_enabled' in d)), - (gr_amount, 'DD_amount'), - (gr_start, 'DD_start'), - (gr_end, 'DD_end'), - (gr_bias, 'DD_bias'), - (gr_exponent, 'DD_exponent'), - (gr_start_offset, 'DD_start_offset'), - (gr_end_offset, 'DD_end_offset'), - (gr_fade, 'DD_fade'), - (gr_smooth, 'DD_smooth'), - ] - self.paste_field_names = [] - for _, field_name in self.infotext_fields: - self.paste_field_names.append(field_name) + def extract_infotext(d: dict, key, old_key): + if 'Detail Daemon' in d: + return d['Detail Daemon'].get(key) + return d.get(old_key) + self.infotext_fields = [ + (gr_enabled, lambda d: True if ('Detail Daemon' in d or 'DD_enabled' in d) else False), + (gr_amount, lambda d: extract_infotext(d, 'amount', 'DD_amount')), + (gr_start, lambda d: extract_infotext(d, 'st', 'DD_start')), + (gr_end, lambda d: extract_infotext(d, 'ed', 'DD_end')), + (gr_bias, lambda d: extract_infotext(d, 'bias', 'DD_bias')), + (gr_exponent, lambda d: extract_infotext(d, 'exp', 'DD_exponent')), + (gr_start_offset, lambda d: extract_infotext(d, 'st_offset', 'DD_start_offset')), + (gr_end_offset, lambda d: extract_infotext(d, 'ed_offset', 'DD_end_offset')), + (gr_fade, lambda d: extract_infotext(d, 'fade', 'DD_fade')), + (gr_smooth, lambda d: extract_infotext(d, 'smooth', 'DD_smooth')), + ] return [gr_enabled, gr_start, gr_end, gr_bias, gr_amount, gr_exponent, gr_start_offset, gr_end_offset, gr_fade, gr_smooth] def process(self, p, enabled, start, end, bias, amount, exponent, start_offset, end_offset, fade, smooth): @@ -88,19 +103,8 @@ class Script(scripts.Script): self.schedule = self.make_schedule(p.steps, start, end, bias, amount, exponent, start_offset, end_offset, fade, smooth) on_cfg_denoiser(self.denoiser_callback) tqdm.write('\033[32mINFO:\033[0m Detail Daemon is enabled') + p.extra_generation_params['Detail Daemon'] = f'amount:{amount},st:{start},ed:{end},bias:{bias},exp:{exponent},st_offset:{start_offset},ed_offset:{end_offset},fade:{fade},smooth:{1 if smooth else 0}' - p.extra_generation_params.update({ - "DD_enabled" : enabled, - "DD_amount" : amount, - "DD_start" : start, - "DD_end" : end, - "DD_bias" : bias, - "DD_exponent" : exponent, - "DD_start_offset" : start_offset, - "DD_end_offset" : end_offset, - "DD_fade" : fade, - "DD_smooth" : smooth, - }) else: if hasattr(self, 'callback_added'): remove_current_script_callbacks()