Update handler.py
Browse files- handler.py +5 -3
handler.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from base64 import b64encode
|
| 2 |
from io import BytesIO
|
| 3 |
from pathlib import Path
|
| 4 |
|
|
@@ -31,8 +31,10 @@ class EndpointHandler:
|
|
| 31 |
image = data.pop("inputs", data)
|
| 32 |
|
| 33 |
# This lets us pass local images as well while developing
|
| 34 |
-
if isinstance(image,
|
| 35 |
-
image = Image.open(BytesIO(image))
|
|
|
|
|
|
|
| 36 |
|
| 37 |
image = np.array(image)
|
| 38 |
image = image[:, :, ::-1] # RGB -> BGR
|
|
|
|
| 1 |
+
from base64 import b64encode, b64decode
|
| 2 |
from io import BytesIO
|
| 3 |
from pathlib import Path
|
| 4 |
|
|
|
|
| 31 |
image = data.pop("inputs", data)
|
| 32 |
|
| 33 |
# This lets us pass local images as well while developing
|
| 34 |
+
if isinstance(image, str):
|
| 35 |
+
image = Image.open(BytesIO(b64decode(image)))
|
| 36 |
+
elif isinstance(image, bytes):
|
| 37 |
+
image = Image.open(BytesIO(image))
|
| 38 |
|
| 39 |
image = np.array(image)
|
| 40 |
image = image[:, :, ::-1] # RGB -> BGR
|