Updated handler.py
Browse files- handler.py +3 -5
handler.py
CHANGED
@@ -4,7 +4,7 @@ from transformers import Blip2Processor, Blip2ForConditionalGeneration
|
|
4 |
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
-
import torch,
|
8 |
|
9 |
|
10 |
class EndpointHandler:
|
@@ -25,13 +25,11 @@ class EndpointHandler:
|
|
25 |
A :obj:`dict`:. The object returned should be a dict of one list like {"captions": ["A hugging face at the office"]} containing :
|
26 |
- "caption": A string corresponding to the generated caption.
|
27 |
"""
|
28 |
-
|
29 |
-
inputs = data["inputs"]
|
30 |
# parameters = data.pop("parameters", {})
|
31 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
32 |
|
33 |
-
|
34 |
-
|
35 |
|
36 |
raw_images = Image.open(BytesIO(inputs))
|
37 |
|
|
|
4 |
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
+
import torch, re, base64
|
8 |
|
9 |
|
10 |
class EndpointHandler:
|
|
|
25 |
A :obj:`dict`:. The object returned should be a dict of one list like {"captions": ["A hugging face at the office"]} containing :
|
26 |
- "caption": A string corresponding to the generated caption.
|
27 |
"""
|
|
|
|
|
28 |
# parameters = data.pop("parameters", {})
|
29 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
30 |
|
31 |
+
|
32 |
+
inputs = base64.b64decode(re.sub('^data:image/.+;base64,', '', data['inputs']))
|
33 |
|
34 |
raw_images = Image.open(BytesIO(inputs))
|
35 |
|