Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ControlNet control mode setting. #746

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions aaaaaa/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any

import gradio as gr
from lib_controlnet.external_code import ControlMode

from aaaaaa.conditional import InputAccordion
from adetailer import ADETAILER, __version__
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"),
)
7 changes: 6 additions & 1 deletion adetailer/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
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 +98,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 +198,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 +262,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 ControlMode, ControlNetUnit

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
Loading