From 291797c9c85b5edaedbc3ddc5bb664fc9c0644a6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 22:16:40 +0900 Subject: [PATCH 1/4] [pre-commit.ci] pre-commit autoupdate (#736) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.2 → v0.8.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.2...v0.8.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- adetailer/__init__.py | 4 ++-- controlnet_ext/__init__.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3343ccb..2f726b8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: - id: prettier - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.2 + rev: v0.8.0 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/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", From cb69a52fb34fc4e404801062186fbff84323558e Mon Sep 17 00:00:00 2001 From: Dowon Date: Mon, 2 Dec 2024 22:18:44 +0900 Subject: [PATCH 2/4] update pre-commit --- .pre-commit-config.yaml | 4 ++-- adetailer/common.py | 2 +- scripts/!adetailer.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f726b8..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.8.0 + rev: v0.8.1 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] 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/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 From 6a0e501654f6db0215c038894c1b1fee09bd5fce Mon Sep 17 00:00:00 2001 From: Dowon Date: Mon, 2 Dec 2024 22:35:35 +0900 Subject: [PATCH 3/4] fix: fix tests mediapipe only failed on macos --- tests/test_mediapipe.py | 9 +++++---- tests/test_ultralytics.py | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) 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) From 190e708b8ba678a8c1c2c1b0a8bca28efb8a77c4 Mon Sep 17 00:00:00 2001 From: Dowon Date: Fri, 6 Dec 2024 09:59:55 +0900 Subject: [PATCH 4/4] fix: update install script There was an attack on the ultralytics package --- install.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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}"