Create handler.py
Browse files- handler.py +26 -0
handler.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
from transformers import pipeline
|
3 |
+
import transformers
|
4 |
+
from PIL import Image
|
5 |
+
import requests
|
6 |
+
|
7 |
+
print('TRANSFORMERS VERSION')
|
8 |
+
print(transformers.__version__)
|
9 |
+
|
10 |
+
class EndpointHandler():
|
11 |
+
def __init__(self, path=""):
|
12 |
+
# load pipe
|
13 |
+
self.pipe = pipeline(task="depth-estimation", model=path)
|
14 |
+
|
15 |
+
|
16 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
17 |
+
# get inputs
|
18 |
+
# image = data.pop("image",data)
|
19 |
+
|
20 |
+
# load image
|
21 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
22 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
23 |
+
|
24 |
+
depth = self.pipe(image)["depth"]
|
25 |
+
|
26 |
+
return depth
|