"""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")