Upload folder using huggingface_hub
Browse files- handler.py +12 -5
handler.py
CHANGED
|
@@ -58,8 +58,15 @@ class EndpointHandler:
|
|
| 58 |
return False
|
| 59 |
|
| 60 |
def _decode_image(self, data):
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
return False
|
| 59 |
|
| 60 |
def _decode_image(self, data):
|
| 61 |
+
try:
|
| 62 |
+
if isinstance(data, str):
|
| 63 |
+
image_bytes = base64.b64decode(data)
|
| 64 |
+
else:
|
| 65 |
+
image_bytes = data
|
| 66 |
+
img = Image.open(io.BytesIO(image_bytes))
|
| 67 |
+
# Ensure loaded
|
| 68 |
+
img.load()
|
| 69 |
+
return img.convert("RGB")
|
| 70 |
+
except Exception as e:
|
| 71 |
+
print(f"Image decode failed: {e}")
|
| 72 |
+
raise ValueError(f"Invalid image data: {e}")
|