artificial-feelings commited on
Commit
da51fe7
1 Parent(s): 6ec0fc0

Upload handler.py

Browse files
Files changed (1) hide show
  1. handler.py +27 -0
handler.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoProcessor, AutoModel
2
+
3
+
4
+ class EndpointHandler():
5
+ def __init__(self, path=""):
6
+ self.processor = AutoProcessor.from_pretrained(path)
7
+ self.model = AutoModel.from_pretrained(path)
8
+
9
+ def __call__(self, data): #-> List[Dict[str, Any]]
10
+ """
11
+ data args:
12
+ inputs (:obj: `list`)
13
+ Return:
14
+ A :obj:`np.array' | `int`: will be serialized and returned
15
+ """
16
+ # get inputs
17
+ input_text = data['inputs']
18
+
19
+ inputs = self.processor(
20
+ text=input_text,
21
+ return_tensors="pt",
22
+ voice_preset = "v2/en_speaker_6"
23
+ )
24
+ speech_values = self.model.generate(**inputs, do_sample=True)
25
+ sampling_rate = self.model.generation_config.sample_rate
26
+
27
+ return (speech_values, sampling_rate)