Spaces:
Runtime error
Runtime error
Commit ·
906f9ca
1
Parent(s): bc6e7dd
Upload folder using huggingface_hub
Browse files- image_caption/get_caption.py +12 -1
image_caption/get_caption.py
CHANGED
|
@@ -12,6 +12,7 @@ import json
|
|
| 12 |
import requests
|
| 13 |
import base64
|
| 14 |
from io import BytesIO
|
|
|
|
| 15 |
|
| 16 |
def get_image_caption(img_obj, prompt=None):
|
| 17 |
"""
|
|
@@ -27,7 +28,17 @@ def get_image_caption(img_obj, prompt=None):
|
|
| 27 |
|
| 28 |
|
| 29 |
buffered = BytesIO()
|
| 30 |
-
img_obj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
| 32 |
url = os.environ.get("IMAGE_CAPTION_ENDPOINT")
|
| 33 |
auth_token = os.environ.get("IMAGE_CAPTION_AUTH_TOKEN")
|
|
|
|
| 12 |
import requests
|
| 13 |
import base64
|
| 14 |
from io import BytesIO
|
| 15 |
+
import PIL
|
| 16 |
|
| 17 |
def get_image_caption(img_obj, prompt=None):
|
| 18 |
"""
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
buffered = BytesIO()
|
| 31 |
+
if img_obj is None:
|
| 32 |
+
return "No image data provided!"
|
| 33 |
+
try:
|
| 34 |
+
img_obj.save(buffered, format="JPEG")
|
| 35 |
+
except PIL.UnidentifiedImageError as e:
|
| 36 |
+
print("Error in saving the image", e)
|
| 37 |
+
return "Invalid image format!"
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print("Some error occurred while saving the image", e)
|
| 40 |
+
return "Some error occurred while loading the image!"
|
| 41 |
+
|
| 42 |
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
| 43 |
url = os.environ.get("IMAGE_CAPTION_ENDPOINT")
|
| 44 |
auth_token = os.environ.get("IMAGE_CAPTION_AUTH_TOKEN")
|