handler.py
Browse files- handler.py +24 -0
handler.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, Any
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
|
5 |
+
class EndpointHandler:
|
6 |
+
def __init__(self, path=""):
|
7 |
+
self.pipeline = pipeline("text-classification",model=path)
|
8 |
+
|
9 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
10 |
+
"""
|
11 |
+
data args:
|
12 |
+
inputs (:obj: `str`)
|
13 |
+
Return:
|
14 |
+
A :obj:`list` | `dict`: will be serialized and returned
|
15 |
+
"""
|
16 |
+
# get inputs
|
17 |
+
inputs = data.pop("inputs",data)
|
18 |
+
|
19 |
+
# run normal prediction
|
20 |
+
prediction = self.pipeline(inputs)
|
21 |
+
return {
|
22 |
+
"inputs": inputs,
|
23 |
+
"outputs": prediction
|
24 |
+
}
|