Spaces:
Runtime error
Runtime error
File size: 2,900 Bytes
8d6526d 7745544 8d6526d cd3958e 4d64757 cd3958e 4d64757 cfc4123 4d64757 e06601a 4d64757 cd3958e 4d64757 cd3958e 4d64757 cd3958e 4d64757 8d6526d 4d64757 |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import gradio as gr
import numpy as np
io1 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_en-hk")
io2 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_hk-en")
io3 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_en-hk")
io4 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_hk-en")
def inference(audio, model):
try:
if not audio:
raise ValueError("No audio input provided")
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)
elif model == "xm_transformer_unity_hk-en":
out_audio = io4(audio)
else:
raise ValueError(f"Unsupported model: {model}")
if not out_audio:
raise ValueError("Model failed to generate output")
return out_audio, "Success"
except Exception as e:
print(f"Error during inference: {str(e)}")
return None, str(e)
block = gr.Blocks()
with block:
gr.HTML(
"""
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
<div
style="
display: inline-flex;
align-items: center;
gap: 0.8rem;
font-size: 1.75rem;
"
>
<h1 style="font-weight: 900; margin-bottom: 7px;">
Hokkien Translation
</h1>
</div>
<p style="margin-bottom: 10px; font-size: 94%">
A demo for fairseq speech-to-speech translation models. It supports S2UT and UnitY models for bidirectional Hokkien and English translation. Please select the model and record the input to submit.
</p>
</div>
"""
)
with gr.Group():
with gr.Box():
with gr.Row().style(mobile_collapse=False, equal_height=True):
audio = gr.Audio(
source="microphone", type="filepath", label="Input"
)
btn = gr.Button("Submit")
model = gr.Dropdown(choices=["xm_transformer_s2ut_en-hk", "xm_transformer_s2ut_hk-en"], value="xm_transformer_s2ut_en-hk", type="value", label="Model")
out = gr.Audio(label="Output")
status = gr.Textbox(label="Status", interactive=False)
btn.click(inference, inputs=[audio, model], outputs=[out, status], api_name="inference")
gr.HTML('''
<div class="footer">
<p>Model by <a href="https://ai.facebook.com/" style="text-decoration: underline;" target="_blank">Meta AI</a>
</p>
</div>
''')
block.launch() |