Update handler.py
Browse files- handler.py +10 -6
handler.py
CHANGED
|
@@ -2,7 +2,8 @@ from typing import Dict, List, Any
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import transformers
|
| 4 |
from PIL import Image
|
| 5 |
-
import
|
|
|
|
| 6 |
|
| 7 |
print('TRANSFORMERS VERSION')
|
| 8 |
print(transformers.__version__)
|
|
@@ -14,12 +15,15 @@ class EndpointHandler():
|
|
| 14 |
|
| 15 |
|
| 16 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
depth = self.pipe(image)["depth"]
|
| 25 |
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import transformers
|
| 4 |
from PIL import Image
|
| 5 |
+
import base64
|
| 6 |
+
from io import BytesIO
|
| 7 |
|
| 8 |
print('TRANSFORMERS VERSION')
|
| 9 |
print(transformers.__version__)
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 18 |
+
base64_image = data.get("image")
|
| 19 |
+
if base64_image is None:
|
| 20 |
+
raise ValueError("No image provided")
|
| 21 |
|
| 22 |
+
if base64_image.startswith('data:image/jpeg;base64,'):
|
| 23 |
+
base64_image = base64_image.replace('data:image/jpeg;base64,', '')
|
| 24 |
+
|
| 25 |
+
image_bytes = base64.b64decode(base64_image)
|
| 26 |
+
image = Image.open(BytesIO(image_bytes))
|
| 27 |
|
| 28 |
depth = self.pipe(image)["depth"]
|
| 29 |
|