philschmid commited on
Commit
5627ce8
·
1 Parent(s): eb3cd49

Create new file

Browse files
Files changed (1) hide show
  1. handler.py +22 -0
handler.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ date (: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
+ date = data.pop("date", None)
19
+
20
+ # run normal prediction
21
+ prediction = self.pipeline(inputs)
22
+ return {"inputs": inputs}