artificial-feelings
commited on
Commit
·
96937e3
1
Parent(s):
73419ab
Upload handler.py
Browse files- handler.py +8 -13
handler.py
CHANGED
@@ -1,27 +1,22 @@
|
|
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 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
speech_values = self.model.generate(**inputs, do_sample=True)
|
25 |
-
|
|
|
26 |
|
27 |
-
return (
|
|
|
1 |
from transformers import AutoProcessor, AutoModel
|
2 |
|
|
|
3 |
class EndpointHandler():
|
4 |
def __init__(self, path=""):
|
5 |
self.processor = AutoProcessor.from_pretrained(path)
|
6 |
self.model = AutoModel.from_pretrained(path)
|
7 |
|
8 |
def __call__(self, data): #-> List[Dict[str, Any]]
|
9 |
+
|
|
|
|
|
|
|
|
|
|
|
10 |
# get inputs
|
11 |
input_text = data['inputs']
|
12 |
|
13 |
inputs = self.processor(
|
14 |
+
text=input_text,
|
15 |
+
return_tensors="pt",
|
16 |
+
voice_preset = "v2/en_speaker_6"
|
17 |
+
)
|
18 |
speech_values = self.model.generate(**inputs, do_sample=True)
|
19 |
+
sample_rate = self.model.generation_config.sample_rate
|
20 |
+
|
21 |
|
22 |
+
return {'audio': speech_values.tolist(), 'sample_rate': sample_rate}
|