getting closer
Browse files- handler.py +10 -11
handler.py
CHANGED
@@ -20,21 +20,20 @@ class EndpointHandler():
|
|
20 |
def __call__(self, data):
|
21 |
try:
|
22 |
|
23 |
-
|
24 |
text_input = None
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
|
31 |
if image_data is not None:
|
32 |
-
|
33 |
-
|
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)
|