diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3343ccb..9979309 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,12 +19,12 @@ repos: - id: mixed-line-ending - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.3.3 + rev: v3.4.1 hooks: - id: prettier - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.2 + rev: v0.8.1 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/adetailer/__init__.py b/adetailer/__init__.py index 6e6721e..ae05994 100644 --- a/adetailer/__init__.py +++ b/adetailer/__init__.py @@ -7,11 +7,11 @@ ADETAILER = "ADetailer" __all__ = [ - "__version__", - "ADetailerArgs", "ADETAILER", "ALL_ARGS", + "ADetailerArgs", "PredictOutput", + "__version__", "get_models", "mediapipe_predict", "ultralytics_predict", diff --git a/adetailer/common.py b/adetailer/common.py index ca6415a..4d1fdcc 100644 --- a/adetailer/common.py +++ b/adetailer/common.py @@ -10,7 +10,7 @@ from huggingface_hub import hf_hub_download 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 REPO_ID = "Bingsu/adetailer" diff --git a/controlnet_ext/__init__.py b/controlnet_ext/__init__.py index 6da28d4..1f3a1aa 100644 --- a/controlnet_ext/__init__.py +++ b/controlnet_ext/__init__.py @@ -16,8 +16,8 @@ from .restore import CNHijackRestore, cn_allow_script_control __all__ = [ - "ControlNetExt", "CNHijackRestore", + "ControlNetExt", "cn_allow_script_control", "controlnet_exists", "controlnet_type", diff --git a/install.py b/install.py index e7242cd..4718666 100644 --- a/install.py +++ b/install.py @@ -8,12 +8,17 @@ from packaging.version import parse 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( - 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) + excluded = excluded_versions.get(package, ()) try: spec = importlib.util.find_spec(name) except ModuleNotFoundError: @@ -32,7 +37,10 @@ def is_installed( try: 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: return False @@ -44,7 +52,7 @@ def run_pip(*args): def install(): deps = [ # requirements - ("ultralytics", "8.2.0", None), + ("ultralytics", "8.3.0", None), ("mediapipe", "0.10.13", "0.10.15"), ("rich", "13.0.0", None), ] @@ -52,7 +60,9 @@ def install(): pkgs = [] for pkg, low, high in deps: 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}" elif low: cmd = f"{pkg}>={low}" diff --git a/scripts/!adetailer.py b/scripts/!adetailer.py index 9ea743e..406e1b5 100644 --- a/scripts/!adetailer.py +++ b/scripts/!adetailer.py @@ -12,7 +12,7 @@ import gradio as gr from PIL import Image, ImageChops -from rich import print +from rich import print # noqa: A004 Shadowing built-in 'print' import modules from aaaaaa.conditional import create_binary_mask, schedulers diff --git a/tests/test_mediapipe.py b/tests/test_mediapipe.py index 900d056..469bcd5 100644 --- a/tests/test_mediapipe.py +++ b/tests/test_mediapipe.py @@ -15,7 +15,8 @@ ) def test_mediapipe(sample_image2: Image.Image, model_name: str): result = mediapipe_predict(model_name, sample_image2) - assert result.preview is not None - assert len(result.bboxes) > 0 - assert len(result.masks) > 0 - assert len(result.confidences) > 0 + if 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) diff --git a/tests/test_ultralytics.py b/tests/test_ultralytics.py index 7ae53a6..e75171d 100644 --- a/tests/test_ultralytics.py +++ b/tests/test_ultralytics.py @@ -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) result = ultralytics_predict(model_path, sample_image) 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): model_path = hf_hub_download("Bingsu/yolo-world-mirror", "yolov8x-worldv2.pt") result = ultralytics_predict(model_path, sample_image) 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( @@ -51,3 +59,4 @@ def test_yolo_world(sample_image2: Image.Image, klass: str): 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)