Spaces:
Runtime error
Runtime error
added error status
Browse files
app.py
CHANGED
|
@@ -1,102 +1,36 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
-
|
| 6 |
io1 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_en-hk")
|
| 7 |
io2 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_hk-en")
|
| 8 |
io3 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_en-hk")
|
| 9 |
io4 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_hk-en")
|
| 10 |
|
| 11 |
def inference(audio, model):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
}
|
| 35 |
-
.dark input[type='range'] {
|
| 36 |
-
accent-color: #dfdfdf;
|
| 37 |
-
}
|
| 38 |
-
.container {
|
| 39 |
-
max-width: 730px;
|
| 40 |
-
margin: auto;
|
| 41 |
-
padding-top: 1.5rem;
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
.details:hover {
|
| 45 |
-
text-decoration: underline;
|
| 46 |
-
}
|
| 47 |
-
.gr-button {
|
| 48 |
-
white-space: nowrap;
|
| 49 |
-
}
|
| 50 |
-
.gr-button:focus {
|
| 51 |
-
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
| 52 |
-
outline: none;
|
| 53 |
-
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
| 54 |
-
--tw-border-opacity: 1;
|
| 55 |
-
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
| 56 |
-
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
| 57 |
-
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
| 58 |
-
--tw-ring-opacity: .5;
|
| 59 |
-
}
|
| 60 |
-
.footer {
|
| 61 |
-
margin-bottom: 45px;
|
| 62 |
-
margin-top: 35px;
|
| 63 |
-
text-align: center;
|
| 64 |
-
border-bottom: 1px solid #e5e5e5;
|
| 65 |
-
}
|
| 66 |
-
.footer>p {
|
| 67 |
-
font-size: .8rem;
|
| 68 |
-
display: inline-block;
|
| 69 |
-
padding: 0 10px;
|
| 70 |
-
transform: translateY(10px);
|
| 71 |
-
background: white;
|
| 72 |
-
}
|
| 73 |
-
.dark .footer {
|
| 74 |
-
border-color: #303030;
|
| 75 |
-
}
|
| 76 |
-
.dark .footer>p {
|
| 77 |
-
background: #0b0f19;
|
| 78 |
-
}
|
| 79 |
-
.prompt h4{
|
| 80 |
-
margin: 1.25em 0 .25em 0;
|
| 81 |
-
font-weight: bold;
|
| 82 |
-
font-size: 115%;
|
| 83 |
-
}
|
| 84 |
-
.animate-spin {
|
| 85 |
-
animation: spin 1s linear infinite;
|
| 86 |
-
}
|
| 87 |
-
@keyframes spin {
|
| 88 |
-
from {
|
| 89 |
-
transform: rotate(0deg);
|
| 90 |
-
}
|
| 91 |
-
to {
|
| 92 |
-
transform: rotate(360deg);
|
| 93 |
-
}
|
| 94 |
-
}
|
| 95 |
-
"""
|
| 96 |
-
|
| 97 |
-
block = gr.Blocks(css=css)
|
| 98 |
-
|
| 99 |
|
|
|
|
| 100 |
|
| 101 |
with block:
|
| 102 |
gr.HTML(
|
|
@@ -128,10 +62,11 @@ with block:
|
|
| 128 |
)
|
| 129 |
|
| 130 |
btn = gr.Button("Submit")
|
| 131 |
-
model = gr.Dropdown(choices=["
|
| 132 |
out = gr.Audio(label="Output")
|
|
|
|
| 133 |
|
| 134 |
-
btn.click(inference, inputs=[audio, model], outputs=out)
|
| 135 |
gr.HTML('''
|
| 136 |
<div class="footer">
|
| 137 |
<p>Model by <a href="https://ai.facebook.com/" style="text-decoration: underline;" target="_blank">Meta AI</a>
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
|
|
|
|
| 4 |
io1 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_en-hk")
|
| 5 |
io2 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_hk-en")
|
| 6 |
io3 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_en-hk")
|
| 7 |
io4 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_hk-en")
|
| 8 |
|
| 9 |
def inference(audio, model):
|
| 10 |
+
try:
|
| 11 |
+
if not audio:
|
| 12 |
+
raise ValueError("No audio input provided")
|
| 13 |
+
|
| 14 |
+
if model == "xm_transformer_s2ut_en-hk":
|
| 15 |
+
out_audio = io1(audio)
|
| 16 |
+
elif model == "xm_transformer_s2ut_hk-en":
|
| 17 |
+
out_audio = io2(audio)
|
| 18 |
+
elif model == "xm_transformer_unity_en-hk":
|
| 19 |
+
out_audio = io3(audio)
|
| 20 |
+
elif model == "xm_transformer_unity_hk-en":
|
| 21 |
+
out_audio = io4(audio)
|
| 22 |
+
else:
|
| 23 |
+
raise ValueError(f"Unsupported model: {model}")
|
| 24 |
+
|
| 25 |
+
if not out_audio:
|
| 26 |
+
raise ValueError("Model failed to generate output")
|
| 27 |
+
|
| 28 |
+
return out_audio, "Success"
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print(f"Error during inference: {str(e)}")
|
| 31 |
+
return None, str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
block = gr.Blocks()
|
| 34 |
|
| 35 |
with block:
|
| 36 |
gr.HTML(
|
|
|
|
| 62 |
)
|
| 63 |
|
| 64 |
btn = gr.Button("Submit")
|
| 65 |
+
model = gr.Dropdown(choices=["xm_transformer_s2ut_en-hk", "xm_transformer_s2ut_hk-en"], value="xm_transformer_s2ut_en-hk", type="value", label="Model")
|
| 66 |
out = gr.Audio(label="Output")
|
| 67 |
+
status = gr.Textbox(label="Status", interactive=False)
|
| 68 |
|
| 69 |
+
btn.click(inference, inputs=[audio, model], outputs=[out, status], api_name="inference")
|
| 70 |
gr.HTML('''
|
| 71 |
<div class="footer">
|
| 72 |
<p>Model by <a href="https://ai.facebook.com/" style="text-decoration: underline;" target="_blank">Meta AI</a>
|