Spaces:
Configuration error
Configuration error
Download app/utils.py from gourinath/rishiproject: direct link, hf CLI and curl.
- Browser
- Download file 541 Bytes
-
https://huggingface.co/spaces/gourinath/rishiproject/resolve/main/app/utils.py
- Command line
-
hf download hf://spaces/gourinath/rishiproject/app/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/gourinath/rishiproject/resolve/main/app/utils.py
541 Bytes
| import base64 | |
| import os | |
| from io import BytesIO | |
| from PIL import Image | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| def get_env(key: str, default: str = "") -> str: | |
| return os.getenv(key, default) | |
| def image_to_base64_jpeg(image: Image.Image) -> str: | |
| """Convert a PIL image to base64-encoded JPEG string.""" | |
| buf = BytesIO() | |
| image = image.convert("RGB") | |
| image.save(buf, format="JPEG", quality=90) | |
| return base64.b64encode(buf.getvalue()).decode("utf-8") | |
| def load_image(file) -> Image.Image: | |
| return Image.open(file) | |