diff --git a/setup.py b/setup.py index 7c15d650c78d..119e7971ea65 100644 --- a/setup.py +++ b/setup.py @@ -142,6 +142,7 @@ "urllib3<=2.0.0", "black", "phonemizer", + "opencv-python", ] # this is a lookup table with items like: diff --git a/src/diffusers/__init__.py b/src/diffusers/__init__.py index 3c7e8654d223..21119e398539 100644 --- a/src/diffusers/__init__.py +++ b/src/diffusers/__init__.py @@ -22,6 +22,7 @@ is_torchsde_available, is_transformers_available, ) +from .utils.import_utils import is_opencv_available # Lazy Import based on @@ -352,7 +353,6 @@ "CogView3PlusPipeline", "CogView4ControlPipeline", "CogView4Pipeline", - "ConsisIDPipeline", "CycleDiffusionPipeline", "EasyAnimateControlPipeline", "EasyAnimateInpaintPipeline", @@ -518,6 +518,25 @@ ] ) + +try: + if not (is_torch_available() and is_transformers_available() and is_opencv_available()): + raise OptionalDependencyNotAvailable() +except OptionalDependencyNotAvailable: + from .utils import dummy_torch_and_transformers_and_opencv_objects # noqa F403 + + _import_structure["utils.dummy_torch_and_transformers_and_opencv_objects"] = [ + name for name in dir(dummy_torch_and_transformers_and_opencv_objects) if not name.startswith("_") + ] + +else: + _import_structure["pipelines"].extend( + [ + "ConsisIDPipeline", + ] + ) + + try: if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()): raise OptionalDependencyNotAvailable() @@ -909,7 +928,6 @@ CogView3PlusPipeline, CogView4ControlPipeline, CogView4Pipeline, - ConsisIDPipeline, CycleDiffusionPipeline, EasyAnimateControlPipeline, EasyAnimateInpaintPipeline, @@ -1073,6 +1091,16 @@ WuerstchenPriorPipeline, ) + try: + if not (is_torch_available() and is_transformers_available() and is_opencv_available()): + raise OptionalDependencyNotAvailable() + except OptionalDependencyNotAvailable: + from .utils.dummy_torch_and_transformers_and_opencv_objects import * # noqa F403 + else: + from .pipelines import ( + ConsisIDPipeline, + ) + try: if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()): raise OptionalDependencyNotAvailable() diff --git a/src/diffusers/dependency_versions_table.py b/src/diffusers/dependency_versions_table.py index 520815d122de..4793972c1cd1 100644 --- a/src/diffusers/dependency_versions_table.py +++ b/src/diffusers/dependency_versions_table.py @@ -49,4 +49,5 @@ "urllib3": "urllib3<=2.0.0", "black": "black", "phonemizer": "phonemizer", + "opencv-python": "opencv-python", } diff --git a/src/diffusers/pipelines/consisid/__init__.py b/src/diffusers/pipelines/consisid/__init__.py index 5052e146f1df..46f5f3352de3 100644 --- a/src/diffusers/pipelines/consisid/__init__.py +++ b/src/diffusers/pipelines/consisid/__init__.py @@ -8,6 +8,7 @@ is_torch_available, is_transformers_available, ) +from ...utils.import_utils import is_opencv_available _dummy_objects = {} @@ -15,22 +16,22 @@ try: - if not (is_transformers_available() and is_torch_available()): + if not (is_transformers_available() and is_torch_available() and is_opencv_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: - from ...utils import dummy_torch_and_transformers_objects # noqa F403 + from ...utils import dummy_torch_and_transformers_and_opencv_objects # noqa F403 - _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects)) + _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_and_opencv_objects)) else: _import_structure["pipeline_consisid"] = ["ConsisIDPipeline"] if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: try: - if not (is_transformers_available() and is_torch_available()): + if not (is_transformers_available() and is_torch_available() and is_opencv_available()): raise OptionalDependencyNotAvailable() except OptionalDependencyNotAvailable: - from ...utils.dummy_torch_and_transformers_objects import * + from ...utils.dummy_torch_and_transformers_and_opencv_objects import * else: from .pipeline_consisid import ConsisIDPipeline diff --git a/src/diffusers/utils/dummy_torch_and_transformers_and_opencv_objects.py b/src/diffusers/utils/dummy_torch_and_transformers_and_opencv_objects.py new file mode 100644 index 000000000000..c0c4d9df5eee --- /dev/null +++ b/src/diffusers/utils/dummy_torch_and_transformers_and_opencv_objects.py @@ -0,0 +1,17 @@ +# This file is autogenerated by the command `make fix-copies`, do not edit. +from ..utils import DummyObject, requires_backends + + +class ConsisIDPipeline(metaclass=DummyObject): + _backends = ["torch", "transformers", "opencv"] + + def __init__(self, *args, **kwargs): + requires_backends(self, ["torch", "transformers", "opencv"]) + + @classmethod + def from_config(cls, *args, **kwargs): + requires_backends(cls, ["torch", "transformers", "opencv"]) + + @classmethod + def from_pretrained(cls, *args, **kwargs): + requires_backends(cls, ["torch", "transformers", "opencv"]) diff --git a/src/diffusers/utils/dummy_torch_and_transformers_objects.py b/src/diffusers/utils/dummy_torch_and_transformers_objects.py index b28fba948149..2136131126e9 100644 --- a/src/diffusers/utils/dummy_torch_and_transformers_objects.py +++ b/src/diffusers/utils/dummy_torch_and_transformers_objects.py @@ -392,21 +392,6 @@ def from_pretrained(cls, *args, **kwargs): requires_backends(cls, ["torch", "transformers"]) -class ConsisIDPipeline(metaclass=DummyObject): - _backends = ["torch", "transformers"] - - def __init__(self, *args, **kwargs): - requires_backends(self, ["torch", "transformers"]) - - @classmethod - def from_config(cls, *args, **kwargs): - requires_backends(cls, ["torch", "transformers"]) - - @classmethod - def from_pretrained(cls, *args, **kwargs): - requires_backends(cls, ["torch", "transformers"]) - - class CycleDiffusionPipeline(metaclass=DummyObject): _backends = ["torch", "transformers"] diff --git a/tests/others/test_dependencies.py b/tests/others/test_dependencies.py index c0839ef0236b..30c16a217c00 100644 --- a/tests/others/test_dependencies.py +++ b/tests/others/test_dependencies.py @@ -37,6 +37,8 @@ def test_backend_registration(self): backend = "k-diffusion" elif backend == "invisible_watermark": backend = "invisible-watermark" + elif backend == "opencv": + backend = "opencv-python" assert backend in deps, f"{backend} is not in the deps table!" def test_pipeline_imports(self):