Thiago Hersan
commited on
Commit
β’
3977b82
1
Parent(s):
64212bb
combine pt and en into one gradio
Browse files- .gitignore +2 -0
- README.md +3 -5
- app.py +38 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.ipynb_checkpoints/
|
2 |
+
|
README.md
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: blue
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: mms-tts-eng gradio
|
3 |
+
emoji: ππ¬
|
4 |
colorFrom: blue
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.42.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
pipeline_en = pipeline(task="text-to-speech", model="facebook/mms-tts-eng")
|
7 |
+
pipeline_pt = pipeline(task="text-to-speech", model="facebook/mms-tts-por")
|
8 |
+
|
9 |
+
def tts(lang):
|
10 |
+
pipeline = pipeline_en if lang == "en" else pipeline_pt
|
11 |
+
def tts_lang(txt):
|
12 |
+
res = pipeline(txt)
|
13 |
+
audio = (res['audio'].reshape(-1) * 2 ** 15).astype(np.int16)
|
14 |
+
return res['sampling_rate'], audio
|
15 |
+
return tts_lang
|
16 |
+
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
gr.Interface(
|
19 |
+
tts("en"),
|
20 |
+
inputs=gr.Textbox(
|
21 |
+
lines=1,
|
22 |
+
value="one two three four",
|
23 |
+
),
|
24 |
+
outputs="audio",
|
25 |
+
)
|
26 |
+
|
27 |
+
gr.Interface(
|
28 |
+
tts("pt"),
|
29 |
+
inputs=gr.Textbox(
|
30 |
+
lines=1,
|
31 |
+
value="um dois tres quatro",
|
32 |
+
),
|
33 |
+
outputs="audio",
|
34 |
+
)
|
35 |
+
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers==4.37.2
|