kumararvindibs commited on
Commit
ccd844e
·
verified ·
1 Parent(s): c84ac25

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +24 -17
handler.py CHANGED
@@ -21,27 +21,34 @@ class EndpointHandler():
21
 
22
  def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
23
  logging.error(f"----------This is an error message {str(data)}")
24
- input_data = data.get("inputs", {})
25
- logging.warning(f"------input_data-- {str(input_data)}")
26
- # encoded_images = input_data.get("images")
27
- #logging.warning(f"---encoded_images----- {str(encoded_images)}")
28
- if not input_data:
29
- #logging.warning(f"---encoded_images--not provided in if block--- {str(encoded_images)}")
30
- return {"captions": [], "error": "No images provided"}
 
 
 
 
 
 
 
31
  try:
32
- logging.warning(f"---encoded_images-- provided in try block--- {str(input_data)}")
33
- byteImgIO = io.BytesIO()
34
 
35
- byteImg = Image.open(input_data)
36
- byteImg.save(byteImgIO, "PNG")
37
- byteImgIO.seek(0)
38
- byteImg = byteImgIO.read()
39
 
40
 
41
- # Non test code
42
- dataBytesIO = io.BytesIO(byteImg)
43
- raw_images =[Image.open(dataBytesIO)]
44
- logging.warning(f"----raw_images----0--- {str(raw_images)}")
45
  # Check if any images were successfully decoded
46
  if not raw_images:
47
  print("No valid images found.")
 
21
 
22
  def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
23
  logging.error(f"----------This is an error message {str(data)}")
24
+ raw_images = data.get("inputs", {})
25
+ # logging.warning(f"------input_data-- {str(input_data)}")
26
+ # encoded_images = input_data.get("images")
27
+ # # Convert image to bytes
28
+ # image = Image.open(encoded_images[0])
29
+ # image_bytes = image.tobytes()
30
+ # logging.warning(f"---image_bytes----- {str(image_bytes)}")
31
+ # # Encode image bytes as base64
32
+ # image_base64 = base64.b64encode(image_bytes).decode("utf-8")
33
+ # #logging.warning(f"---encoded_images----- {str(image_base64)}")
34
+ # # print("000--------", image_base64)
35
+ # if not encoded_images:
36
+ # logging.warning(f"---encoded_images--not provided in if block--- {str(encoded_images)}")
37
+ # return {"captions": [], "error": "No images provided"}
38
  try:
39
+ # logging.warning(f"---encoded_images-- provided in try block--- {str(encoded_images)}")
40
+ # byteImgIO = io.BytesIO()
41
 
42
+ # byteImg = Image.open(encoded_images[0])
43
+ # byteImg.save(byteImgIO, "PNG")
44
+ # byteImgIO.seek(0)
45
+ # byteImg = byteImgIO.read()
46
 
47
 
48
+ # # Non test code
49
+ # dataBytesIO = io.BytesIO(byteImg)
50
+ # raw_images =[Image.open(dataBytesIO)]
51
+ # logging.warning(f"----raw_images----0--- {str(raw_images)}")
52
  # Check if any images were successfully decoded
53
  if not raw_images:
54
  print("No valid images found.")