Skip to content

Commit

Permalink
Add ControlNet control mode setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
ComplexRobot committed Dec 2, 2024
1 parent 358d170 commit bcf545a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions aaaaaa/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from adetailer import ADETAILER, __version__
from adetailer.args import ALL_ARGS, MASK_MERGE_INVERT
from controlnet_ext import controlnet_exists, controlnet_type, get_cn_models
from lib_controlnet.external_code import ControlMode

if controlnet_type == "forge":
from lib_controlnet import global_state
Expand Down Expand Up @@ -718,3 +719,12 @@ def controlnet(w: Widgets, n: int, is_img2img: bool):
interactive=controlnet_exists,
elem_id=eid("ad_controlnet_guidance_end"),
)

w.ad_controlnet_control_mode = gr.Radio(
choices=[e.value for e in ControlMode],
value=ControlMode.BALANCED.value,
label="ControlNet control mode" + suffix(n),
visible=True,
interactive=controlnet_exists,
elem_id=eid("ad_controlnet_control_mode"),
)
6 changes: 5 additions & 1 deletion adetailer/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from dataclasses import dataclass
from enum import Enum
from functools import cached_property, partial
from typing import Any, Literal, NamedTuple, Optional
from typing import Any, Literal, NamedTuple, Optional, Union
from lib_controlnet.external_code import ControlMode

try:
from pydantic.v1 import (
Expand Down Expand Up @@ -96,6 +97,7 @@ class ADetailerArgs(BaseModel, extra=Extra.forbid):
ad_controlnet_weight: confloat(ge=0.0, le=1.0) = 1.0
ad_controlnet_guidance_start: confloat(ge=0.0, le=1.0) = 0.0
ad_controlnet_guidance_end: confloat(ge=0.0, le=1.0) = 1.0
ad_controlnet_control_mode: Union[ControlMode, int, str] = ControlMode.BALANCED
is_api: bool = True

@validator("is_api", pre=True)
Expand Down Expand Up @@ -195,6 +197,7 @@ def extra_params(self, suffix: str = "") -> dict[str, Any]:
"ADetailer ControlNet weight",
"ADetailer ControlNet guidance start",
"ADetailer ControlNet guidance end",
"ADetailer ControlNet control mode",
],
cond="None",
)
Expand Down Expand Up @@ -258,6 +261,7 @@ def need_skip(self) -> bool:
("ad_controlnet_weight", "ADetailer ControlNet weight"),
("ad_controlnet_guidance_start", "ADetailer ControlNet guidance start"),
("ad_controlnet_guidance_end", "ADetailer ControlNet guidance end"),
("ad_controlnet_control_mode", "ADetailer ControlNet control mode"),
]

_args = [Arg(*args) for args in _all_args]
Expand Down
4 changes: 3 additions & 1 deletion controlnet_ext/controlnet_ext_forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np
from lib_controlnet import external_code, global_state
from lib_controlnet.external_code import ControlNetUnit
from lib_controlnet.external_code import ControlNetUnit, ControlMode

from modules import scripts
from modules.processing import StableDiffusionProcessing
Expand Down Expand Up @@ -53,6 +53,7 @@ def update_scripts_args( # noqa: PLR0913
weight: float,
guidance_start: float,
guidance_end: float,
control_mode: ControlMode,
):
if (not self.cn_available) or model == "None":
return
Expand Down Expand Up @@ -81,6 +82,7 @@ def update_scripts_args( # noqa: PLR0913
weight=weight,
guidance_start=guidance_start,
guidance_end=guidance_end,
control_mode=control_mode,
processor_res=pres,
)
],
Expand Down
1 change: 1 addition & 0 deletions scripts/!adetailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def update_controlnet_args(self, p, args: ADetailerArgs) -> None:
weight=args.ad_controlnet_weight,
guidance_start=args.ad_controlnet_guidance_start,
guidance_end=args.ad_controlnet_guidance_end,
control_mode=args.ad_controlnet_control_mode
)

def is_ad_enabled(self, *args) -> bool:
Expand Down

0 comments on commit bcf545a

Please sign in to comment.