TenzinGayche
commited on
Commit
•
61bebd5
1
Parent(s):
b75453d
Update handler.py
Browse files- handler.py +2 -13
handler.py
CHANGED
@@ -9,15 +9,6 @@ from num2tib.core import convert
|
|
9 |
from num2tib.core import convert2text
|
10 |
import re
|
11 |
converter = pyewts.pyewts()
|
12 |
-
import requests
|
13 |
-
|
14 |
-
def download_file(url, destination):
|
15 |
-
response = requests.get(url)
|
16 |
-
with open(destination, 'wb') as file:
|
17 |
-
file.write(response.content)
|
18 |
-
|
19 |
-
# Example usage:
|
20 |
-
download_file('https://huggingface.co/openpecha/speecht5-tts-01/resolve/main/female_2.npy', 'female_2.npy')
|
21 |
def replace_numbers_with_convert(sentence, wylie=True):
|
22 |
pattern = r'\d+(\.\d+)?'
|
23 |
def replace(match):
|
@@ -36,7 +27,6 @@ speaker_embeddings = {
|
|
36 |
|
37 |
}
|
38 |
|
39 |
-
|
40 |
replacements = [
|
41 |
('_', '_'),
|
42 |
('*', 'v'),
|
@@ -71,10 +61,9 @@ class EndpointHandler():
|
|
71 |
Returns:
|
72 |
bytes: _description_
|
73 |
"""
|
74 |
-
|
75 |
|
76 |
# process input
|
77 |
-
text = data.get("inputs", None)
|
78 |
|
79 |
if len(text.strip()) == 0:
|
80 |
return (16000, np.zeros(0).astype(np.int16))
|
@@ -87,6 +76,6 @@ class EndpointHandler():
|
|
87 |
input_ids = input_ids[..., :self.model.config.max_text_positions]
|
88 |
speaker_embedding = np.load(speaker_embeddings['Lhasa(female)'])
|
89 |
speaker_embedding = torch.tensor(speaker_embedding)
|
90 |
-
speech = self.model.generate_speech(input_ids.to('cuda'), speaker_embedding.to('cuda'), vocoder=vocoder.to('cuda'))
|
91 |
speech = nr.reduce_noise(y=speech.to('cpu'), sr=16000)
|
92 |
return speech.tobytes()
|
|
|
9 |
from num2tib.core import convert2text
|
10 |
import re
|
11 |
converter = pyewts.pyewts()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def replace_numbers_with_convert(sentence, wylie=True):
|
13 |
pattern = r'\d+(\.\d+)?'
|
14 |
def replace(match):
|
|
|
27 |
|
28 |
}
|
29 |
|
|
|
30 |
replacements = [
|
31 |
('_', '_'),
|
32 |
('*', 'v'),
|
|
|
61 |
Returns:
|
62 |
bytes: _description_
|
63 |
"""
|
64 |
+
text = data.pop("inputs",data)
|
65 |
|
66 |
# process input
|
|
|
67 |
|
68 |
if len(text.strip()) == 0:
|
69 |
return (16000, np.zeros(0).astype(np.int16))
|
|
|
76 |
input_ids = input_ids[..., :self.model.config.max_text_positions]
|
77 |
speaker_embedding = np.load(speaker_embeddings['Lhasa(female)'])
|
78 |
speaker_embedding = torch.tensor(speaker_embedding)
|
79 |
+
speech = self.model.generate_speech(input_ids.to('cuda'), speaker_embedding.to('cuda'), vocoder=self.vocoder.to('cuda'))
|
80 |
speech = nr.reduce_noise(y=speech.to('cpu'), sr=16000)
|
81 |
return speech.tobytes()
|