kobesar commited on
Commit
487fb51
·
1 Parent(s): df58ec8

Upload handler.py

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