File size: 1,999 Bytes
8d6526d
 
 
 
 
 
7b2e534
8d6526d
2d5af26
8d6526d
2d5af26
8d6526d
 
 
 
 
cbca006
 
 
 
8d6526d
 
cbca006
50f34cd
cbca006
50f34cd
cbca006
50f34cd
8d0ad90
50f34cd
8d6526d
 
 
 
 
2d5af26
8d6526d
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
os.system("pip install gradio==3.3")
import gradio as gr
import numpy as np
import streamlit as st

title = "Hokkien Translation"

description = "Gradio Demo for fairseq speech-to-speech translation models. We have S2UT and UnitY models for bidirectional Hokkien and English translation. Please select the model and record your input to try it."

article = "<p style='text-align: center'><a href='https://ai.facebook.com/blog/ai-translation-hokkien/' target='_blank'>Speech-to-speech translation for a real-world unwritten language</a> | <a href='https://github.com/facebookresearch/fairseq/tree/ust/examples/hokkien' 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_unity_en-hk", "xm_transformer_unity_en-hk", "xm_transformer_s2ut_en-hk", "xm_transformer_s2ut_hk-en"], default="xm_transformer_unity_en-hk",type="value", label="Model")
],
    gr.outputs.Audio(label="Output"),
    article=article,
    title=title,
    description=description).queue().launch()