Spaces:
Running
Running
Download src/backend/annotators/depth_control.py from rupeshs/fastsdcpu: direct link, hf CLI and curl.
- Browser
- Download file 528 Bytes
-
https://huggingface.co/spaces/rupeshs/fastsdcpu/resolve/main/src/backend/annotators/depth_control.py
- Command line
-
hf download hf://spaces/rupeshs/fastsdcpu/src/backend/annotators/depth_control.py
-
curl -L -o depth_control.py https://huggingface.co/spaces/rupeshs/fastsdcpu/resolve/main/src/backend/annotators/depth_control.py
528 Bytes
| import numpy as np | |
| from backend.annotators.control_interface import ControlInterface | |
| from PIL import Image | |
| from transformers import pipeline | |
| class DepthControl(ControlInterface): | |
| def get_control_image(self, image: Image) -> Image: | |
| depth_estimator = pipeline("depth-estimation") | |
| image = depth_estimator(image)["depth"] | |
| image = np.array(image) | |
| image = image[:, :, None] | |
| image = np.concatenate([image, image, image], axis=2) | |
| image = Image.fromarray(image) | |
| return image | |