Update handler.py
Browse files- handler.py +31 -16
handler.py
CHANGED
@@ -34,22 +34,37 @@ class EndpointHandler():
|
|
34 |
# image: await (await fetch('https://placekitten.com/300/300')).blob()
|
35 |
# }
|
36 |
# })
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
#
|
41 |
-
|
42 |
-
#
|
43 |
-
#
|
44 |
-
#
|
45 |
-
# image = Image.open(BytesIO(base64.b64decode(imageBase64)))
|
46 |
-
|
47 |
-
# except:
|
48 |
-
image_url = inputs['image']
|
49 |
-
image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
|
50 |
-
|
51 |
-
question = inputs["question"]
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
# data = data.pop("inputs", data)
|
54 |
# data = data.pop("image", image)
|
55 |
|
@@ -71,7 +86,7 @@ class EndpointHandler():
|
|
71 |
|
72 |
|
73 |
prompt = f"Question: {question}, Answer:"
|
74 |
-
processed = self.processor(images=image, text=prompt, return_tensors="pt")
|
75 |
|
76 |
# answer = self._generate_answer(
|
77 |
# model_path, prompt, image,
|
|
|
34 |
# image: await (await fetch('https://placekitten.com/300/300')).blob()
|
35 |
# }
|
36 |
# })
|
37 |
+
###################
|
38 |
+
inputs = data.get("inputs")
|
39 |
+
imageBase64 = inputs.get("image")
|
40 |
+
# imageURL = inputs.get("image")
|
41 |
+
question = inputs.get("question")
|
42 |
+
# print(imageURL)
|
43 |
+
# print(text)
|
44 |
+
# image = Image.open(requests.get(imageBase64, stream=True).raw)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
image = Image.open(BytesIO(base64.b64decode(imageBase64.split(",")[1].encode())))
|
47 |
+
###################
|
48 |
+
|
49 |
+
######################################
|
50 |
+
|
51 |
+
# inputs = data.pop("inputs", data)
|
52 |
+
# parameters = data.pop("parameters", {})
|
53 |
+
# # if isinstance(inputs, Image.Image):
|
54 |
+
# # image = [inputs]
|
55 |
+
# # else:
|
56 |
+
# # try:
|
57 |
+
# # imageBase64 = inputs["image"]
|
58 |
+
# # # image = Image.open(BytesIO(base64.b64decode(imageBase64.split(",")[1].encode())))
|
59 |
+
# # image = Image.open(BytesIO(base64.b64decode(imageBase64)))
|
60 |
+
|
61 |
+
# # except:
|
62 |
+
# image_url = inputs['image']
|
63 |
+
# image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
|
64 |
+
|
65 |
+
|
66 |
+
# question = inputs["question"]
|
67 |
+
######################################
|
68 |
# data = data.pop("inputs", data)
|
69 |
# data = data.pop("image", image)
|
70 |
|
|
|
86 |
|
87 |
|
88 |
prompt = f"Question: {question}, Answer:"
|
89 |
+
processed = self.processor(images=image, text=prompt, return_tensors="pt")#.to(self.device)
|
90 |
|
91 |
# answer = self._generate_answer(
|
92 |
# model_path, prompt, image,
|