eBoreal commited on
Commit
61ce98e
·
1 Parent(s): b2dff23

safer parsing

Browse files
Files changed (1) hide show
  1. 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.pop("inputs", None)
35
 
36
  if not inputs:
37
  return f"Inputs not in payload got {data}"
38
 
39
  # get additional date field0
40
- prompt = inputs.pop("prompt", None)
41
- image_url = inputs.pop("image", None)
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