mirror of
https://github.com/Bing-su/adetailer.git
synced 2026-04-28 02:01:15 +00:00
style: apply black, fix by ruff
This commit is contained in:
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user