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