Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import torch
|
|
| 3 |
import torchaudio
|
| 4 |
import numpy as np
|
| 5 |
from transformers import AutoProcessor, SeamlessM4Tv2Model
|
|
|
|
| 6 |
|
| 7 |
class SeamlessTranslator:
|
| 8 |
def __init__(self):
|
|
@@ -13,16 +14,16 @@ class SeamlessTranslator:
|
|
| 13 |
self.sample_rate = self.model.config.sampling_rate
|
| 14 |
|
| 15 |
self.languages = {
|
| 16 |
-
"English": "eng",
|
| 17 |
-
"Spanish": "spa",
|
| 18 |
-
"French": "fra",
|
| 19 |
-
"German": "deu",
|
| 20 |
-
"Italian": "ita",
|
| 21 |
-
"Portuguese": "por",
|
| 22 |
-
"Russian": "rus",
|
| 23 |
-
"Chinese": "cmn",
|
| 24 |
-
"Japanese": "jpn",
|
| 25 |
-
"Korean": "kor"
|
| 26 |
}
|
| 27 |
|
| 28 |
def translate_text(self, text, src_lang, tgt_lang, progress=gr.Progress()):
|
|
@@ -32,11 +33,14 @@ class SeamlessTranslator:
|
|
| 32 |
progress(0.6, desc="Generating audio...")
|
| 33 |
audio_array = self.model.generate(**inputs, tgt_lang=self.languages[tgt_lang])[0].cpu().numpy().squeeze()
|
| 34 |
progress(1.0, desc="Done!")
|
| 35 |
-
return (self.sample_rate, audio_array)
|
| 36 |
except Exception as e:
|
| 37 |
-
raise gr.Error(str(e))
|
| 38 |
|
| 39 |
def translate_audio(self, audio_path, tgt_lang, progress=gr.Progress()):
|
|
|
|
|
|
|
|
|
|
| 40 |
progress(0.3, desc="Loading audio...")
|
| 41 |
try:
|
| 42 |
audio, orig_freq = torchaudio.load(audio_path)
|
|
@@ -46,9 +50,9 @@ class SeamlessTranslator:
|
|
| 46 |
inputs = self.processor(audios=audio, return_tensors="pt")
|
| 47 |
audio_array = self.model.generate(**inputs, tgt_lang=self.languages[tgt_lang])[0].cpu().numpy().squeeze()
|
| 48 |
progress(1.0, desc="Done!")
|
| 49 |
-
return (self.sample_rate, audio_array)
|
| 50 |
except Exception as e:
|
| 51 |
-
raise gr.Error(str(e))
|
| 52 |
|
| 53 |
css = """
|
| 54 |
#component-0 {
|
|
@@ -58,68 +62,186 @@ css = """
|
|
| 58 |
}
|
| 59 |
|
| 60 |
.container {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
border-radius: 12px;
|
| 62 |
-
|
|
|
|
| 63 |
}
|
| 64 |
|
| 65 |
.gr-form {
|
| 66 |
-
border
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
.gr-button {
|
| 70 |
border-radius: 8px !important;
|
| 71 |
-
background: linear-gradient(
|
| 72 |
color: white !important;
|
| 73 |
font-weight: 600 !important;
|
|
|
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
.gr-button:hover {
|
|
|
|
| 77 |
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1) !important;
|
| 78 |
-
transform: translateY(-1px);
|
| 79 |
}
|
| 80 |
|
| 81 |
.gr-input, .gr-select {
|
| 82 |
border-radius: 8px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
.gr-panel {
|
| 86 |
border-radius: 12px !important;
|
|
|
|
|
|
|
| 87 |
}
|
| 88 |
|
| 89 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
text-align: center;
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
margin: 1rem 0;
|
| 94 |
-
background: linear-gradient(to right, #2563eb, #4f46e5);
|
| 95 |
-
-webkit-background-clip: text;
|
| 96 |
-
-webkit-text-fill-color: transparent;
|
| 97 |
}
|
| 98 |
|
| 99 |
-
.
|
|
|
|
|
|
|
|
|
|
| 100 |
text-align: center;
|
| 101 |
-
|
| 102 |
-
margin-bottom: 2rem;
|
| 103 |
}
|
| 104 |
|
| 105 |
-
.
|
| 106 |
-
|
| 107 |
-
margin-bottom:
|
|
|
|
| 108 |
}
|
| 109 |
|
| 110 |
-
.
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
}
|
| 115 |
|
| 116 |
-
.
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
padding-top: 1rem;
|
| 120 |
-
border-top: 1px solid #e5e7eb;
|
| 121 |
-
color: #6b7280;
|
| 122 |
-
font-size: 0.875rem;
|
| 123 |
}
|
| 124 |
"""
|
| 125 |
|
|
@@ -127,45 +249,71 @@ def create_ui():
|
|
| 127 |
translator = SeamlessTranslator()
|
| 128 |
|
| 129 |
with gr.Blocks(css=css, title="A.R.I.S. Translator") as demo:
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
|
|
|
| 137 |
with gr.Tabs() as tabs:
|
| 138 |
-
# Text
|
| 139 |
-
with gr.Tab("Text Translation", id=1):
|
| 140 |
with gr.Row():
|
| 141 |
with gr.Column():
|
| 142 |
text_input = gr.Textbox(
|
| 143 |
label="Text to Translate",
|
| 144 |
placeholder="Enter your text here...",
|
| 145 |
-
lines=5
|
|
|
|
| 146 |
)
|
| 147 |
with gr.Row():
|
| 148 |
src_lang = gr.Dropdown(
|
| 149 |
choices=list(translator.languages.keys()),
|
| 150 |
-
value="English",
|
| 151 |
-
label="Source Language"
|
|
|
|
| 152 |
)
|
| 153 |
tgt_lang = gr.Dropdown(
|
| 154 |
choices=list(translator.languages.keys()),
|
| 155 |
-
value="Spanish",
|
| 156 |
-
label="Target Language"
|
|
|
|
| 157 |
)
|
| 158 |
-
translate_btn = gr.Button("Translate", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
with gr.Column():
|
| 161 |
-
gr.
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
| 166 |
|
| 167 |
-
# Audio
|
| 168 |
-
with gr.Tab("Audio Translation", id=2):
|
| 169 |
with gr.Row():
|
| 170 |
with gr.Column():
|
| 171 |
audio_input = gr.Audio(
|
|
@@ -174,22 +322,52 @@ def create_ui():
|
|
| 174 |
)
|
| 175 |
tgt_lang_audio = gr.Dropdown(
|
| 176 |
choices=list(translator.languages.keys()),
|
| 177 |
-
value="English",
|
| 178 |
-
label="Target Language"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
)
|
| 180 |
-
translate_audio_btn = gr.Button("Translate Audio", variant="primary")
|
| 181 |
|
| 182 |
with gr.Column():
|
| 183 |
-
gr.
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
|
|
|
| 189 |
gr.HTML(
|
| 190 |
"""
|
| 191 |
<div class="footer">
|
| 192 |
-
|
|
|
|
|
|
|
| 193 |
</div>
|
| 194 |
"""
|
| 195 |
)
|
|
@@ -198,13 +376,13 @@ def create_ui():
|
|
| 198 |
translate_btn.click(
|
| 199 |
fn=translator.translate_text,
|
| 200 |
inputs=[text_input, src_lang, tgt_lang],
|
| 201 |
-
outputs=audio_output
|
| 202 |
)
|
| 203 |
|
| 204 |
translate_audio_btn.click(
|
| 205 |
fn=translator.translate_audio,
|
| 206 |
inputs=[audio_input, tgt_lang_audio],
|
| 207 |
-
outputs=audio_output_from_audio
|
| 208 |
)
|
| 209 |
|
| 210 |
return demo
|
|
|
|
| 3 |
import torchaudio
|
| 4 |
import numpy as np
|
| 5 |
from transformers import AutoProcessor, SeamlessM4Tv2Model
|
| 6 |
+
from datetime import datetime
|
| 7 |
|
| 8 |
class SeamlessTranslator:
|
| 9 |
def __init__(self):
|
|
|
|
| 14 |
self.sample_rate = self.model.config.sampling_rate
|
| 15 |
|
| 16 |
self.languages = {
|
| 17 |
+
"🇺🇸 English": "eng",
|
| 18 |
+
"🇪🇸 Spanish": "spa",
|
| 19 |
+
"🇫🇷 French": "fra",
|
| 20 |
+
"🇩🇪 German": "deu",
|
| 21 |
+
"🇮🇹 Italian": "ita",
|
| 22 |
+
"🇵🇹 Portuguese": "por",
|
| 23 |
+
"🇷🇺 Russian": "rus",
|
| 24 |
+
"🇨🇳 Chinese": "cmn",
|
| 25 |
+
"🇯🇵 Japanese": "jpn",
|
| 26 |
+
"🇰🇷 Korean": "kor"
|
| 27 |
}
|
| 28 |
|
| 29 |
def translate_text(self, text, src_lang, tgt_lang, progress=gr.Progress()):
|
|
|
|
| 33 |
progress(0.6, desc="Generating audio...")
|
| 34 |
audio_array = self.model.generate(**inputs, tgt_lang=self.languages[tgt_lang])[0].cpu().numpy().squeeze()
|
| 35 |
progress(1.0, desc="Done!")
|
| 36 |
+
return (self.sample_rate, audio_array), f"✅ Translation completed: {src_lang} → {tgt_lang}"
|
| 37 |
except Exception as e:
|
| 38 |
+
raise gr.Error(f"❌ Translation failed: {str(e)}")
|
| 39 |
|
| 40 |
def translate_audio(self, audio_path, tgt_lang, progress=gr.Progress()):
|
| 41 |
+
if audio_path is None:
|
| 42 |
+
raise gr.Error("❌ Please upload an audio file")
|
| 43 |
+
|
| 44 |
progress(0.3, desc="Loading audio...")
|
| 45 |
try:
|
| 46 |
audio, orig_freq = torchaudio.load(audio_path)
|
|
|
|
| 50 |
inputs = self.processor(audios=audio, return_tensors="pt")
|
| 51 |
audio_array = self.model.generate(**inputs, tgt_lang=self.languages[tgt_lang])[0].cpu().numpy().squeeze()
|
| 52 |
progress(1.0, desc="Done!")
|
| 53 |
+
return (self.sample_rate, audio_array), "✅ Audio translation completed"
|
| 54 |
except Exception as e:
|
| 55 |
+
raise gr.Error(f"❌ Translation failed: {str(e)}")
|
| 56 |
|
| 57 |
css = """
|
| 58 |
#component-0 {
|
|
|
|
| 62 |
}
|
| 63 |
|
| 64 |
.container {
|
| 65 |
+
border-radius: 16px;
|
| 66 |
+
padding: 24px;
|
| 67 |
+
background: white;
|
| 68 |
+
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.header-container {
|
| 72 |
+
text-align: center;
|
| 73 |
+
margin-bottom: 2rem;
|
| 74 |
+
padding: 2rem;
|
| 75 |
+
background: linear-gradient(135deg, #f8fafc, #e2e8f0);
|
| 76 |
+
border-radius: 16px;
|
| 77 |
+
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.title {
|
| 81 |
+
font-size: 2.75rem;
|
| 82 |
+
font-weight: 800;
|
| 83 |
+
background: linear-gradient(135deg, #1e40af, #3b82f6);
|
| 84 |
+
-webkit-background-clip: text;
|
| 85 |
+
-webkit-text-fill-color: transparent;
|
| 86 |
+
margin-bottom: 0.5rem;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
.subtitle {
|
| 90 |
+
color: #64748b;
|
| 91 |
+
font-size: 1.1rem;
|
| 92 |
+
margin-bottom: 1rem;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.stats {
|
| 96 |
+
display: flex;
|
| 97 |
+
justify-content: center;
|
| 98 |
+
gap: 2rem;
|
| 99 |
+
margin-top: 1rem;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.stat-item {
|
| 103 |
+
text-align: center;
|
| 104 |
+
padding: 0.5rem 1rem;
|
| 105 |
+
background: white;
|
| 106 |
+
border-radius: 8px;
|
| 107 |
+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
.stat-value {
|
| 111 |
+
font-weight: 600;
|
| 112 |
+
color: #1e40af;
|
| 113 |
+
font-size: 1.25rem;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
.stat-label {
|
| 117 |
+
color: #64748b;
|
| 118 |
+
font-size: 0.875rem;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.tab-nav {
|
| 122 |
+
background: white;
|
| 123 |
+
padding: 0.5rem;
|
| 124 |
border-radius: 12px;
|
| 125 |
+
margin-bottom: 1.5rem;
|
| 126 |
+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
| 127 |
}
|
| 128 |
|
| 129 |
.gr-form {
|
| 130 |
+
border: none !important;
|
| 131 |
+
background: white;
|
| 132 |
+
padding: 1.5rem !important;
|
| 133 |
+
border-radius: 12px !important;
|
| 134 |
+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.gr-box {
|
| 138 |
+
border-radius: 12px !important;
|
| 139 |
+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
| 140 |
}
|
| 141 |
|
| 142 |
.gr-button {
|
| 143 |
border-radius: 8px !important;
|
| 144 |
+
background: linear-gradient(135deg, #1e40af, #3b82f6) !important;
|
| 145 |
color: white !important;
|
| 146 |
font-weight: 600 !important;
|
| 147 |
+
padding: 0.75rem 1.5rem !important;
|
| 148 |
+
transition: all 0.2s !important;
|
| 149 |
}
|
| 150 |
|
| 151 |
.gr-button:hover {
|
| 152 |
+
transform: translateY(-1px) !important;
|
| 153 |
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1) !important;
|
|
|
|
| 154 |
}
|
| 155 |
|
| 156 |
.gr-input, .gr-select {
|
| 157 |
border-radius: 8px !important;
|
| 158 |
+
border: 1px solid #e2e8f0 !important;
|
| 159 |
+
padding: 0.75rem !important;
|
| 160 |
+
transition: all 0.2s !important;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
.gr-input:focus, .gr-select:focus {
|
| 164 |
+
border-color: #3b82f6 !important;
|
| 165 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
|
| 166 |
}
|
| 167 |
|
| 168 |
.gr-panel {
|
| 169 |
border-radius: 12px !important;
|
| 170 |
+
border: none !important;
|
| 171 |
+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1) !important;
|
| 172 |
}
|
| 173 |
|
| 174 |
+
.output-container {
|
| 175 |
+
background: #f8fafc;
|
| 176 |
+
padding: 1.5rem;
|
| 177 |
+
border-radius: 12px;
|
| 178 |
+
margin-top: 1rem;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
.output-label {
|
| 182 |
+
font-weight: 600;
|
| 183 |
+
color: #1e40af;
|
| 184 |
+
margin-bottom: 0.75rem;
|
| 185 |
+
font-size: 1.1rem;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
.status-message {
|
| 189 |
+
padding: 0.75rem;
|
| 190 |
+
border-radius: 8px;
|
| 191 |
+
margin-top: 1rem;
|
| 192 |
+
font-size: 0.875rem;
|
| 193 |
+
background: #f0f9ff;
|
| 194 |
+
border-left: 4px solid #3b82f6;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
.footer {
|
| 198 |
text-align: center;
|
| 199 |
+
margin-top: 3rem;
|
| 200 |
+
padding: 1.5rem;
|
| 201 |
+
background: white;
|
| 202 |
+
border-radius: 12px;
|
| 203 |
+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.footer-text {
|
| 207 |
+
color: #64748b;
|
| 208 |
+
font-size: 0.875rem;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.feature-grid {
|
| 212 |
+
display: grid;
|
| 213 |
+
grid-template-columns: repeat(3, 1fr);
|
| 214 |
+
gap: 1rem;
|
| 215 |
margin: 1rem 0;
|
|
|
|
|
|
|
|
|
|
| 216 |
}
|
| 217 |
|
| 218 |
+
.feature-item {
|
| 219 |
+
background: white;
|
| 220 |
+
padding: 1rem;
|
| 221 |
+
border-radius: 8px;
|
| 222 |
text-align: center;
|
| 223 |
+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
|
|
|
| 224 |
}
|
| 225 |
|
| 226 |
+
.feature-icon {
|
| 227 |
+
font-size: 1.5rem;
|
| 228 |
+
margin-bottom: 0.5rem;
|
| 229 |
+
color: #3b82f6;
|
| 230 |
}
|
| 231 |
|
| 232 |
+
.language-pair {
|
| 233 |
+
display: flex;
|
| 234 |
+
align-items: center;
|
| 235 |
+
gap: 1rem;
|
| 236 |
+
margin: 1rem 0;
|
| 237 |
+
padding: 0.75rem;
|
| 238 |
+
background: #f8fafc;
|
| 239 |
+
border-radius: 8px;
|
| 240 |
}
|
| 241 |
|
| 242 |
+
.language-arrow {
|
| 243 |
+
color: #3b82f6;
|
| 244 |
+
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
}
|
| 246 |
"""
|
| 247 |
|
|
|
|
| 249 |
translator = SeamlessTranslator()
|
| 250 |
|
| 251 |
with gr.Blocks(css=css, title="A.R.I.S. Translator") as demo:
|
| 252 |
+
# Header
|
| 253 |
+
with gr.Column(elem_class="header-container"):
|
| 254 |
+
gr.HTML(
|
| 255 |
+
"""
|
| 256 |
+
<div class="title">A.R.I.S. Translator</div>
|
| 257 |
+
<div class="subtitle">Advanced Real-time Interpretation System</div>
|
| 258 |
+
<div class="stats">
|
| 259 |
+
<div class="stat-item">
|
| 260 |
+
<div class="stat-value">10</div>
|
| 261 |
+
<div class="stat-label">Languages</div>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="stat-item">
|
| 264 |
+
<div class="stat-value">Real-time</div>
|
| 265 |
+
<div class="stat-label">Translation</div>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="stat-item">
|
| 268 |
+
<div class="stat-value">Neural</div>
|
| 269 |
+
<div class="stat-label">Technology</div>
|
| 270 |
+
</div>
|
| 271 |
+
</div>
|
| 272 |
+
"""
|
| 273 |
+
)
|
| 274 |
|
| 275 |
+
# Main content
|
| 276 |
with gr.Tabs() as tabs:
|
| 277 |
+
# Text Translation Tab
|
| 278 |
+
with gr.Tab("🔤 Text Translation", id=1):
|
| 279 |
with gr.Row():
|
| 280 |
with gr.Column():
|
| 281 |
text_input = gr.Textbox(
|
| 282 |
label="Text to Translate",
|
| 283 |
placeholder="Enter your text here...",
|
| 284 |
+
lines=5,
|
| 285 |
+
elem_classes="gr-input"
|
| 286 |
)
|
| 287 |
with gr.Row():
|
| 288 |
src_lang = gr.Dropdown(
|
| 289 |
choices=list(translator.languages.keys()),
|
| 290 |
+
value="🇺🇸 English",
|
| 291 |
+
label="Source Language",
|
| 292 |
+
elem_classes="gr-select"
|
| 293 |
)
|
| 294 |
tgt_lang = gr.Dropdown(
|
| 295 |
choices=list(translator.languages.keys()),
|
| 296 |
+
value="🇪🇸 Spanish",
|
| 297 |
+
label="Target Language",
|
| 298 |
+
elem_classes="gr-select"
|
| 299 |
)
|
| 300 |
+
translate_btn = gr.Button("🔄 Translate", variant="primary")
|
| 301 |
+
status_text = gr.Textbox(
|
| 302 |
+
label="Status",
|
| 303 |
+
interactive=False,
|
| 304 |
+
elem_classes="status-message"
|
| 305 |
+
)
|
| 306 |
|
| 307 |
with gr.Column():
|
| 308 |
+
with gr.Box(elem_classes="output-container"):
|
| 309 |
+
gr.HTML('<div class="output-label">🔊 Translation Output</div>')
|
| 310 |
+
audio_output = gr.Audio(
|
| 311 |
+
label="Translated Audio",
|
| 312 |
+
type="numpy"
|
| 313 |
+
)
|
| 314 |
|
| 315 |
+
# Audio Translation Tab
|
| 316 |
+
with gr.Tab("🎤 Audio Translation", id=2):
|
| 317 |
with gr.Row():
|
| 318 |
with gr.Column():
|
| 319 |
audio_input = gr.Audio(
|
|
|
|
| 322 |
)
|
| 323 |
tgt_lang_audio = gr.Dropdown(
|
| 324 |
choices=list(translator.languages.keys()),
|
| 325 |
+
value="🇺🇸 English",
|
| 326 |
+
label="Target Language",
|
| 327 |
+
elem_classes="gr-select"
|
| 328 |
+
)
|
| 329 |
+
translate_audio_btn = gr.Button("🔄 Translate Audio", variant="primary")
|
| 330 |
+
status_text_audio = gr.Textbox(
|
| 331 |
+
label="Status",
|
| 332 |
+
interactive=False,
|
| 333 |
+
elem_classes="status-message"
|
| 334 |
)
|
|
|
|
| 335 |
|
| 336 |
with gr.Column():
|
| 337 |
+
with gr.Box(elem_classes="output-container"):
|
| 338 |
+
gr.HTML('<div class="output-label">🔊 Translation Output</div>')
|
| 339 |
+
audio_output_from_audio = gr.Audio(
|
| 340 |
+
label="Translated Audio",
|
| 341 |
+
type="numpy"
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
# Features Grid
|
| 345 |
+
gr.HTML(
|
| 346 |
+
"""
|
| 347 |
+
<div class="feature-grid">
|
| 348 |
+
<div class="feature-item">
|
| 349 |
+
<div class="feature-icon">🌐</div>
|
| 350 |
+
<div>10 Languages</div>
|
| 351 |
+
</div>
|
| 352 |
+
<div class="feature-item">
|
| 353 |
+
<div class="feature-icon">⚡</div>
|
| 354 |
+
<div>Real-time Processing</div>
|
| 355 |
+
</div>
|
| 356 |
+
<div class="feature-item">
|
| 357 |
+
<div class="feature-icon">🎯</div>
|
| 358 |
+
<div>High Accuracy</div>
|
| 359 |
+
</div>
|
| 360 |
+
</div>
|
| 361 |
+
"""
|
| 362 |
+
)
|
| 363 |
|
| 364 |
+
# Footer
|
| 365 |
gr.HTML(
|
| 366 |
"""
|
| 367 |
<div class="footer">
|
| 368 |
+
<div class="footer-text">
|
| 369 |
+
Powered by Meta's SeamlessM4T model | Built with ❤️ using Gradio
|
| 370 |
+
</div>
|
| 371 |
</div>
|
| 372 |
"""
|
| 373 |
)
|
|
|
|
| 376 |
translate_btn.click(
|
| 377 |
fn=translator.translate_text,
|
| 378 |
inputs=[text_input, src_lang, tgt_lang],
|
| 379 |
+
outputs=[audio_output, status_text]
|
| 380 |
)
|
| 381 |
|
| 382 |
translate_audio_btn.click(
|
| 383 |
fn=translator.translate_audio,
|
| 384 |
inputs=[audio_input, tgt_lang_audio],
|
| 385 |
+
outputs=[audio_output_from_audio, status_text_audio]
|
| 386 |
)
|
| 387 |
|
| 388 |
return demo
|