Pengwei Li
commited on
Commit
·
3d50426
1
Parent(s):
bab8242
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install gradio==2.8.0b2")
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
title = "fairseq S2S"
|
7 |
+
|
8 |
+
description = "Gradio Demo for fairseq S2S: speech-to-speech translation models. To use it, simply add your audio, or click one of the examples to load them. Read more at the links below."
|
9 |
+
|
10 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2010.05171' target='_blank'>fairseq S2T: Fast Speech-to-Text Modeling with fairseq</a> | <a href='https://github.com/pytorch/fairseq/tree/main/examples/speech_to_text' target='_blank'>Github Repo</a></p>"
|
11 |
+
|
12 |
+
examples = [
|
13 |
+
["common_voice_es_en.flac","xm_transformer_600m-es_en-multi_domain"],
|
14 |
+
["common_voice_ru_18945535.flac","xm_transformer_600m-ru_en-multi_domain"],
|
15 |
+
["common_voice_fr_19731305.mp3","xm_transformer_600m-fr_en-multi_domain"],
|
16 |
+
["common_voice_en_ru.mp3","xm_transformer_600m-en_ru-multi_domain"],
|
17 |
+
["common_voice_en_es.mp3","xm_transformer_600m-en_es-multi_domain"],
|
18 |
+
["common_voice_en_ar.mp3","xm_transformer_600m-en_ar-multi_domain"],
|
19 |
+
["common_voice_en_tr.mp3","xm_transformer_600m-en_tr-multi_domain"],
|
20 |
+
["common_voice_en_fr.mp3","xm_transformer_600m-en_fr-multi_domain"],
|
21 |
+
["common_voice_en_vi.mp3","xm_transformer_600m-en_vi-multi_domain"],
|
22 |
+
]
|
23 |
+
|
24 |
+
io1 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-es_en-multi_domain")
|
25 |
+
|
26 |
+
io2 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-ru_en-multi_domain")
|
27 |
+
|
28 |
+
io3 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-en_ru-multi_domain")
|
29 |
+
|
30 |
+
io4 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-en_es-multi_domain")
|
31 |
+
|
32 |
+
io5 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-en_zh-multi_domain")
|
33 |
+
|
34 |
+
io6 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-fr_en-multi_domain")
|
35 |
+
|
36 |
+
io7 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-en_ar-multi_domain")
|
37 |
+
|
38 |
+
io8 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-en_tr-multi_domain")
|
39 |
+
|
40 |
+
io9 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-en_fr-multi_domain")
|
41 |
+
|
42 |
+
io10 = gr.Interface.load("huggingface/facebook/xm_transformer_600m-en_vi-multi_domain")
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
def inference(text,model):
|
50 |
+
if model == "xm_transformer_600m-es_en-multi_domain":
|
51 |
+
outtext = io1(text)
|
52 |
+
elif model == "xm_transformer_600m-ru_en-multi_domain":
|
53 |
+
outtext = io2(text)
|
54 |
+
elif model == "xm_transformer_600m-en_ru-multi_domain":
|
55 |
+
outtext = io3(text)
|
56 |
+
elif model == "xm_transformer_600m-en_es-multi_domain":
|
57 |
+
outtext = io4(text)
|
58 |
+
elif model == "xm_transformer_600m-en_zh-multi_domain":
|
59 |
+
outtext = io5(text)
|
60 |
+
elif model == "xm_transformer_600m-fr_en-multi_domain":
|
61 |
+
outtext = io6(text)
|
62 |
+
elif model == "xm_transformer_600m-en_ar-multi_domain":
|
63 |
+
outtext = io7(text)
|
64 |
+
elif model == "xm_transformer_600m-en_tr-multi_domain":
|
65 |
+
outtext = io8(text)
|
66 |
+
elif model == "xm_transformer_600m-en_fr-multi_domain":
|
67 |
+
outtext = io9(text)
|
68 |
+
else:
|
69 |
+
outtext = io10(text)
|
70 |
+
return outtext
|
71 |
+
|
72 |
+
|
73 |
+
gr.Interface(
|
74 |
+
inference,
|
75 |
+
[gr.inputs.Audio(label="Input",type="filepath"),gr.inputs.Dropdown(choices=["xm_transformer_600m-es_en-multi_domain","xm_transformer_600m-ru_en-multi_domain","xm_transformer_600m-en_ru-multi_domain","xm_transformer_600m-en_es-multi_domain","xm_transformer_600m-fr_en-multi_domain","xm_transformer_600m-en_ar-multi_domain","xm_transformer_600m-en_tr-multi_domain","xm_transformer_600m-en_fr-multi_domain","xm_transformer_600m-en_vi-multi_domain"], type="value", default="xm_transformer_600m-es_en-multi_domain", label="model")
|
76 |
+
],
|
77 |
+
gr.outputs.Audio(label="Output"),
|
78 |
+
article=article,
|
79 |
+
title=title,
|
80 |
+
examples=examples,
|
81 |
+
description=description).launch(enable_queue=True,cache_examples=False)
|