Spaces:
Runtime error
Runtime error
Download image_preprocessing.py from Pulseb/insiders-generation-hub: direct link, hf CLI and curl.
- Browser
- Download file 804 Bytes
-
https://huggingface.co/spaces/Pulseb/insiders-generation-hub/resolve/main/image_preprocessing.py
- Command line
-
hf download hf://spaces/Pulseb/insiders-generation-hub/image_preprocessing.py
-
curl -L -o image_preprocessing.py https://huggingface.co/spaces/Pulseb/insiders-generation-hub/resolve/main/image_preprocessing.py
804 Bytes
| from pathlib import Path | |
| from typing import Union | |
| from PIL import Image, ImageOps | |
| from pillow_heif import register_heif_opener | |
| # Register HEIC/HEIF decoding globally so Pillow-based consumers such as Gradio | |
| # can accept iPhone uploads as well as the preprocessing function below. | |
| register_heif_opener(thumbnails=False) | |
| def load_standardized_image(image_path: Union[str, Path]) -> Image.Image: | |
| """Load an image with its orientation applied and normalize it to RGB.""" | |
| with Image.open(image_path) as image: | |
| image.load() | |
| oriented_image = ImageOps.exif_transpose(image) | |
| standardized_image = oriented_image.convert("RGB") | |
| # Return a detached image without source metadata, including EXIF orientation. | |
| standardized_image.info.clear() | |
| return standardized_image | |