Spaces:
Build error
Build error
app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install gradio==3.3")
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
title = "SpeechMatrix Speech-to-speech Translation"
|
8 |
+
|
9 |
+
description = "Gradio Demo for SpeechMatrix. To use it, simply record your audio, or click the example to load. Read more at the links below. \nNote: These models are trained on SpeechMatrix data only, and meant to serve as a baseline for future research."
|
10 |
+
|
11 |
+
article = "<p style='text-align: center'><a href='https://research.facebook.com/publications/speechmatrix' target='_blank'>SpeechMatrix</a> | <a href='https://github.com/facebookresearch/fairseq/tree/ust' target='_blank'>Github Repo</a></p>"
|
12 |
+
|
13 |
+
SRC_LIST = ['cs', 'de', 'en', 'es', 'et', 'fi', 'fr', 'hr', 'hu', 'it', 'nl', 'pl', 'pt', 'ro', 'sk', 'sl']
|
14 |
+
TGT_LIST = ['en', 'fr', 'es']
|
15 |
+
MODEL_LIST = ['xm_transformer_sm_all-en']
|
16 |
+
for src in SRC_LIST:
|
17 |
+
for tgt in TGT_LIST:
|
18 |
+
if src != tgt:
|
19 |
+
MODEL_LIST.append(f"textless_sm_{src}_{tgt}")
|
20 |
+
|
21 |
+
examples = []
|
22 |
+
|
23 |
+
io_dict = {model: gr.Interface.load(f"huggingface/facebook/{model}", api_key=st.secrets["api_key"]) for model in MODEL_LIST}
|
24 |
+
|
25 |
+
def inference(audio, model):
|
26 |
+
out_audio = io_dict[model](audio)
|
27 |
+
return out_audio
|
28 |
+
gr.Interface(
|
29 |
+
inference,
|
30 |
+
[gr.inputs.Audio(source="microphone", type="filepath", label="Input"),gr.inputs.Dropdown(choices=MODEL_LIST, default="xm_transformer_sm_all-en",type="value", label="Model")
|
31 |
+
],
|
32 |
+
gr.outputs.Audio(label="Output"),
|
33 |
+
article=article,
|
34 |
+
title=title,
|
35 |
+
examples=examples,
|
36 |
+
cache_examples=False,
|
37 |
+
description=description).queue().launch()
|