mirror of
https://github.com/Bing-su/adetailer.git
synced 2026-01-26 19:29:54 +00:00
feat: xyz grid
This commit is contained in:
@@ -1 +1 @@
|
||||
__version__ = "23.6.1.post0"
|
||||
__version__ = "23.6.2.dev0"
|
||||
|
||||
@@ -7,6 +7,7 @@ import sys
|
||||
import traceback
|
||||
from contextlib import contextmanager, suppress
|
||||
from copy import copy, deepcopy
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
from typing import Any
|
||||
@@ -26,7 +27,7 @@ from adetailer.args import ALL_ARGS, BBOX_SORTBY, ADetailerArgs, EnableChecker
|
||||
from adetailer.common import PredictOutput
|
||||
from adetailer.mask import filter_by_ratio, mask_preprocess, sort_bboxes
|
||||
from adetailer.ui import adui, ordinal, suffix
|
||||
from controlnet_ext import ControlNetExt, controlnet_exists
|
||||
from controlnet_ext import ControlNetExt, controlnet_exists, get_cn_models
|
||||
from controlnet_ext.restore import (
|
||||
CNHijackRestore,
|
||||
cn_allow_script_control,
|
||||
@@ -630,5 +631,87 @@ def on_ui_settings():
|
||||
)
|
||||
|
||||
|
||||
# xyz_grid
|
||||
|
||||
|
||||
def make_axis_on_xyz_grid():
|
||||
xyz_grid = None
|
||||
for script in scripts.scripts_data:
|
||||
if script.script_class.__module__ == "xyz_grid.py":
|
||||
xyz_grid = script.module
|
||||
break
|
||||
|
||||
if xyz_grid is None:
|
||||
return
|
||||
|
||||
model_list = ["None"] + list(model_mapping.keys())
|
||||
|
||||
def set_value(p, x, xs, *, field: str):
|
||||
if not hasattr(p, "adetailer_xyz"):
|
||||
p.adetailer_xyz = {}
|
||||
p.adetailer_xyz[field] = x
|
||||
|
||||
axis = [
|
||||
xyz_grid.AxisOption(
|
||||
"[ADetailer] ADetailer model 1st",
|
||||
str,
|
||||
partial(set_value, field="ad_model"),
|
||||
choices=lambda: model_list,
|
||||
),
|
||||
xyz_grid.AxisOption(
|
||||
"[ADetailer] ADetailer prompt 1st",
|
||||
str,
|
||||
partial(set_value, field="ad_prompt"),
|
||||
),
|
||||
xyz_grid.AxisOption(
|
||||
"[ADetailer] ADetailer negative prompt 1st",
|
||||
str,
|
||||
partial(set_value, field="ad_prompt"),
|
||||
),
|
||||
xyz_grid.AxisOption(
|
||||
"[ADetailer] Mask erosion / dilation 1st",
|
||||
float,
|
||||
partial(set_value, field="ad_dilate_erode"),
|
||||
),
|
||||
xyz_grid.AxisOption(
|
||||
"[ADetailer] Inpaint denoising strength 1st",
|
||||
float,
|
||||
partial(set_value, field="ad_denoising_strength"),
|
||||
),
|
||||
xyz_grid.AxisOption(
|
||||
"[ADetailer] Inpaint only masked 1st",
|
||||
bool,
|
||||
partial(set_value, field="ad_inpaint_only_masked"),
|
||||
choices=lambda: ["True", "False"],
|
||||
),
|
||||
xyz_grid.AxisOption(
|
||||
"[ADetailer] Inpaint only masked padding 1st",
|
||||
int,
|
||||
partial(set_value, field="ad_inpaint_only_masked_padding"),
|
||||
),
|
||||
xyz_grid.AxisOption(
|
||||
"[ADetailer] ControlNet model 1st",
|
||||
int,
|
||||
partial(set_value, field="ad_controlnet_model"),
|
||||
choices=lambda: ["None"] + get_cn_models(),
|
||||
),
|
||||
]
|
||||
|
||||
if not any(x.label.startswith("[ADetailer]") for x in xyz_grid.axis_options):
|
||||
xyz_grid.axis_options.extend(axis)
|
||||
|
||||
|
||||
def on_before_ui():
|
||||
try:
|
||||
make_axis_on_xyz_grid()
|
||||
except Exception:
|
||||
error = traceback.format_exc()
|
||||
print(
|
||||
f"[-] ADetailer: xyz_grid error:\n{error}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
|
||||
script_callbacks.on_ui_settings(on_ui_settings)
|
||||
script_callbacks.on_after_component(on_after_component)
|
||||
script_callbacks.on_before_ui(on_before_ui)
|
||||
|
||||
@@ -11,5 +11,12 @@ if TYPE_CHECKING:
|
||||
def on_after_component(callback: Callable):
|
||||
pass
|
||||
|
||||
def on_before_ui(callback: Callable):
|
||||
pass
|
||||
|
||||
else:
|
||||
from modules.script_callbacks import on_after_component, on_ui_settings
|
||||
from modules.script_callbacks import (
|
||||
on_after_component,
|
||||
on_before_ui,
|
||||
on_ui_settings,
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import namedtuple
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
@@ -79,5 +80,15 @@ if TYPE_CHECKING:
|
||||
def elem_id(self, item_id: Any) -> str:
|
||||
pass
|
||||
|
||||
ScriptClassData = namedtuple(
|
||||
"ScriptClassData", ["script_class", "path", "basedir", "module"]
|
||||
)
|
||||
scripts_data: list[ScriptClassData] = []
|
||||
|
||||
else:
|
||||
from modules.scripts import AlwaysVisible, PostprocessImageArgs, Script
|
||||
from modules.scripts import (
|
||||
AlwaysVisible,
|
||||
PostprocessImageArgs,
|
||||
Script,
|
||||
scripts_data,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user