nicklorch commited on
Commit
c04fdf8
·
1 Parent(s): 29107e0

getting closer

Browse files
Files changed (1) hide show
  1. handler.py +10 -11
handler.py CHANGED
@@ -20,21 +20,20 @@ class EndpointHandler():
20
  def __call__(self, data):
21
  try:
22
 
23
- logger.info('data is %s', data)
24
  text_input = None
 
25
 
26
- logger.info('data is a dict %s', data)
27
- inputs = data.pop("inputs", None)
28
- text_input = inputs["text"] if "text" in inputs else None
29
- image_data = inputs['image'] if 'image' in inputs else None
 
 
30
 
31
  if image_data is not None:
32
- if isinstance(image_data, Image):
33
- logger.info('image is an image')
34
- image = image_data
35
- else:
36
- logger.info('image is encoded')
37
- image = BytesIO(base64.b64decode(image_data))
38
 
39
  if text_input:
40
  processor = self.processor(text=text_input, return_tensors="pt", padding=True).to(device)
 
20
  def __call__(self, data):
21
  try:
22
 
23
+ inputs = data.pop("inputs", None)
24
  text_input = None
25
+ image_data = None
26
 
27
+ if isinstance(inputs, Image):
28
+ logger.info('image sent directly')
29
+ image = inputs
30
+ else:
31
+ text_input = inputs["text"] if "text" in inputs else None
32
+ image_data = inputs['image'] if 'image' in inputs else None
33
 
34
  if image_data is not None:
35
+ logger.info('image is encoded')
36
+ image = BytesIO(base64.b64decode(image_data))
 
 
 
 
37
 
38
  if text_input:
39
  processor = self.processor(text=text_input, return_tensors="pt", padding=True).to(device)