Spaces:
Runtime error
Runtime error
migrate to blocks from interface (#1)
Browse files- migrate to blocks from interface (4c5e0a85807d2b0d947b016e572f97fb029da116)
Co-authored-by: Ahsen Khaliq <akhaliq@users.noreply.huggingface.co>
app.py
CHANGED
@@ -1,23 +1,12 @@
|
|
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 = "Hokkien Translation"
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
examples = [
|
14 |
-
["enhanced_direct_s2st_units_audios_es-en_set2_source_12478_cv.flac","xm_transformer_s2ut_800m-es-en-st-asr-bt_h1_2022"],
|
15 |
-
]
|
16 |
-
|
17 |
-
io1 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_en-hk", api_key=st.secrets["api_key"])
|
18 |
-
io2 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_hk-en", api_key=st.secrets["api_key"])
|
19 |
-
io3 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_en-hk", api_key=st.secrets["api_key"])
|
20 |
-
io4 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_hk-en", api_key=st.secrets["api_key"])
|
21 |
|
22 |
def inference(audio, model):
|
23 |
if model == "xm_transformer_s2ut_en-hk":
|
@@ -30,12 +19,124 @@ def inference(audio, model):
|
|
30 |
out_audio = io4(audio)
|
31 |
return out_audio
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
inference,
|
36 |
-
[gr.inputs.Audio(source="microphone", type="filepath", label="Input"),gr.inputs.Dropdown(choices=["xm_transformer_unity_en-hk", "xm_transformer_unity_hk-en", "xm_transformer_s2ut_en-hk", "xm_transformer_s2ut_hk-en"], default="xm_transformer_unity_en-hk",type="value", label="Model")
|
37 |
-
],
|
38 |
-
gr.outputs.Audio(label="Output"),
|
39 |
-
article=article,
|
40 |
-
title=title,
|
41 |
-
description=description).queue().launch()
|
|
|
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 |
if model == "xm_transformer_s2ut_en-hk":
|
|
|
19 |
out_audio = io4(audio)
|
20 |
return out_audio
|
21 |
|
22 |
+
|
23 |
+
css = """
|
24 |
+
.gradio-container {
|
25 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
26 |
+
}
|
27 |
+
.gr-button {
|
28 |
+
color: white;
|
29 |
+
border-color: black;
|
30 |
+
background: black;
|
31 |
+
}
|
32 |
+
input[type='range'] {
|
33 |
+
accent-color: black;
|
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(
|
103 |
+
"""
|
104 |
+
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
105 |
+
<div
|
106 |
+
style="
|
107 |
+
display: inline-flex;
|
108 |
+
align-items: center;
|
109 |
+
gap: 0.8rem;
|
110 |
+
font-size: 1.75rem;
|
111 |
+
"
|
112 |
+
>
|
113 |
+
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
114 |
+
Hokkien Translation
|
115 |
+
</h1>
|
116 |
+
</div>
|
117 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
118 |
+
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.
|
119 |
+
</p>
|
120 |
+
</div>
|
121 |
+
"""
|
122 |
+
)
|
123 |
+
with gr.Group():
|
124 |
+
with gr.Box():
|
125 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
126 |
+
audio = gr.Audio(
|
127 |
+
source="microphone", type="filepath", label="Input"
|
128 |
+
)
|
129 |
+
|
130 |
+
btn = gr.Button("Submit")
|
131 |
+
model = gr.Dropdown(choices=["xm_transformer_unity_en-hk", "xm_transformer_unity_hk-en", "xm_transformer_s2ut_en-hk", "xm_transformer_s2ut_hk-en"], value="xm_transformer_unity_en-hk",type="value", label="Model")
|
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>
|
138 |
+
</p>
|
139 |
+
</div>
|
140 |
+
''')
|
141 |
|
142 |
+
block.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|