mirror of
https://github.com/Bing-su/adetailer.git
synced 2026-03-12 17:00:04 +00:00
style: apply black, fix by ruff
This commit is contained in:
@@ -13,13 +13,14 @@ from controlnet_ext import controlnet_exists, controlnet_forge, get_cn_models
|
||||
|
||||
if controlnet_forge:
|
||||
from lib_controlnet import global_state
|
||||
|
||||
cn_module_choices = {
|
||||
"inpaint": list(m for m in global_state.get_filtered_preprocessors("Inpaint")),
|
||||
"lineart": list(m for m in global_state.get_filtered_preprocessors("Lineart")),
|
||||
"openpose": list(m for m in global_state.get_filtered_preprocessors("OpenPose")),
|
||||
"tile": list(m for m in global_state.get_filtered_preprocessors("Tile")),
|
||||
"scribble": list(m for m in global_state.get_filtered_preprocessors("Scribble")),
|
||||
"depth": list(m for m in global_state.get_filtered_preprocessors("Depth")),
|
||||
"inpaint": list(global_state.get_filtered_preprocessors("Inpaint")),
|
||||
"lineart": list(global_state.get_filtered_preprocessors("Lineart")),
|
||||
"openpose": list(global_state.get_filtered_preprocessors("OpenPose")),
|
||||
"tile": list(global_state.get_filtered_preprocessors("Tile")),
|
||||
"scribble": list(global_state.get_filtered_preprocessors("Scribble")),
|
||||
"depth": list(global_state.get_filtered_preprocessors("Depth")),
|
||||
}
|
||||
else:
|
||||
cn_module_choices = {
|
||||
|
||||
@@ -8,7 +8,7 @@ from textwrap import dedent
|
||||
|
||||
from modules import extensions, sd_models, shared
|
||||
|
||||
from .common import cn_model_regex
|
||||
from .common import cn_model_module, cn_model_regex
|
||||
|
||||
try:
|
||||
from modules.paths import extensions_builtin_dir, extensions_dir, models_path
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
from lib_controlnet import external_code, global_state
|
||||
@@ -15,13 +14,18 @@ from .common import cn_model_regex
|
||||
controlnet_exists = True
|
||||
controlnet_forge = True
|
||||
|
||||
def find_script(p : StableDiffusionProcessing, script_title : str) -> scripts.Script:
|
||||
script = next((s for s in p.scripts.scripts if s.title() == script_title ), None)
|
||||
|
||||
def find_script(p: StableDiffusionProcessing, script_title: str) -> scripts.Script:
|
||||
script = next((s for s in p.scripts.scripts if s.title() == script_title), None)
|
||||
if not script:
|
||||
raise Exception("Script not found: " + script_title)
|
||||
msg = f"Script not found: {script_title!r}"
|
||||
raise RuntimeError(msg)
|
||||
return script
|
||||
|
||||
def add_forge_script_to_adetailer_run(p: StableDiffusionProcessing, script_title : str, script_args : list):
|
||||
|
||||
def add_forge_script_to_adetailer_run(
|
||||
p: StableDiffusionProcessing, script_title: str, script_args: list
|
||||
):
|
||||
p.scripts = copy.copy(scripts.scripts_img2img)
|
||||
p.scripts.alwayson_scripts = []
|
||||
p.script_args_value = []
|
||||
@@ -32,6 +36,7 @@ def add_forge_script_to_adetailer_run(p: StableDiffusionProcessing, script_title
|
||||
p.scripts.alwayson_scripts.append(script)
|
||||
p.script_args_value.extend(script_args)
|
||||
|
||||
|
||||
class ControlNetExt:
|
||||
def __init__(self):
|
||||
self.cn_available = False
|
||||
@@ -52,41 +57,35 @@ class ControlNetExt:
|
||||
if (not self.cn_available) or model == "None":
|
||||
return
|
||||
|
||||
if controlnet_forge:
|
||||
image = np.asarray(p.init_images[0])
|
||||
mask = np.zeros_like(image)
|
||||
mask[:] = 255
|
||||
image = np.asarray(p.init_images[0])
|
||||
mask = np.zeros_like(image)
|
||||
mask[:] = 255
|
||||
|
||||
cnet_image = {
|
||||
"image": image,
|
||||
"mask": mask
|
||||
}
|
||||
cnet_image = {"image": image, "mask": mask}
|
||||
|
||||
pres = external_code.pixel_perfect_resolution(
|
||||
image,
|
||||
target_H=p.height,
|
||||
target_W=p.width,
|
||||
resize_mode=external_code.resize_mode_from_value(p.resize_mode)
|
||||
)
|
||||
pres = external_code.pixel_perfect_resolution(
|
||||
image,
|
||||
target_H=p.height,
|
||||
target_W=p.width,
|
||||
resize_mode=external_code.resize_mode_from_value(p.resize_mode),
|
||||
)
|
||||
|
||||
add_forge_script_to_adetailer_run(
|
||||
p,
|
||||
"ControlNet",
|
||||
[
|
||||
ControlNetUnit(
|
||||
enabled=True,
|
||||
image=cnet_image,
|
||||
model=model,
|
||||
module=module,
|
||||
weight=weight,
|
||||
guidance_start=guidance_start,
|
||||
guidance_end=guidance_end,
|
||||
processor_res=pres
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
return
|
||||
add_forge_script_to_adetailer_run(
|
||||
p,
|
||||
"ControlNet",
|
||||
[
|
||||
ControlNetUnit(
|
||||
enabled=True,
|
||||
image=cnet_image,
|
||||
model=model,
|
||||
module=module,
|
||||
weight=weight,
|
||||
guidance_start=guidance_start,
|
||||
guidance_end=guidance_end,
|
||||
processor_res=pres,
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def get_cn_models() -> list[str]:
|
||||
|
||||
@@ -667,7 +667,7 @@ class AfterDetailerScript(scripts.Script):
|
||||
else:
|
||||
p._ad_disabled = True
|
||||
|
||||
def _postprocess_image_inner(
|
||||
def _postprocess_image_inner( # noqa: C901
|
||||
self, p, pp, args: ADetailerArgs, *, n: int = 0
|
||||
) -> bool:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user