Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,8 @@ from google.genai import types
|
|
| 9 |
from PIL import Image
|
| 10 |
from io import BytesIO
|
| 11 |
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Cấu hình API Key
|
| 14 |
api_key = os.getenv("GEMINI_API_KEY")
|
|
@@ -21,7 +23,8 @@ def load_image_as_bytes(image_path):
|
|
| 21 |
"""Chuyển ảnh thành dữ liệu nhị phân với kiểm tra lỗi"""
|
| 22 |
try:
|
| 23 |
with Image.open(image_path) as img:
|
| 24 |
-
img = img.
|
|
|
|
| 25 |
img_bytes = BytesIO()
|
| 26 |
img.save(img_bytes, format="JPEG") # Lưu ảnh vào buffer
|
| 27 |
return img_bytes.getvalue() # Lấy dữ liệu nhị phân
|
|
|
|
| 9 |
from PIL import Image
|
| 10 |
from io import BytesIO
|
| 11 |
from huggingface_hub import hf_hub_download
|
| 12 |
+
import time
|
| 13 |
+
import json
|
| 14 |
|
| 15 |
# Cấu hình API Key
|
| 16 |
api_key = os.getenv("GEMINI_API_KEY")
|
|
|
|
| 23 |
"""Chuyển ảnh thành dữ liệu nhị phân với kiểm tra lỗi"""
|
| 24 |
try:
|
| 25 |
with Image.open(image_path) as img:
|
| 26 |
+
img = img.
|
| 27 |
+
convert("RGB") # Đảm bảo ảnh là RGB
|
| 28 |
img_bytes = BytesIO()
|
| 29 |
img.save(img_bytes, format="JPEG") # Lưu ảnh vào buffer
|
| 30 |
return img_bytes.getvalue() # Lấy dữ liệu nhị phân
|