Skip to content

Commit

Permalink
fix: disable when inpaint with skip img2img
Browse files Browse the repository at this point in the history
bug!
  • Loading branch information
Bing-su committed Mar 21, 2024
1 parent 9c6d982 commit f185f60
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions scripts/!adetailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def is_ad_enabled(self, *args_) -> bool:
not_none = any(arg.get("ad_model", "None") != "None" for arg in arg_list)
return ad_enabled and not_none

def check_skip_img2img(self, p, *args_) -> None:
def set_skip_img2img(self, p, *args_) -> None:
if (
hasattr(p, "_ad_skip_img2img")
or not hasattr(p, "init_images")
Expand All @@ -211,20 +211,29 @@ def check_skip_img2img(self, p, *args_) -> None:

if len(args_) >= 2 and isinstance(args_[1], bool):
p._ad_skip_img2img = args_[1]
if args_[1]:
p._ad_orig = SkipImg2ImgOrig(
steps=p.steps,
sampler_name=p.sampler_name,
width=p.width,
height=p.height,
)
p.steps = 1
p.sampler_name = "Euler"
p.width = 128
p.height = 128
else:
p._ad_skip_img2img = False

if not p._ad_skip_img2img:
return

if self.is_img2img_inpaint(p):
p._ad_disabled = True
msg = "[-] ADetailer: img2img inpainting with skip img2img is not supported. (because it's buggy)"
print(msg)
return

p._ad_orig = SkipImg2ImgOrig(
steps=p.steps,
sampler_name=p.sampler_name,
width=p.width,
height=p.height,
)
p.steps = 1
p.sampler_name = "Euler"
p.width = 128
p.height = 128

@staticmethod
def get_i(p) -> int:
it = p.iteration
Expand Down Expand Up @@ -672,21 +681,26 @@ def process(self, p, *args_):
print(msg)
return

if self.is_ad_enabled(*args_):
arg_list = self.get_args(p, *args_)
self.check_skip_img2img(p, *args_)
if not self.is_ad_enabled(*args_):
p._ad_disabled = True
return

self.set_skip_img2img(p, *args_)
if getattr(p, "_ad_disabled", False):
# case when img2img inpainting with skip img2img
return

if hasattr(p, "_ad_xyz_prompt_sr"):
replaced_positive_prompt, replaced_negative_prompt = self.get_prompt(
p, arg_list[0]
)
arg_list[0].ad_prompt = replaced_positive_prompt[0]
arg_list[0].ad_negative_prompt = replaced_negative_prompt[0]
arg_list = self.get_args(p, *args_)

extra_params = self.extra_params(arg_list)
p.extra_generation_params.update(extra_params)
else:
p._ad_disabled = True
if hasattr(p, "_ad_xyz_prompt_sr"):
replaced_positive_prompt, replaced_negative_prompt = self.get_prompt(
p, arg_list[0]
)
arg_list[0].ad_prompt = replaced_positive_prompt[0]
arg_list[0].ad_negative_prompt = replaced_negative_prompt[0]

extra_params = self.extra_params(arg_list)
p.extra_generation_params.update(extra_params)

def _postprocess_image_inner(
self, p, pp, args: ADetailerArgs, *, n: int = 0
Expand Down

0 comments on commit f185f60

Please sign in to comment.