Spaces:
Configuration error
Configuration error
Duplicate from facebook/Hokkien_Translation
Browse filesCo-authored-by: Pengwei Li <lpw@users.noreply.huggingface.co>
- .gitattributes +31 -0
- README.md +12 -0
- app.py +142 -0
.gitattributes
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
23 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Hokkien Translation
|
3 |
+
emoji: 🎙️
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.5
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: cc-by-nc-4.0
|
11 |
+
duplicated_from: facebook/Hokkien_Translation
|
12 |
+
---
|
app.py
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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", api_key=os.environ['api_key'])
|
7 |
+
io2 = gr.Interface.load("huggingface/facebook/xm_transformer_s2ut_hk-en", api_key=os.environ['api_key'])
|
8 |
+
io3 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_en-hk", api_key=os.environ['api_key'])
|
9 |
+
io4 = gr.Interface.load("huggingface/facebook/xm_transformer_unity_hk-en", api_key=os.environ['api_key'])
|
10 |
+
|
11 |
+
def inference(audio, model):
|
12 |
+
if model == "xm_transformer_s2ut_en-hk":
|
13 |
+
out_audio = io1(audio)
|
14 |
+
elif model == "xm_transformer_s2ut_hk-en":
|
15 |
+
out_audio = io2(audio)
|
16 |
+
elif model == "xm_transformer_unity_en-hk":
|
17 |
+
out_audio = io3(audio)
|
18 |
+
else:
|
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: black;
|
29 |
+
border-color: grey;
|
30 |
+
background: white;
|
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: 700px; 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 |
+
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.
|
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()
|