diff options
Diffstat (limited to 'src/mcp_sd15/preprocessors/depth.py')
| -rw-r--r-- | src/mcp_sd15/preprocessors/depth.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mcp_sd15/preprocessors/depth.py b/src/mcp_sd15/preprocessors/depth.py new file mode 100644 index 0000000..861b889 --- /dev/null +++ b/src/mcp_sd15/preprocessors/depth.py @@ -0,0 +1,24 @@ +"""MiDaS depth-map preprocessing.""" + +from __future__ import annotations + +from typing import cast + +from PIL import Image + + +class DepthPreprocessor: + """Lazily loads the fixed MiDaS annotator from the local cache.""" + + def __init__(self) -> None: + self._detector: object | None = None + + def __call__(self, image: Image.Image) -> Image.Image: + if self._detector is None: + from controlnet_aux import MidasDetector + + self._detector = MidasDetector.from_pretrained( + "lllyasviel/Annotators", local_files_only=True + ) + result = cast(Image.Image, self._detector(image)) # type: ignore[operator] + return result.convert("RGB") |
