Spaces:
Running
Running
File size: 11,417 Bytes
5ae02e5 23dd469 5ae02e5 23dd469 388fe1b 2a6eab9 23dd469 2a6eab9 23dd469 388fe1b 23dd469 5ae02e5 2a6eab9 5ae02e5 aa1a596 2a6eab9 aa1a596 2a6eab9 aa1a596 2a6eab9 6418068 aa1a596 6418068 5ae02e5 6418068 2a6eab9 6418068 2a6eab9 6418068 23dd469 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 23dd469 2a6eab9 6418068 23dd469 aa1a596 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 388fe1b 6418068 2a6eab9 aa1a596 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 2a6eab9 6418068 5ae02e5 2a6eab9 aa1a596 2a6eab9 388fe1b 23dd469 6418068 aa1a596 |
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
import gradio as gr
import torch
import torchaudio
import numpy as np
from transformers import AutoProcessor, SeamlessM4Tv2Model
from datetime import datetime
import time
class ARISTranslator:
def __init__(self, model_name: str = "facebook/seamless-m4t-v2-large"):
self.processor = AutoProcessor.from_pretrained(model_name)
self.model = SeamlessM4Tv2Model.from_pretrained(model_name)
self.sample_rate = self.model.config.sampling_rate
self.language_codes = {
"English (US)": "eng",
"Spanish (ES)": "spa",
"French (FR)": "fra",
"German (DE)": "deu",
"Italian (IT)": "ita",
"Portuguese (BR)": "por",
"Russian (RU)": "rus",
"Chinese (CN)": "cmn",
"Japanese (JP)": "jpn",
"Korean (KR)": "kor",
"Hindi (IN)": "hin",
"Arabic (AR)": "ara"
}
def process_audio(self, audio_path: str, tgt_lang: str) -> tuple[int, np.ndarray]:
try:
if audio_path is None:
raise gr.Error("No audio input provided")
# Carregar e resample do áudio
audio, orig_freq = torchaudio.load(audio_path)
audio = torchaudio.functional.resample(audio, orig_freq=orig_freq, new_freq=16000)
# Processar através do modelo
inputs = self.processor(audios=audio, return_tensors="pt")
audio_array = self.model.generate(**inputs, tgt_lang=self.language_codes[tgt_lang])[0].cpu().numpy().squeeze()
return self.sample_rate, audio_array
except Exception as e:
raise gr.Error(f"Audio processing failed: {str(e)}")
def translate_text(self, text: str, src_lang: str, tgt_lang: str) -> tuple[int, np.ndarray]:
try:
if not text.strip():
raise gr.Error("No text input provided")
inputs = self.processor(text=text, src_lang=self.language_codes[src_lang], return_tensors="pt")
audio_array = self.model.generate(**inputs, tgt_lang=self.language_codes[tgt_lang])[0].cpu().numpy().squeeze()
return self.sample_rate, audio_array
except Exception as e:
raise gr.Error(f"Translation failed: {str(e)}")
css = """
:root {
--primary: #00ffff;
--secondary: #0066cc;
--accent: #ff3366;
--background: #000000;
--text: #ffffff;
}
#aris-interface {
background-color: var(--background);
background-image:
radial-gradient(circle at 20% 20%, rgba(0, 102, 204, 0.1) 0%, transparent 50%),
radial-gradient(circle at 80% 80%, rgba(0, 255, 255, 0.1) 0%, transparent 50%);
min-height: 100vh;
font-family: 'Courier New', monospace;
padding: 20px;
}
.title-container {
text-align: center;
color: var(--primary);
margin-bottom: 30px;
position: relative;
}
.title-container h1 {
font-size: 3em;
letter-spacing: 10px;
margin: 0;
text-shadow: 0 0 10px var(--primary);
}
.title-container h3 {
font-size: 1.2em;
letter-spacing: 3px;
opacity: 0.8;
margin: 5px 0;
}
#status-ring {
width: 400px;
height: 400px;
border: 4px solid var(--primary);
border-radius: 50%;
margin: 20px auto;
position: relative;
animation: pulse 2s infinite;
display: flex;
align-items: center;
justify-content: center;
background:
radial-gradient(circle at center, rgba(0, 255, 255, 0.1) 0%, transparent 70%),
conic-gradient(from 0deg, transparent 0%, rgba(0, 255, 255, 0.1) 50%, transparent 100%);
}
#outer-ring-decoration {
position: absolute;
width: 420px;
height: 420px;
border-radius: 50%;
border: 1px solid rgba(0, 255, 255, 0.3);
animation: rotate 20s linear infinite;
}
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(0, 255, 255, 0.4); }
70% { box-shadow: 0 0 0 20px rgba(0, 255, 255, 0); }
100% { box-shadow: 0 0 0 0 rgba(0, 255, 255, 0); }
}
.aris-textbox {
background-color: rgba(0, 0, 0, 0.8) !important;
border: 2px solid var(--primary) !important;
color: var(--primary) !important;
font-family: 'Courier New', monospace !important;
border-radius: 5px !important;
padding: 10px !important;
}
.aris-button {
background-color: transparent !important;
border: 2px solid var(--primary) !important;
color: var(--primary) !important;
font-family: 'Courier New', monospace !important;
text-transform: uppercase !important;
letter-spacing: 2px !important;
padding: 12px 24px !important;
border-radius: 5px !important;
transition: all 0.3s ease !important;
}
.aris-button:hover {
background-color: rgba(0, 255, 255, 0.1) !important;
box-shadow: 0 0 15px rgba(0, 255, 255, 0.3) !important;
transform: translateY(-2px) !important;
}
.status-box {
background-color: rgba(0, 0, 0, 0.8) !important;
border: 2px solid var(--primary) !important;
color: var(--primary) !important;
padding: 15px !important;
border-radius: 5px !important;
margin: 5px !important;
text-align: center !important;
text-transform: uppercase !important;
letter-spacing: 1px !important;
transition: all 0.3s ease !important;
position: relative;
overflow: hidden;
}
.status-box::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 2px;
background: linear-gradient(90deg, transparent, var(--primary));
animation: scan-line 2s linear infinite;
}
@keyframes scan-line {
0% { left: -100%; }
100% { left: 100%; }
}
"""
def create_interface():
translator = ARISTranslator()
def update_status():
return (
f"A.R.I.S. CORE v2.0.0\n"
f"Time: {datetime.now().strftime('%H:%M:%S')}\n"
f"Neural Engine: ACTIVE\n"
f"Translation Matrix: OPERATIONAL"
)
with gr.Blocks(css=css, title="A.R.I.S. - Advanced Real-time Interpretation System") as demo:
gr.HTML('''
<div class="title-container">
<h1>A.R.I.S.</h1>
<h3>Advanced Real-time Interpretation System</h3>
<div class="mode-indicator">QUANTUM CORE ACTIVE</div>
</div>
''')
with gr.Column(elem_id="aris-interface"):
gr.HTML("""
<div id="status-ring">
<div id="outer-ring-decoration"></div>
<div id="inner-ring">
<div id="core">
<div>A.R.I.S.</div>
<div>QUANTUM CORE</div>
<div>v2.0.0</div>
<div class="system-version">NEURAL ENGINE ACTIVE</div>
</div>
</div>
</div>
""")
with gr.Row():
with gr.Column():
with gr.Tab("Text Translation"):
text_input = gr.Textbox(
label="INPUT TEXT",
placeholder="Enter text for translation...",
elem_classes=["aris-textbox"],
lines=3
)
with gr.Row():
src_lang_text = gr.Dropdown(
choices=list(translator.language_codes.keys()),
value="English (US)",
label="SOURCE LANGUAGE",
elem_classes=["aris-textbox"]
)
tgt_lang_text = gr.Dropdown(
choices=list(translator.language_codes.keys()),
value="Spanish (ES)",
label="TARGET LANGUAGE",
elem_classes=["aris-textbox"]
)
translate_btn = gr.Button("▶ TRANSLATE TEXT", elem_classes=["aris-button"])
with gr.Tab("Audio Translation"):
audio_input = gr.Audio(
label="AUDIO INPUT",
type="filepath"
)
tgt_lang_audio = gr.Dropdown(
choices=list(translator.language_codes.keys()),
value="English (US)",
label="TARGET LANGUAGE",
elem_classes=["aris-textbox"]
)
translate_audio_btn = gr.Button("▶ TRANSLATE AUDIO", elem_classes=["aris-button"])
with gr.Column():
audio_output = gr.Audio(
label="TRANSLATION OUTPUT",
type="numpy"
)
with gr.Row():
with gr.Column(min_width=200):
gr.HTML(
"""
<div class="status-box">
NEURAL CORE<br>
<strong>OPERATIONAL</strong>
</div>
"""
)
with gr.Column(min_width=200):
gr.HTML(
"""
<div class="status-box">
QUANTUM ENGINE<br>
<strong>ACTIVE</strong>
</div>
"""
)
with gr.Row():
with gr.Column(min_width=200):
gr.HTML(
"""
<div class="status-box">
TRANSLATION MATRIX<br>
<strong>CALIBRATED</strong>
</div>
"""
)
with gr.Column(min_width=200):
gr.HTML(
"""
<div class="status-box">
VOICE SYNTHESIS<br>
<strong>READY</strong>
</div>
"""
)
# Event handlers
translate_btn.click(
fn=translator.translate_text,
inputs=[text_input, src_lang_text, tgt_lang_text],
outputs=audio_output
)
translate_audio_btn.click(
fn=translator.process_audio,
inputs=[audio_input, tgt_lang_audio],
outputs=audio_output
)
return demo
if __name__ == "__main__":
demo = create_interface()
demo.queue()
demo.launch() |