SwordElucidator
commited on
Commit
•
be59b56
1
Parent(s):
9ad10c7
Update handler.py
Browse files- handler.py +9 -1
handler.py
CHANGED
@@ -45,7 +45,15 @@ class EndpointHandler():
|
|
45 |
|
46 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
47 |
image = data['inputs'].pop("image", None)
|
|
|
48 |
type = data['inputs'].pop("type", '<MORE_DETAILED_CAPTION>')
|
49 |
text = data['inputs'].pop("text", None)
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
return self.run_example(image, type, text_input=text)
|
|
|
45 |
|
46 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
47 |
image = data['inputs'].pop("image", None)
|
48 |
+
image_url = data['inputs'].pop("image_url", None)
|
49 |
type = data['inputs'].pop("type", '<MORE_DETAILED_CAPTION>')
|
50 |
text = data['inputs'].pop("text", None)
|
51 |
+
if image:
|
52 |
+
image = Image.open(BytesIO(base64.b64decode(image)))
|
53 |
+
elif image_url:
|
54 |
+
response = requests.get(image_url)
|
55 |
+
if response.status_code == 200:
|
56 |
+
image = Image.open(BytesIO(response.content))
|
57 |
+
else:
|
58 |
+
raise ValueError(f"Unable to download image from URL: {image_url}")
|
59 |
return self.run_example(image, type, text_input=text)
|