Spaces:
Sleeping
Sleeping
| import base64 | |
| from io import BytesIO | |
| from PIL import Image | |
| # This utility file is included primarily for modularity, | |
| # though the PIL to Base64/Image loading logic is largely handled within models.py | |
| # using the native SDK methods of google-genai and openai for simplicity. | |
| def image_to_base664(img: Image.Image) -> str: | |
| """Converts a PIL Image object to a base64 encoded string.""" | |
| buffer = BytesIO() | |
| # Use PNG for high quality transfer compatible with most APIs | |
| img.save(buffer, format="PNG") | |
| img_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8') | |
| return img_base64 |