Spaces:
Runtime error
Runtime error
Download utility/file_handler.py from Anshu370/AI_Similar_Image_Visualizer: direct link, hf CLI and curl.
- Browser
- Download file 503 Bytes
-
https://huggingface.co/spaces/Anshu370/AI_Similar_Image_Visualizer/resolve/main/utility/file_handler.py
- Command line
-
hf download hf://spaces/Anshu370/AI_Similar_Image_Visualizer/utility/file_handler.py
-
curl -L -o file_handler.py https://huggingface.co/spaces/Anshu370/AI_Similar_Image_Visualizer/resolve/main/utility/file_handler.py
503 Bytes
| from PIL import Image | |
| from io import BytesIO | |
| import requests | |
| from fastapi import UploadFile | |
| from typing import Optional | |
| async def get_file(file: Optional[UploadFile] = None, url: Optional[str] = None) -> Image.Image: | |
| if file: | |
| image = Image.open(file.file).convert("RGB") | |
| elif url: | |
| response = requests.get(url) | |
| image = Image.open(BytesIO(response.content)).convert("RGB") | |
| else: | |
| raise ValueError("No image file or URL provided.") | |
| return image |