sbarouti commited on
Commit
9bb3f96
·
verified ·
1 Parent(s): fa213b1

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +11 -2
handler.py CHANGED
@@ -23,8 +23,17 @@ class EndpointHandler():
23
  imageData = inputs.get("image")
24
  print("** imageData: ", imageData)
25
 
26
- image = Image.open(BytesIO(base64.b64decode(imageData)))
27
- print("** image: ", image)
 
 
 
 
 
 
 
 
 
28
 
29
  inputs = self.processor(text=text, images=image, return_tensors="pt", padding=True)
30
  outputs = self.model(**inputs)
 
23
  imageData = inputs.get("image")
24
  print("** imageData: ", imageData)
25
 
26
+ image = None
27
+ if image_data:
28
+ try:
29
+ image = Image.open(BytesIO(base64.b64decode(image_data)))
30
+ print("** image: ", image)
31
+ except Exception as e:
32
+ raise ValueError(f"Error decoding image: {e}")
33
+
34
+ if not text and not image:
35
+ raise ValueError("Both text and image cannot be None. Provide at least one.")
36
+
37
 
38
  inputs = self.processor(text=text, images=image, return_tensors="pt", padding=True)
39
  outputs = self.model(**inputs)