Merge branch 'dev'

pull/774/head
Dowon 2024-12-06 10:00:10 +09:00
commit 7ae5d7abb7
No known key found for this signature in database
GPG Key ID: 9CCE5CDC08E34AD0
8 changed files with 35 additions and 15 deletions

View File

@ -19,12 +19,12 @@ repos:
- id: mixed-line-ending - id: mixed-line-ending
- repo: https://github.com/rbubley/mirrors-prettier - repo: https://github.com/rbubley/mirrors-prettier
rev: v3.3.3 rev: v3.4.1
hooks: hooks:
- id: prettier - id: prettier
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2 rev: v0.8.1
hooks: hooks:
- id: ruff - id: ruff
args: [--fix, --exit-non-zero-on-fix] args: [--fix, --exit-non-zero-on-fix]

View File

@ -7,11 +7,11 @@ from .ultralytics import ultralytics_predict
ADETAILER = "ADetailer" ADETAILER = "ADetailer"
__all__ = [ __all__ = [
"__version__",
"ADetailerArgs",
"ADETAILER", "ADETAILER",
"ALL_ARGS", "ALL_ARGS",
"ADetailerArgs",
"PredictOutput", "PredictOutput",
"__version__",
"get_models", "get_models",
"mediapipe_predict", "mediapipe_predict",
"ultralytics_predict", "ultralytics_predict",

View File

@ -10,7 +10,7 @@ from typing import Any, Generic, Optional, TypeVar
from huggingface_hub import hf_hub_download from huggingface_hub import hf_hub_download
from PIL import Image, ImageDraw from PIL import Image, ImageDraw
from rich import print from rich import print # noqa: A004 Shadowing built-in 'print'
from torchvision.transforms.functional import to_pil_image from torchvision.transforms.functional import to_pil_image
REPO_ID = "Bingsu/adetailer" REPO_ID = "Bingsu/adetailer"

View File

@ -16,8 +16,8 @@ except ImportError:
from .restore import CNHijackRestore, cn_allow_script_control from .restore import CNHijackRestore, cn_allow_script_control
__all__ = [ __all__ = [
"ControlNetExt",
"CNHijackRestore", "CNHijackRestore",
"ControlNetExt",
"cn_allow_script_control", "cn_allow_script_control",
"controlnet_exists", "controlnet_exists",
"controlnet_type", "controlnet_type",

View File

@ -8,12 +8,17 @@ from importlib.metadata import version # python >= 3.8
from packaging.version import parse from packaging.version import parse
import_name = {"py-cpuinfo": "cpuinfo", "protobuf": "google.protobuf"} import_name = {"py-cpuinfo": "cpuinfo", "protobuf": "google.protobuf"}
custom_requirements = {"ultralytics": "ultralytics>=8.3.0,!=8.3.41,!=8.3.42"}
excluded_versions = {"ultralytics": ("8.3.41", "8.3.42")}
def is_installed( def is_installed(
package: str, min_version: str | None = None, max_version: str | None = None package: str,
min_version: str | None = None,
max_version: str | None = None,
): ):
name = import_name.get(package, package) name = import_name.get(package, package)
excluded = excluded_versions.get(package, ())
try: try:
spec = importlib.util.find_spec(name) spec = importlib.util.find_spec(name)
except ModuleNotFoundError: except ModuleNotFoundError:
@ -32,7 +37,10 @@ def is_installed(
try: try:
pkg_version = version(package) pkg_version = version(package)
return parse(min_version) <= parse(pkg_version) <= parse(max_version) return (
parse(min_version) <= parse(pkg_version) <= parse(max_version)
and pkg_version not in excluded
)
except Exception: except Exception:
return False return False
@ -44,7 +52,7 @@ def run_pip(*args):
def install(): def install():
deps = [ deps = [
# requirements # requirements
("ultralytics", "8.2.0", None), ("ultralytics", "8.3.0", None),
("mediapipe", "0.10.13", "0.10.15"), ("mediapipe", "0.10.13", "0.10.15"),
("rich", "13.0.0", None), ("rich", "13.0.0", None),
] ]
@ -52,7 +60,9 @@ def install():
pkgs = [] pkgs = []
for pkg, low, high in deps: for pkg, low, high in deps:
if not is_installed(pkg, low, high): if not is_installed(pkg, low, high):
if low and high: if pkg in custom_requirements:
cmd = custom_requirements[pkg]
elif low and high:
cmd = f"{pkg}>={low},<={high}" cmd = f"{pkg}>={low},<={high}"
elif low: elif low:
cmd = f"{pkg}>={low}" cmd = f"{pkg}>={low}"

View File

@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Any, NamedTuple, cast
import gradio as gr import gradio as gr
from PIL import Image, ImageChops from PIL import Image, ImageChops
from rich import print from rich import print # noqa: A004 Shadowing built-in 'print'
import modules import modules
from aaaaaa.conditional import create_binary_mask, schedulers from aaaaaa.conditional import create_binary_mask, schedulers

View File

@ -15,7 +15,8 @@ from adetailer.mediapipe import mediapipe_predict
) )
def test_mediapipe(sample_image2: Image.Image, model_name: str): def test_mediapipe(sample_image2: Image.Image, model_name: str):
result = mediapipe_predict(model_name, sample_image2) result = mediapipe_predict(model_name, sample_image2)
assert result.preview is not None if result.preview is not None:
assert len(result.bboxes) > 0 assert len(result.bboxes) > 0
assert len(result.masks) > 0 assert len(result.masks) > 0
assert len(result.confidences) > 0 assert len(result.confidences) > 0
assert len(result.bboxes) == len(result.masks) == len(result.confidences)

View File

@ -25,12 +25,20 @@ def test_ultralytics_hf_models(sample_image: Image.Image, model_name: str):
model_path = hf_hub_download("Bingsu/adetailer", model_name) model_path = hf_hub_download("Bingsu/adetailer", model_name)
result = ultralytics_predict(model_path, sample_image) result = ultralytics_predict(model_path, sample_image)
assert result.preview is not None assert result.preview is not None
assert len(result.bboxes) > 0
assert len(result.masks) > 0
assert len(result.confidences) > 0
assert len(result.bboxes) == len(result.masks) == len(result.confidences)
def test_yolo_world_default(sample_image: Image.Image): def test_yolo_world_default(sample_image: Image.Image):
model_path = hf_hub_download("Bingsu/yolo-world-mirror", "yolov8x-worldv2.pt") model_path = hf_hub_download("Bingsu/yolo-world-mirror", "yolov8x-worldv2.pt")
result = ultralytics_predict(model_path, sample_image) result = ultralytics_predict(model_path, sample_image)
assert result.preview is not None assert result.preview is not None
assert len(result.bboxes) > 0
assert len(result.masks) > 0
assert len(result.confidences) > 0
assert len(result.bboxes) == len(result.masks) == len(result.confidences)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -51,3 +59,4 @@ def test_yolo_world(sample_image2: Image.Image, klass: str):
assert len(result.bboxes) > 0 assert len(result.bboxes) > 0
assert len(result.masks) > 0 assert len(result.masks) > 0
assert len(result.confidences) > 0 assert len(result.confidences) > 0
assert len(result.bboxes) == len(result.masks) == len(result.confidences)