Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,11 +14,13 @@ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
|
14 |
speaker_embeddings = {
|
15 |
"BDL": "spkemb/cmu_us_bdl_arctic-wav-arctic_a0009.npy",
|
16 |
"CLB": "spkemb/cmu_us_clb_arctic-wav-arctic_a0144.npy",
|
|
|
|
|
17 |
"SLT": "spkemb/cmu_us_slt_arctic-wav-arctic_a0508.npy",
|
18 |
}
|
19 |
|
20 |
def getNews(search_key):
|
21 |
-
return requests.get ("https://newsapi.org/v2/everything?q=" +search_key+ "&
|
22 |
# return requests.get ("https://newsapi.org/v2/top-headlines?country=us&apiKey=3bca07c913ec4703a23f6ba03e15b30b").content.decode("utf-8" )
|
23 |
|
24 |
def getHeadlines():
|
@@ -29,18 +31,18 @@ def predict(text, speaker):
|
|
29 |
if len(text.strip()) == 0:
|
30 |
return (16000, np.zeros(0).astype(np.int16))
|
31 |
|
32 |
-
#
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
inputs = processor(text=getNews(text),
|
37 |
-
return_tensors="pt")
|
38 |
|
39 |
# limit input length
|
40 |
input_ids = inputs["input_ids"]
|
41 |
input_ids = input_ids[..., :model.config.max_text_positions]
|
|
|
42 |
|
43 |
-
speaker_embedding = np.load(
|
|
|
44 |
speaker_embedding = torch.tensor(speaker_embedding).unsqueeze(0)
|
45 |
|
46 |
speech = model.generate_speech(input_ids, speaker_embedding, vocoder=vocoder)
|
@@ -72,17 +74,29 @@ examples = [
|
|
72 |
["It is not in the stars to hold our destiny but in ourselves.", "BDL (male)"],
|
73 |
["The octopus and Oliver went to the opera in October.", "CLB (female)"],
|
74 |
["She sells seashells by the seashore. I saw a kitten eating chicken in the kitchen.", "RMS (male)"],
|
|
|
|
|
75 |
["How much wood would a woodchuck chuck if a woodchuck could chuck wood? He would chuck, he would, as much as he could, and chuck as much wood as a woodchuck would if a woodchuck could chuck wood.", "CLB (female)"],
|
76 |
]
|
77 |
|
78 |
gr.Interface(
|
79 |
fn=predict,
|
80 |
inputs=[
|
81 |
-
gr.Text(label="
|
82 |
-
gr.Radio(label="
|
83 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
"Technology",
|
85 |
-
"Politics",
|
86 |
"KPop",
|
87 |
"Surprise Me!"
|
88 |
],
|
@@ -96,3 +110,6 @@ gr.Interface(
|
|
96 |
article=article,
|
97 |
examples=examples,
|
98 |
).launch()
|
|
|
|
|
|
|
|
14 |
speaker_embeddings = {
|
15 |
"BDL": "spkemb/cmu_us_bdl_arctic-wav-arctic_a0009.npy",
|
16 |
"CLB": "spkemb/cmu_us_clb_arctic-wav-arctic_a0144.npy",
|
17 |
+
"KSP": "spkemb/cmu_us_ksp_arctic-wav-arctic_b0087.npy",
|
18 |
+
"RMS": "spkemb/cmu_us_rms_arctic-wav-arctic_b0353.npy",
|
19 |
"SLT": "spkemb/cmu_us_slt_arctic-wav-arctic_a0508.npy",
|
20 |
}
|
21 |
|
22 |
def getNews(search_key):
|
23 |
+
return requests.get ("https://newsapi.org/v2/everything?q=" +search_key+ "&pagesize=3&apiKey=3bca07c913ec4703a23f6ba03e15b30b").content.decode("utf-8")
|
24 |
# return requests.get ("https://newsapi.org/v2/top-headlines?country=us&apiKey=3bca07c913ec4703a23f6ba03e15b30b").content.decode("utf-8" )
|
25 |
|
26 |
def getHeadlines():
|
|
|
31 |
if len(text.strip()) == 0:
|
32 |
return (16000, np.zeros(0).astype(np.int16))
|
33 |
|
34 |
+
# text = getNews ()
|
35 |
+
# inputs = processor(text=text, return_tensors="pt")
|
36 |
+
inputs = processor(text=getNews(text),
|
37 |
+
return_tensors="pt")
|
|
|
|
|
38 |
|
39 |
# limit input length
|
40 |
input_ids = inputs["input_ids"]
|
41 |
input_ids = input_ids[..., :model.config.max_text_positions]
|
42 |
+
|
43 |
|
44 |
+
speaker_embedding = np.load(speaker_embeddings[speaker[:3]])
|
45 |
+
|
46 |
speaker_embedding = torch.tensor(speaker_embedding).unsqueeze(0)
|
47 |
|
48 |
speech = model.generate_speech(input_ids, speaker_embedding, vocoder=vocoder)
|
|
|
74 |
["It is not in the stars to hold our destiny but in ourselves.", "BDL (male)"],
|
75 |
["The octopus and Oliver went to the opera in October.", "CLB (female)"],
|
76 |
["She sells seashells by the seashore. I saw a kitten eating chicken in the kitchen.", "RMS (male)"],
|
77 |
+
["Brisk brave brigadiers brandished broad bright blades, blunderbusses, and bludgeons—balancing them badly.", "SLT (female)"],
|
78 |
+
["A synonym for cinnamon is a cinnamon synonym.", "BDL (male)"],
|
79 |
["How much wood would a woodchuck chuck if a woodchuck could chuck wood? He would chuck, he would, as much as he could, and chuck as much wood as a woodchuck would if a woodchuck could chuck wood.", "CLB (female)"],
|
80 |
]
|
81 |
|
82 |
gr.Interface(
|
83 |
fn=predict,
|
84 |
inputs=[
|
85 |
+
gr.Text(label="Input Text"),
|
86 |
+
gr.Radio(label="Speaker", choices=[
|
87 |
+
"BDL (male)",
|
88 |
+
"CLB (female)",
|
89 |
+
"KSP (male)",
|
90 |
+
"RMS (male)",
|
91 |
+
"SLT (female)",
|
92 |
+
"Surprise Me!"
|
93 |
+
],
|
94 |
+
value="BDL (male)"),
|
95 |
+
|
96 |
+
gr.Radio(label="Preset", choices=[
|
97 |
+
"US",
|
98 |
+
"International",
|
99 |
"Technology",
|
|
|
100 |
"KPop",
|
101 |
"Surprise Me!"
|
102 |
],
|
|
|
110 |
article=article,
|
111 |
examples=examples,
|
112 |
).launch()
|
113 |
+
|
114 |
+
|
115 |
+
|