Spaces:
Runtime error
Runtime error
| import os | |
| os.system("pip install gradio==3.3") | |
| import gradio as gr | |
| import numpy as np | |
| import streamlit as st | |
| title = "Fairseq Speech to Speech Translation" | |
| description = "Gradio Demo for fairseq S2S: speech-to-speech translation models. To use it, simply record your audio. Read more at the links below." | |
| article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2107.05604' target='_blank'>Direct speech-to-speech translation with discrete units</a> | <a href='https://github.com/facebookresearch/fairseq/tree/main/examples/speech_to_speech' target='_blank'>Github Repo</a></p>" | |
| examples = [ | |
| ["enhanced_direct_s2st_units_audios_es-en_set2_source_12478_cv.flac","xm_transformer_s2ut_800m-es-en-st-asr-bt_h1_2022"], | |
| ] | |
| io1 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_en-hk", api_key=st.secrets["api_key"]) | |
| io2 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_hk-en", api_key=st.secrets["api_key"]) | |
| io3 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_en-hk", api_key=st.secrets["api_key"]) | |
| io4 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_hk-en", api_key=st.secrets["api_key"]) | |
| def inference(audio, model): | |
| if model == "xm_transformer_s2ut_en-hk": | |
| out_audio = io1(audio) | |
| elif model == "xm_transformer_s2ut_hk-en": | |
| out_audio = io2(audio) | |
| elif model == "xm_transformer_unity_en-hk": | |
| out_audio = io3(audio) | |
| else: | |
| out_audio = io4(audio) | |
| return out_audio | |
| gr.Interface( | |
| inference, | |
| [gr.inputs.Audio(source="microphone", type="filepath", label="Input"),gr.inputs.Dropdown(choices=["xm_transformer_s2ut_en-hk", "xm_transformer_s2ut_hk-en", "xm_transformer_unity_en-hk", "xm_transformer_unity_en-hk"], default="xm_transformer_s2ut_en-hk",type="value", label="Model") | |
| ], | |
| gr.outputs.Audio(label="Output"), | |
| article=article, | |
| title=title, | |
| description=description).queue().launch() |