Skip to content

Commit

Permalink
fix: params.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing-su committed Dec 30, 2023
1 parent 1d40c6a commit f1dfb34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- 파일을 인자로 추가하는 몇몇 스크립트에 대해 deepcopy의 에러를 피하기 위해 script_args 복사 방법을 변경함
- skip img2img 기능을 사용할 때 너비, 높이를 128로 고정하여 스킵 과정이 조금 더 나아짐
- img2img inpainting 모드에서 adetailer 자동 비활성화
- 처음 생성된 params.txt 파일을 항상 유지하도록 변경함

## 2023-11-19

Expand Down
44 changes: 7 additions & 37 deletions scripts/!adetailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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__()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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, "")
Expand All @@ -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):
Expand Down

0 comments on commit f1dfb34

Please sign in to comment.