farquasar commited on
Commit
d63155f
1 Parent(s): a610c96

Create handler.py

Browse files
Files changed (1) hide show
  1. handler.py +26 -0
handler.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("automatic-speech-recognition",
7
+ model=path,
8
+ chunk_length_s = 30 ,
9
+ stride_length_s = (3, 0),
10
+ generate_kwargs = {"language":"pt"} ,
11
+ device = 0
12
+ )
13
+
14
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
15
+ """
16
+ data args:
17
+ inputs (:obj: `str`)
18
+ date (:obj: `str`)
19
+ Return:
20
+ A :obj:`list` | `dict`: will be serialized and returned
21
+ """
22
+ # get inputs
23
+ inputs = data.pop("inputs",data)
24
+ # run normal prediction
25
+ prediction = self.pipeline(inputs)
26
+ return prediction