Update handler.py
Browse files- handler.py +6 -13
handler.py
CHANGED
@@ -21,22 +21,15 @@ class EndpointHandler():
|
|
21 |
|
22 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
23 |
logging.error(f"----------This is an error message")
|
24 |
-
#logging.critical('-------------------This is a critical message')
|
25 |
-
print("000000--",type(data))
|
26 |
-
#logging.warning('--------This is a warning message')
|
27 |
-
print("input data is here------------",data)
|
28 |
input_data = data.get("inputs", {})
|
29 |
-
logging.warning(
|
30 |
-
print("input data is here-2-----------",type(input_data))
|
31 |
encoded_images = input_data.get("images")
|
32 |
-
logging.warning(f"---encoded_images-----
|
33 |
-
print("input encoded_images is here------------",type(encoded_images))
|
34 |
if not encoded_images:
|
|
|
35 |
return {"captions": [], "error": "No images provided"}
|
36 |
-
|
37 |
-
#texts = input_data.get("texts", ["a photography of"] * len(encoded_images))
|
38 |
-
|
39 |
try:
|
|
|
40 |
byteImgIO = io.BytesIO()
|
41 |
|
42 |
byteImg = Image.open(encoded_images[0])
|
@@ -48,7 +41,7 @@ class EndpointHandler():
|
|
48 |
# Non test code
|
49 |
dataBytesIO = io.BytesIO(byteImg)
|
50 |
raw_images =[Image.open(dataBytesIO)]
|
51 |
-
logging.warning(f"----raw_images----
|
52 |
# Check if any images were successfully decoded
|
53 |
if not raw_images:
|
54 |
print("No valid images found.")
|
@@ -63,7 +56,7 @@ class EndpointHandler():
|
|
63 |
out = self.model.generate(**processed_inputs)
|
64 |
|
65 |
captions = self.processor.batch_decode(out, skip_special_tokens=True)
|
66 |
-
logging.warning(f"----captions----
|
67 |
print("caption is here-------",captions)
|
68 |
return {"captions": captions}
|
69 |
except Exception as e:
|
|
|
21 |
|
22 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
23 |
logging.error(f"----------This is an error message")
|
|
|
|
|
|
|
|
|
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 encoded_images:
|
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(encoded_images)}")
|
33 |
byteImgIO = io.BytesIO()
|
34 |
|
35 |
byteImg = Image.open(encoded_images[0])
|
|
|
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.")
|
|
|
56 |
out = self.model.generate(**processed_inputs)
|
57 |
|
58 |
captions = self.processor.batch_decode(out, skip_special_tokens=True)
|
59 |
+
logging.warning(f"----captions---- {str(captions)}")
|
60 |
print("caption is here-------",captions)
|
61 |
return {"captions": captions}
|
62 |
except Exception as e:
|