Upload handler.py
Browse filesfixed image load issue
- handler.py +7 -2
handler.py
CHANGED
|
@@ -26,7 +26,10 @@ class EndpointHandler():
|
|
| 26 |
inputs = data.pop("inputs", data)
|
| 27 |
parameters = data.pop("parameters", {})
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
processed_image = self.processor(images=raw_images, return_tensors="pt")
|
| 32 |
processed_image["pixel_values"] = processed_image["pixel_values"].to(device)
|
|
@@ -38,4 +41,6 @@ class EndpointHandler():
|
|
| 38 |
)
|
| 39 |
description = self.processor.batch_decode(out, skip_special_tokens=True)
|
| 40 |
|
| 41 |
-
return {"description": description}
|
|
|
|
|
|
|
|
|
| 26 |
inputs = data.pop("inputs", data)
|
| 27 |
parameters = data.pop("parameters", {})
|
| 28 |
|
| 29 |
+
if isinstance(inputs, bytes): # If a single image is passed
|
| 30 |
+
raw_images = [Image.open(BytesIO(inputs))]
|
| 31 |
+
else: # If already a list of images
|
| 32 |
+
raw_images = [Image.open(BytesIO(_img)) for _img in inputs]
|
| 33 |
|
| 34 |
processed_image = self.processor(images=raw_images, return_tensors="pt")
|
| 35 |
processed_image["pixel_values"] = processed_image["pixel_values"].to(device)
|
|
|
|
| 41 |
)
|
| 42 |
description = self.processor.batch_decode(out, skip_special_tokens=True)
|
| 43 |
|
| 44 |
+
return {"description": description}
|
| 45 |
+
|
| 46 |
+
handler = EndpointHandler()
|