safer parsing
Browse files- handler.py +6 -3
handler.py
CHANGED
|
@@ -31,14 +31,14 @@ class EndpointHandler:
|
|
| 31 |
A :obj:`list` | `dict`: will be serialized and returned
|
| 32 |
"""
|
| 33 |
# get inputs
|
| 34 |
-
inputs = data.
|
| 35 |
|
| 36 |
if not inputs:
|
| 37 |
return f"Inputs not in payload got {data}"
|
| 38 |
|
| 39 |
# get additional date field0
|
| 40 |
-
prompt = inputs.
|
| 41 |
-
image_url = inputs.
|
| 42 |
|
| 43 |
if image_url is None:
|
| 44 |
return "You need to upload an image URL for LLaVA to work."
|
|
@@ -72,6 +72,9 @@ class EndpointHandler:
|
|
| 72 |
|
| 73 |
output = self.model.generate(**inputs, max_new_tokens=100)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
| 75 |
clean = self.processor.decode(output[0], skip_special_tokens=True)
|
| 76 |
|
| 77 |
return clean
|
|
|
|
| 31 |
A :obj:`list` | `dict`: will be serialized and returned
|
| 32 |
"""
|
| 33 |
# get inputs
|
| 34 |
+
inputs = data.get("inputs")
|
| 35 |
|
| 36 |
if not inputs:
|
| 37 |
return f"Inputs not in payload got {data}"
|
| 38 |
|
| 39 |
# get additional date field0
|
| 40 |
+
prompt = inputs.get("prompt")
|
| 41 |
+
image_url = inputs.get("image")
|
| 42 |
|
| 43 |
if image_url is None:
|
| 44 |
return "You need to upload an image URL for LLaVA to work."
|
|
|
|
| 72 |
|
| 73 |
output = self.model.generate(**inputs, max_new_tokens=100)
|
| 74 |
|
| 75 |
+
if not output:
|
| 76 |
+
return 'Model failed to generate'
|
| 77 |
+
|
| 78 |
clean = self.processor.decode(output[0], skip_special_tokens=True)
|
| 79 |
|
| 80 |
return clean
|