From f1dfb34ed12de82edbbb96812cbcf480b7011fb5 Mon Sep 17 00:00:00 2001 From: Dowon Date: Sat, 30 Dec 2023 17:07:41 +0900 Subject: [PATCH] fix: params.txt --- CHANGELOG.md | 1 + scripts/!adetailer.py | 44 +++++++------------------------------------ 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39c6d24..7207ef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - 파일을 인자로 추가하는 몇몇 스크립트에 대해 deepcopy의 에러를 피하기 위해 script_args 복사 방법을 변경함 - skip img2img 기능을 사용할 때 너비, 높이를 128로 고정하여 스킵 과정이 조금 더 나아짐 - img2img inpainting 모드에서 adetailer 자동 비활성화 +- 처음 생성된 params.txt 파일을 항상 유지하도록 변경함 ## 2023-11-19 diff --git a/scripts/!adetailer.py b/scripts/!adetailer.py index f23845c..eb37a7d 100644 --- a/scripts/!adetailer.py +++ b/scripts/!adetailer.py @@ -41,9 +41,8 @@ CNHijackRestore, cn_allow_script_control, ) -from modules import images, safe, script_callbacks, scripts, shared +from modules import images, paths, safe, script_callbacks, scripts, shared from modules.devices import NansException -from modules.paths import data_path, models_path from modules.processing import ( Processed, StableDiffusionProcessingImg2Img, @@ -54,7 +53,7 @@ from modules.shared import cmd_opts, opts, state no_huggingface = getattr(cmd_opts, "ad_no_huggingface", False) -adetailer_dir = Path(models_path, "adetailer") +adetailer_dir = Path(paths.models_path, "adetailer") extra_models_dir = shared.opts.data.get("ad_extra_models_dir", "") model_mapping = get_models( adetailer_dir, extra_dir=extra_models_dir, huggingface=not no_huggingface @@ -105,28 +104,6 @@ def preseve_prompts(p): p.all_negative_prompts = all_ng -@contextmanager -def change_skip_img2img_args(p): - if hasattr(p, "_ad_orig"): - steps = p.steps - sampler_name = p.sampler_name - width = p.width - height = p.height - try: - p.steps = p._ad_orig.steps - p.sampler_name = p._ad_orig.sampler_name - p.width = p._ad_orig.width - p.height = p._ad_orig.height - yield - finally: - p.steps = steps - p.sampler_name = sampler_name - p.width = width - p.height = height - else: - yield - - class AfterDetailerScript(scripts.Script): def __init__(self): super().__init__() @@ -427,18 +404,10 @@ def infotext(p) -> str: p, p.all_prompts, p.all_seeds, p.all_subseeds, None, 0, 0 ) - def write_params_txt(self, p) -> None: - i = self.get_i(p) - lenp = len(p.all_prompts) - if i % lenp != lenp - 1: - return - - with change_skip_img2img_args(p): - infotext = self.infotext(p) - - params_txt = Path(data_path, "params.txt") + def write_params_txt(self, content: str) -> None: + params_txt = Path(paths.data_path, "params.txt") with suppress(Exception): - params_txt.write_text(infotext, encoding="utf-8") + params_txt.write_text(content, encoding="utf-8") @staticmethod def script_args_copy(script_args): @@ -775,6 +744,7 @@ def postprocess_image(self, p, pp, *args_): pp.image = self.ensure_rgb_image(pp.image) init_image = copy(pp.image) arg_list = self.get_args(p, *args_) + params_txt_content = Path(paths.data_path, "params.txt").read_text("utf-8") if self.need_call_postprocess(p): dummy = Processed(p, [], p.seed, "") @@ -800,7 +770,7 @@ def postprocess_image(self, p, pp, *args_): p.scripts.before_process(copy_p) p.scripts.process(copy_p) - self.write_params_txt(p) + self.write_params_txt(params_txt_content) def on_after_component(component, **_kwargs):