more debugging
Browse files- handler.py +11 -2
handler.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
from io import BytesIO
|
2 |
import base64
|
3 |
import traceback
|
|
|
4 |
|
5 |
from PIL import Image
|
6 |
import torch
|
7 |
from transformers import CLIPProcessor, CLIPTextModel, CLIPVisionModelWithProjection
|
8 |
|
9 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
|
|
|
10 |
|
11 |
class EndpointHandler():
|
12 |
def __init__(self, path=""):
|
@@ -17,9 +20,11 @@ class EndpointHandler():
|
|
17 |
def __call__(self, data):
|
18 |
try:
|
19 |
|
|
|
20 |
text_input = None
|
21 |
if isinstance(data, dict):
|
22 |
print('data is a dict: ', data)
|
|
|
23 |
inputs = data.pop("inputs", None)
|
24 |
text_input = inputs["text"] if "text" in inputs else None
|
25 |
image_data = BytesIO(base64.b64decode(inputs['image'])) if 'image' in inputs else None
|
@@ -39,5 +44,9 @@ class EndpointHandler():
|
|
39 |
return {'embeddings':self.image_model(**processor).image_embeds.tolist()[0]}
|
40 |
else:
|
41 |
return {'embeddings':None}
|
42 |
-
except Exception:
|
43 |
-
|
|
|
|
|
|
|
|
|
|
1 |
from io import BytesIO
|
2 |
import base64
|
3 |
import traceback
|
4 |
+
import logging
|
5 |
|
6 |
from PIL import Image
|
7 |
import torch
|
8 |
from transformers import CLIPProcessor, CLIPTextModel, CLIPVisionModelWithProjection
|
9 |
|
10 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
11 |
+
logger = logging.getLogger(__name__)
|
12 |
+
logger.setLevel('INFO')
|
13 |
|
14 |
class EndpointHandler():
|
15 |
def __init__(self, path=""):
|
|
|
20 |
def __call__(self, data):
|
21 |
try:
|
22 |
|
23 |
+
logger.info('data is %s', data)
|
24 |
text_input = None
|
25 |
if isinstance(data, dict):
|
26 |
print('data is a dict: ', data)
|
27 |
+
logger.info('data is a dict %s', data)
|
28 |
inputs = data.pop("inputs", None)
|
29 |
text_input = inputs["text"] if "text" in inputs else None
|
30 |
image_data = BytesIO(base64.b64decode(inputs['image'])) if 'image' in inputs else None
|
|
|
44 |
return {'embeddings':self.image_model(**processor).image_embeds.tolist()[0]}
|
45 |
else:
|
46 |
return {'embeddings':None}
|
47 |
+
except Exception as ex:
|
48 |
+
logger.error('error doing request: %s', ex)
|
49 |
+
logger.exception(ex)
|
50 |
+
stack_info = traceback.format_exc()
|
51 |
+
logger.error('stack trace:\n%s',stack_info)
|
52 |
+
return {'Error':stack_info}
|