From 773dd78671d8d2024925f1cd1cc4343cae02d440 Mon Sep 17 00:00:00 2001 From: Bingsu Date: Tue, 2 May 2023 13:04:01 +0900 Subject: [PATCH] feat: Enable ADetailer checkbox --- README.md | 7 +++++++ adetailer/__version__.py | 2 +- install.py | 6 ++++-- scripts/!adetailer.py | 28 ++++++++++++++++++++-------- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index bb95970..4249faa 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,10 @@ On the ControlNet tab, select a ControlNet inpaint model and set the model weigh ![image](https://i.imgur.com/i74ukgi.png) ![image](https://i.imgur.com/I5VVkoh.png) + +## Changelog + +### 2023-05-02 + +- Remove `None` from model list and add `Enable ADetailer` checkbox. +- install.py `skip_install` fix. diff --git a/adetailer/__version__.py b/adetailer/__version__.py index d0064a2..87294f2 100644 --- a/adetailer/__version__.py +++ b/adetailer/__version__.py @@ -1 +1 @@ -__version__ = "23.5.2.post2" +__version__ = "23.5.3" diff --git a/install.py b/install.py index 85aad5d..7139da4 100644 --- a/install.py +++ b/install.py @@ -69,8 +69,10 @@ def install(): try: - from launch import skip_install -except ImportError: + import launch + + skip_install = launch.args.skip_install +except Exception: skip_install = False if not skip_install: diff --git a/scripts/!adetailer.py b/scripts/!adetailer.py index 2b793e9..cadcbe5 100644 --- a/scripts/!adetailer.py +++ b/scripts/!adetailer.py @@ -8,7 +8,7 @@ from pathlib import Path import gradio as gr import torch -import modules +import modules # noqa: F401 from adetailer import __version__, get_models, mediapipe_predict, ultralytics_predict from adetailer.common import dilate_erode, is_all_black, offset from controlnet_ext import ControlNetExt, controlnet_exists, get_cn_inpaint_models @@ -19,7 +19,7 @@ from modules.processing import ( create_infotext, process_images, ) -from modules.shared import cmd_opts, opts, state +from modules.shared import cmd_opts, opts AFTER_DETAILER = "After Detailer" adetailer_dir = Path(models_path, "adetailer") @@ -30,6 +30,7 @@ print( ) ALL_ARGS = [ + ("ad_enable", "ADetailer enable", bool), ("ad_model", "ADetailer model", str), ("ad_prompt", "ADetailer prompt", str), ("ad_negative_prompt", "ADetailer negative prompt", str), @@ -51,6 +52,7 @@ ALL_ARGS = [ class ADetailerArgs: + ad_enable: bool ad_model: str ad_prompt: str ad_negative_prompt: str @@ -123,11 +125,18 @@ class AfterDetailerScript(scripts.Script): return scripts.AlwaysVisible def ui(self, is_img2img): - model_list = ["None"] + list(model_mapping.keys()) + model_list = list(model_mapping.keys()) w = Widgets() with gr.Accordion(AFTER_DETAILER, open=False, elem_id="AD_main_acc"): + with gr.Row(): + w.ad_enable = gr.Checkbox( + label="Enable ADetailer", + value=True, + visible=True, + ) + with gr.Group(): with gr.Row(): w.ad_model = gr.Dropdown( @@ -295,8 +304,11 @@ class AfterDetailerScript(scripts.Script): if not success: print("[-] ADetailer: ControlNetExt init failed.", file=sys.stderr) - def extra_params(self, **kwargs): - params = {name: kwargs[attr] for attr, name, *_ in ALL_ARGS} + def is_ad_enabled(self, args: ADetailerArgs): + return args.ad_enable and args.ad_model != "None" + + def extra_params(self, args: ADetailerArgs): + params = {name: getattr(args, attr) for attr, name, *_ in ALL_ARGS[1:]} params["ADetailer conf"] = int(params["ADetailer conf"] * 100) params["ADetailer version"] = __version__ @@ -467,8 +479,8 @@ class AfterDetailerScript(scripts.Script): def process(self, p, *args_): args = self.get_args(*args_) - if args.ad_model != "None": - extra_params = self.extra_params(**args.asdict()) + if self.is_ad_enabled(args): + extra_params = self.extra_params(args) p.extra_generation_params.update(extra_params) def postprocess_image(self, p, pp, *args_): @@ -477,7 +489,7 @@ class AfterDetailerScript(scripts.Script): args = self.get_args(*args_) - if args.ad_model == "None": + if not self.is_ad_enabled(args): return p._idx = getattr(p, "_idx", -1) + 1