apenasissso commited on
Commit
5210503
1 Parent(s): d771b53

handler.py

Browse files
Files changed (1) hide show
  1. handler.py +24 -0
handler.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from speechbrain.pretrained import EncoderClassifier
2
+ from typing import Dict, List, Any
3
+
4
+
5
+ class EndpointHandler:
6
+ def __init__(self, path=""):
7
+ self.model = EncoderClassifier.from_hparams(".")
8
+
9
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
10
+ """
11
+ data args:
12
+ inputs (:obj: `str`)
13
+ date (:obj: `str`)
14
+ Return:
15
+ A :obj:`list` | `dict`: will be serialized and returned
16
+ """
17
+ # get inputs
18
+ audio_url = data.pop("audio_url", data)
19
+
20
+ # check if date exists and if it is a holiday
21
+ # run normal prediction
22
+ output = self.model.classify_file(audio_url)
23
+ return {"prediction": output[1].exp()}
24
+