Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,26 +4,58 @@ import torchaudio
|
|
4 |
import numpy as np
|
5 |
from transformers import AutoProcessor, SeamlessM4Tv2Model
|
6 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
class
|
9 |
def __init__(self, model_name: str = "facebook/seamless-m4t-v2-large"):
|
10 |
self.processor = AutoProcessor.from_pretrained(model_name)
|
11 |
self.model = SeamlessM4Tv2Model.from_pretrained(model_name)
|
12 |
self.sample_rate = self.model.config.sampling_rate
|
|
|
|
|
13 |
|
14 |
self.language_codes = {
|
15 |
-
"English": "eng",
|
16 |
-
"Spanish": "spa",
|
17 |
-
"French": "fra",
|
18 |
-
"German": "deu",
|
19 |
-
"Italian": "ita",
|
20 |
-
"Portuguese": "por",
|
21 |
-
"Russian": "rus",
|
22 |
-
"Chinese": "cmn",
|
23 |
-
"Japanese": "jpn"
|
|
|
|
|
|
|
24 |
}
|
25 |
|
26 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
try:
|
28 |
inputs = self.processor(text=text, src_lang=self.language_codes[src_lang], return_tensors="pt")
|
29 |
audio_array = self.model.generate(**inputs, tgt_lang=self.language_codes[tgt_lang])[0].cpu().numpy().squeeze()
|
@@ -31,19 +63,52 @@ class SeamlessTranslator:
|
|
31 |
except Exception as e:
|
32 |
raise gr.Error(f"Translation failed: {str(e)}")
|
33 |
|
34 |
-
# Custom CSS for Jarvis theme
|
35 |
css = """
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
min-height: 100vh;
|
40 |
font-family: 'Courier New', monospace;
|
|
|
41 |
}
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
#status-ring {
|
44 |
-
width:
|
45 |
-
height:
|
46 |
-
border: 4px solid
|
47 |
border-radius: 50%;
|
48 |
margin: 20px auto;
|
49 |
position: relative;
|
@@ -51,174 +116,362 @@ css = """
|
|
51 |
display: flex;
|
52 |
align-items: center;
|
53 |
justify-content: center;
|
|
|
|
|
|
|
54 |
}
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
60 |
}
|
61 |
|
62 |
#inner-ring {
|
63 |
-
width:
|
64 |
-
height:
|
65 |
-
border: 2px solid
|
66 |
border-radius: 50%;
|
67 |
display: flex;
|
68 |
align-items: center;
|
69 |
justify-content: center;
|
|
|
70 |
}
|
71 |
|
72 |
#core {
|
73 |
-
width:
|
74 |
-
height:
|
75 |
-
border: 3px solid
|
76 |
border-radius: 50%;
|
77 |
-
background-color:
|
78 |
display: flex;
|
|
|
79 |
align-items: center;
|
80 |
justify-content: center;
|
81 |
-
color:
|
82 |
text-align: center;
|
83 |
-
padding:
|
|
|
|
|
84 |
}
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
font-family: 'Courier New', monospace !important;
|
|
|
|
|
91 |
}
|
92 |
|
93 |
-
.
|
94 |
background-color: transparent !important;
|
95 |
-
border: 2px solid
|
96 |
-
color:
|
97 |
font-family: 'Courier New', monospace !important;
|
|
|
|
|
|
|
|
|
|
|
98 |
}
|
99 |
|
100 |
-
.
|
101 |
background-color: rgba(0, 255, 255, 0.1) !important;
|
|
|
|
|
102 |
}
|
103 |
|
104 |
.status-box {
|
105 |
-
background-color:
|
106 |
-
border: 2px solid
|
107 |
-
color:
|
108 |
-
padding:
|
109 |
border-radius: 5px !important;
|
110 |
margin: 5px !important;
|
111 |
text-align: center !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
"""
|
114 |
|
115 |
def create_interface():
|
116 |
-
translator =
|
117 |
-
|
118 |
-
def translate_text(text: str, src_lang: str, tgt_lang: str, progress=gr.Progress()):
|
119 |
-
progress(0, desc="Initializing...")
|
120 |
-
progress(0.3, desc="Processing text...")
|
121 |
-
sample_rate, audio = translator.translate(text, src_lang, tgt_lang)
|
122 |
-
progress(0.7, desc="Generating audio...")
|
123 |
-
progress(1.0, desc="Complete!")
|
124 |
-
return audio
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
""
|
129 |
-
|
130 |
-
|
131 |
-
""
|
132 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
-
|
135 |
-
with gr.Column(elem_id="jarvis-interface"):
|
136 |
-
# Status Ring
|
137 |
gr.HTML("""
|
138 |
<div id="status-ring">
|
|
|
139 |
<div id="inner-ring">
|
140 |
<div id="core">
|
141 |
-
<div>
|
142 |
-
<div>
|
|
|
|
|
143 |
</div>
|
144 |
</div>
|
145 |
</div>
|
146 |
""")
|
147 |
|
148 |
-
# Input controls
|
149 |
with gr.Row():
|
150 |
-
text_input = gr.Textbox(
|
151 |
-
label="Command Input",
|
152 |
-
placeholder="Enter text to translate...",
|
153 |
-
elem_classes=["jarvis-textbox"],
|
154 |
-
lines=3
|
155 |
-
)
|
156 |
-
|
157 |
-
with gr.Row():
|
158 |
-
src_lang = gr.Dropdown(
|
159 |
-
choices=list(translator.language_codes.keys()),
|
160 |
-
value="English",
|
161 |
-
label="Source Language",
|
162 |
-
elem_classes=["jarvis-textbox"]
|
163 |
-
)
|
164 |
-
tgt_lang = gr.Dropdown(
|
165 |
-
choices=list(translator.language_codes.keys()),
|
166 |
-
value="Spanish",
|
167 |
-
label="Target Language",
|
168 |
-
elem_classes=["jarvis-textbox"]
|
169 |
-
)
|
170 |
-
|
171 |
-
translate_btn = gr.Button(
|
172 |
-
"▶ EXECUTE TRANSLATION",
|
173 |
-
elem_classes=["jarvis-button"]
|
174 |
-
)
|
175 |
-
|
176 |
-
# Output audio
|
177 |
-
audio_output = gr.Audio(
|
178 |
-
label="Translated Speech",
|
179 |
-
type="numpy"
|
180 |
-
)
|
181 |
-
|
182 |
-
# Status boxes
|
183 |
-
with gr.Row():
|
184 |
-
with gr.Column():
|
185 |
-
gr.Markdown(
|
186 |
-
"""
|
187 |
-
<div class="status-box">
|
188 |
-
SYSTEM STATUS<br>
|
189 |
-
<strong>ACTIVE</strong>
|
190 |
-
</div>
|
191 |
-
"""
|
192 |
-
)
|
193 |
with gr.Column():
|
194 |
-
gr.
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
with gr.Column():
|
203 |
-
gr.
|
204 |
-
""
|
205 |
-
|
206 |
-
TRANSLATION<br>
|
207 |
-
<strong>ONLINE</strong>
|
208 |
-
</div>
|
209 |
-
"""
|
210 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
-
|
|
|
|
|
|
|
|
|
213 |
translate_btn.click(
|
214 |
-
fn=translate_text,
|
215 |
-
inputs=[text_input,
|
216 |
outputs=audio_output
|
217 |
)
|
218 |
-
|
|
|
|
|
|
|
219 |
return demo
|
220 |
|
221 |
if __name__ == "__main__":
|
222 |
demo = create_interface()
|
223 |
demo.queue()
|
224 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import numpy as np
|
5 |
from transformers import AutoProcessor, SeamlessM4Tv2Model
|
6 |
from datetime import datetime
|
7 |
+
import time
|
8 |
+
import threading
|
9 |
+
import queue
|
10 |
+
import sounddevice as sd
|
11 |
|
12 |
+
class ARISTranslator:
|
13 |
def __init__(self, model_name: str = "facebook/seamless-m4t-v2-large"):
|
14 |
self.processor = AutoProcessor.from_pretrained(model_name)
|
15 |
self.model = SeamlessM4Tv2Model.from_pretrained(model_name)
|
16 |
self.sample_rate = self.model.config.sampling_rate
|
17 |
+
self.audio_queue = queue.Queue()
|
18 |
+
self.is_recording = False
|
19 |
|
20 |
self.language_codes = {
|
21 |
+
"English (US)": "eng",
|
22 |
+
"Spanish (ES)": "spa",
|
23 |
+
"French (FR)": "fra",
|
24 |
+
"German (DE)": "deu",
|
25 |
+
"Italian (IT)": "ita",
|
26 |
+
"Portuguese (BR)": "por",
|
27 |
+
"Russian (RU)": "rus",
|
28 |
+
"Chinese (CN)": "cmn",
|
29 |
+
"Japanese (JP)": "jpn",
|
30 |
+
"Korean (KR)": "kor",
|
31 |
+
"Hindi (IN)": "hin",
|
32 |
+
"Arabic (AR)": "ara"
|
33 |
}
|
34 |
|
35 |
+
def start_recording(self):
|
36 |
+
self.is_recording = True
|
37 |
+
threading.Thread(target=self._record_audio).start()
|
38 |
+
|
39 |
+
def stop_recording(self):
|
40 |
+
self.is_recording = False
|
41 |
+
|
42 |
+
def _record_audio(self):
|
43 |
+
with sd.InputStream(channels=1, samplerate=16000, callback=self._audio_callback):
|
44 |
+
while self.is_recording:
|
45 |
+
time.sleep(0.1)
|
46 |
+
|
47 |
+
def _audio_callback(self, indata, frames, time, status):
|
48 |
+
self.audio_queue.put(indata.copy())
|
49 |
+
|
50 |
+
def translate_realtime(self, audio_chunk, src_lang: str, tgt_lang: str) -> tuple[int, np.ndarray]:
|
51 |
+
try:
|
52 |
+
inputs = self.processor(audios=audio_chunk, return_tensors="pt")
|
53 |
+
audio_array = self.model.generate(**inputs, tgt_lang=self.language_codes[tgt_lang])[0].cpu().numpy().squeeze()
|
54 |
+
return self.sample_rate, audio_array
|
55 |
+
except Exception as e:
|
56 |
+
raise gr.Error(f"Translation failed: {str(e)}")
|
57 |
+
|
58 |
+
def translate_text(self, text: str, src_lang: str, tgt_lang: str) -> tuple[int, np.ndarray]:
|
59 |
try:
|
60 |
inputs = self.processor(text=text, src_lang=self.language_codes[src_lang], return_tensors="pt")
|
61 |
audio_array = self.model.generate(**inputs, tgt_lang=self.language_codes[tgt_lang])[0].cpu().numpy().squeeze()
|
|
|
63 |
except Exception as e:
|
64 |
raise gr.Error(f"Translation failed: {str(e)}")
|
65 |
|
|
|
66 |
css = """
|
67 |
+
/* Cores e temas da interface */
|
68 |
+
:root {
|
69 |
+
--primary: #00ffff;
|
70 |
+
--secondary: #0066cc;
|
71 |
+
--accent: #ff3366;
|
72 |
+
--background: #000000;
|
73 |
+
--text: #ffffff;
|
74 |
+
}
|
75 |
+
|
76 |
+
#aris-interface {
|
77 |
+
background-color: var(--background);
|
78 |
+
background-image:
|
79 |
+
radial-gradient(circle at 20% 20%, rgba(0, 102, 204, 0.1) 0%, transparent 50%),
|
80 |
+
radial-gradient(circle at 80% 80%, rgba(0, 255, 255, 0.1) 0%, transparent 50%);
|
81 |
min-height: 100vh;
|
82 |
font-family: 'Courier New', monospace;
|
83 |
+
padding: 20px;
|
84 |
}
|
85 |
|
86 |
+
.title-container {
|
87 |
+
text-align: center;
|
88 |
+
color: var(--primary);
|
89 |
+
margin-bottom: 30px;
|
90 |
+
position: relative;
|
91 |
+
}
|
92 |
+
|
93 |
+
.title-container h1 {
|
94 |
+
font-size: 3em;
|
95 |
+
letter-spacing: 10px;
|
96 |
+
margin: 0;
|
97 |
+
text-shadow: 0 0 10px var(--primary);
|
98 |
+
}
|
99 |
+
|
100 |
+
.title-container h3 {
|
101 |
+
font-size: 1.2em;
|
102 |
+
letter-spacing: 3px;
|
103 |
+
opacity: 0.8;
|
104 |
+
margin: 5px 0;
|
105 |
+
}
|
106 |
+
|
107 |
+
/* Sistema de anéis central */
|
108 |
#status-ring {
|
109 |
+
width: 400px;
|
110 |
+
height: 400px;
|
111 |
+
border: 4px solid var(--primary);
|
112 |
border-radius: 50%;
|
113 |
margin: 20px auto;
|
114 |
position: relative;
|
|
|
116 |
display: flex;
|
117 |
align-items: center;
|
118 |
justify-content: center;
|
119 |
+
background:
|
120 |
+
radial-gradient(circle at center, rgba(0, 255, 255, 0.1) 0%, transparent 70%),
|
121 |
+
conic-gradient(from 0deg, transparent 0%, rgba(0, 255, 255, 0.1) 50%, transparent 100%);
|
122 |
}
|
123 |
|
124 |
+
#outer-ring-decoration {
|
125 |
+
position: absolute;
|
126 |
+
width: 420px;
|
127 |
+
height: 420px;
|
128 |
+
border-radius: 50%;
|
129 |
+
border: 1px solid rgba(0, 255, 255, 0.3);
|
130 |
+
animation: rotate 20s linear infinite;
|
131 |
}
|
132 |
|
133 |
#inner-ring {
|
134 |
+
width: 300px;
|
135 |
+
height: 300px;
|
136 |
+
border: 2px solid var(--primary);
|
137 |
border-radius: 50%;
|
138 |
display: flex;
|
139 |
align-items: center;
|
140 |
justify-content: center;
|
141 |
+
position: relative;
|
142 |
}
|
143 |
|
144 |
#core {
|
145 |
+
width: 200px;
|
146 |
+
height: 200px;
|
147 |
+
border: 3px solid var(--primary);
|
148 |
border-radius: 50%;
|
149 |
+
background-color: rgba(0, 0, 0, 0.8);
|
150 |
display: flex;
|
151 |
+
flex-direction: column;
|
152 |
align-items: center;
|
153 |
justify-content: center;
|
154 |
+
color: var(--primary);
|
155 |
text-align: center;
|
156 |
+
padding: 15px;
|
157 |
+
position: relative;
|
158 |
+
box-shadow: 0 0 20px rgba(0, 255, 255, 0.2);
|
159 |
}
|
160 |
|
161 |
+
/* Animações */
|
162 |
+
@keyframes pulse {
|
163 |
+
0% { box-shadow: 0 0 0 0 rgba(0, 255, 255, 0.4); }
|
164 |
+
70% { box-shadow: 0 0 0 20px rgba(0, 255, 255, 0); }
|
165 |
+
100% { box-shadow: 0 0 0 0 rgba(0, 255, 255, 0); }
|
166 |
+
}
|
167 |
+
|
168 |
+
@keyframes rotate {
|
169 |
+
from { transform: rotate(0deg); }
|
170 |
+
to { transform: rotate(360deg); }
|
171 |
+
}
|
172 |
+
|
173 |
+
/* Elementos da interface */
|
174 |
+
.aris-controls {
|
175 |
+
background: rgba(0, 0, 0, 0.7);
|
176 |
+
border: 2px solid var(--primary);
|
177 |
+
border-radius: 10px;
|
178 |
+
padding: 20px;
|
179 |
+
margin: 20px 0;
|
180 |
+
box-shadow: 0 0 15px rgba(0, 255, 255, 0.1);
|
181 |
+
}
|
182 |
+
|
183 |
+
.aris-textbox {
|
184 |
+
background-color: rgba(0, 0, 0, 0.8) !important;
|
185 |
+
border: 2px solid var(--primary) !important;
|
186 |
+
color: var(--primary) !important;
|
187 |
font-family: 'Courier New', monospace !important;
|
188 |
+
border-radius: 5px !important;
|
189 |
+
padding: 10px !important;
|
190 |
}
|
191 |
|
192 |
+
.aris-button {
|
193 |
background-color: transparent !important;
|
194 |
+
border: 2px solid var(--primary) !important;
|
195 |
+
color: var(--primary) !important;
|
196 |
font-family: 'Courier New', monospace !important;
|
197 |
+
text-transform: uppercase !important;
|
198 |
+
letter-spacing: 2px !important;
|
199 |
+
padding: 12px 24px !important;
|
200 |
+
border-radius: 5px !important;
|
201 |
+
transition: all 0.3s ease !important;
|
202 |
}
|
203 |
|
204 |
+
.aris-button:hover {
|
205 |
background-color: rgba(0, 255, 255, 0.1) !important;
|
206 |
+
box-shadow: 0 0 15px rgba(0, 255, 255, 0.3) !important;
|
207 |
+
transform: translateY(-2px) !important;
|
208 |
}
|
209 |
|
210 |
.status-box {
|
211 |
+
background-color: rgba(0, 0, 0, 0.8) !important;
|
212 |
+
border: 2px solid var(--primary) !important;
|
213 |
+
color: var(--primary) !important;
|
214 |
+
padding: 15px !important;
|
215 |
border-radius: 5px !important;
|
216 |
margin: 5px !important;
|
217 |
text-align: center !important;
|
218 |
+
text-transform: uppercase !important;
|
219 |
+
letter-spacing: 1px !important;
|
220 |
+
transition: all 0.3s ease !important;
|
221 |
+
position: relative;
|
222 |
+
overflow: hidden;
|
223 |
+
}
|
224 |
+
|
225 |
+
.status-box::before {
|
226 |
+
content: '';
|
227 |
+
position: absolute;
|
228 |
+
top: 0;
|
229 |
+
left: -100%;
|
230 |
+
width: 100%;
|
231 |
+
height: 2px;
|
232 |
+
background: linear-gradient(90deg, transparent, var(--primary));
|
233 |
+
animation: scan-line 2s linear infinite;
|
234 |
+
}
|
235 |
+
|
236 |
+
@keyframes scan-line {
|
237 |
+
0% { left: -100%; }
|
238 |
+
100% { left: 100%; }
|
239 |
+
}
|
240 |
+
|
241 |
+
.mode-indicator {
|
242 |
+
position: absolute;
|
243 |
+
top: 10px;
|
244 |
+
right: 10px;
|
245 |
+
padding: 5px 10px;
|
246 |
+
background-color: var(--accent);
|
247 |
+
color: var(--text);
|
248 |
+
border-radius: 3px;
|
249 |
+
font-size: 0.8em;
|
250 |
+
letter-spacing: 1px;
|
251 |
+
}
|
252 |
+
|
253 |
+
.stats-container {
|
254 |
+
display: grid;
|
255 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
256 |
+
gap: 15px;
|
257 |
+
margin-top: 20px;
|
258 |
+
}
|
259 |
+
|
260 |
+
.stat-item {
|
261 |
+
background: rgba(0, 0, 0, 0.7);
|
262 |
+
border: 1px solid var(--primary);
|
263 |
+
padding: 10px;
|
264 |
+
border-radius: 5px;
|
265 |
+
text-align: center;
|
266 |
+
color: var(--primary);
|
267 |
+
}
|
268 |
+
|
269 |
+
.language-pair-display {
|
270 |
+
display: flex;
|
271 |
+
align-items: center;
|
272 |
+
justify-content: center;
|
273 |
+
gap: 10px;
|
274 |
+
margin: 10px 0;
|
275 |
+
color: var(--primary);
|
276 |
+
font-size: 1.2em;
|
277 |
+
}
|
278 |
+
|
279 |
+
.language-pair-display::before,
|
280 |
+
.language-pair-display::after {
|
281 |
+
content: '⟨';
|
282 |
+
color: var(--secondary);
|
283 |
}
|
284 |
"""
|
285 |
|
286 |
def create_interface():
|
287 |
+
translator = ARISTranslator()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
+
def update_status():
|
290 |
+
return (
|
291 |
+
f"A.R.I.S. CORE v2.0.0\n"
|
292 |
+
f"Time: {datetime.now().strftime('%H:%M:%S')}\n"
|
293 |
+
f"Neural Engine: ACTIVE\n"
|
294 |
+
f"Translation Matrix: OPERATIONAL"
|
295 |
)
|
296 |
+
|
297 |
+
def start_realtime_translation(src_lang, tgt_lang):
|
298 |
+
translator.start_recording()
|
299 |
+
return "Real-time translation active..."
|
300 |
+
|
301 |
+
def stop_realtime_translation():
|
302 |
+
translator.stop_recording()
|
303 |
+
return "Translation stopped."
|
304 |
+
|
305 |
+
with gr.Blocks(css=css, title="A.R.I.S. - Advanced Real-time Interpretation System") as demo:
|
306 |
+
gr.HTML('''
|
307 |
+
<div class="title-container">
|
308 |
+
<h1>A.R.I.S.</h1>
|
309 |
+
<h3>Advanced Real-time Interpretation System</h3>
|
310 |
+
<div class="mode-indicator">QUANTUM CORE ACTIVE</div>
|
311 |
+
</div>
|
312 |
+
''')
|
313 |
|
314 |
+
with gr.Column(elem_id="aris-interface"):
|
|
|
|
|
315 |
gr.HTML("""
|
316 |
<div id="status-ring">
|
317 |
+
<div id="outer-ring-decoration"></div>
|
318 |
<div id="inner-ring">
|
319 |
<div id="core">
|
320 |
+
<div>A.R.I.S.</div>
|
321 |
+
<div>QUANTUM CORE</div>
|
322 |
+
<div>v2.0.0</div>
|
323 |
+
<div class="system-version">NEURAL ENGINE ACTIVE</div>
|
324 |
</div>
|
325 |
</div>
|
326 |
</div>
|
327 |
""")
|
328 |
|
|
|
329 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
with gr.Column():
|
331 |
+
with gr.Tab("Real-time Translation"):
|
332 |
+
src_lang_realtime = gr.Dropdown(
|
333 |
+
choices=list(translator.language_codes.keys()),
|
334 |
+
value="English (US)",
|
335 |
+
label="SOURCE LANGUAGE",
|
336 |
+
elem_classes=["aris-textbox"]
|
337 |
+
)
|
338 |
+
tgt_lang_realtime = gr.Dropdown(
|
339 |
+
choices=list(translator.language_codes.keys()),
|
340 |
+
value="Spanish (ES)",
|
341 |
+
label="TARGET LANGUAGE",
|
342 |
+
elem_classes=["aris-textbox"]
|
343 |
+
)
|
344 |
+
start_btn = gr.Button("▶ START REAL-TIME TRANSLATION", elem_classes=["aris-button"])
|
345 |
+
stop_btn = gr.Button("⬛ STOP TRANSLATION", elem_classes=["aris-button"])
|
346 |
+
status_realtime = gr.Textbox(label="REAL-TIME STATUS", elem_classes=["aris-textbox"])
|
347 |
+
|
348 |
+
with gr.Tab("Text Translation"):
|
349 |
+
text_input = gr.Textbox(
|
350 |
+
label="INPUT TEXT",
|
351 |
+
placeholder="Enter text for translation...",
|
352 |
+
elem_classes=["aris-textbox"],
|
353 |
+
lines=3
|
354 |
+
)
|
355 |
+
with gr.Row():
|
356 |
+
src_lang_text = gr.Dropdown(
|
357 |
+
choices=list(translator.language_codes.keys()),
|
358 |
+
value="English (US)",
|
359 |
+
label="SOURCE LANGUAGE",
|
360 |
+
elem_classes=["aris-textbox"]
|
361 |
+
)
|
362 |
+
tgt_lang_text = gr.Dropdown(
|
363 |
+
choices=list(translator.language_codes.keys()),
|
364 |
+
value="Spanish (ES)",
|
365 |
+
label="TARGET LANGUAGE",
|
366 |
+
elem_classes=["aris-textbox"]
|
367 |
+
)
|
368 |
+
translate_btn = gr.Button("▶ TRANSLATE TEXT", elem_classes=["aris-button"])
|
369 |
+
|
370 |
with gr.Column():
|
371 |
+
audio_output = gr.Audio(
|
372 |
+
label="TRANSLATION OUTPUT",
|
373 |
+
type="numpy"
|
|
|
|
|
|
|
|
|
374 |
)
|
375 |
+
|
376 |
+
with gr.Row():
|
377 |
+
with gr.Column(min_width=200):
|
378 |
+
gr.HTML(
|
379 |
+
"""
|
380 |
+
<div class="status-box">
|
381 |
+
NEURAL CORE<br>
|
382 |
+
<strong>OPERATIONAL</strong>
|
383 |
+
</div>
|
384 |
+
"""
|
385 |
+
)
|
386 |
+
with gr.Column(min_width=200):
|
387 |
+
gr.HTML(
|
388 |
+
"""
|
389 |
+
<div class="status-box">
|
390 |
+
QUANTUM ENGINE<br>
|
391 |
+
<strong>ACTIVE</strong>
|
392 |
+
</div>
|
393 |
+
"""
|
394 |
+
)
|
395 |
+
|
396 |
+
with gr.Row():
|
397 |
+
with gr.Column(min_width=200):
|
398 |
+
gr.HTML(
|
399 |
+
"""
|
400 |
+
<div class="status-box">
|
401 |
+
TRANSLATION MATRIX<br>
|
402 |
+
<strong>CALIBRATED</strong>
|
403 |
+
</div>
|
404 |
+
"""
|
405 |
+
)
|
406 |
+
with gr.Column(min_width=200):
|
407 |
+
gr.HTML(
|
408 |
+
"""
|
409 |
+
<div class="status-box">
|
410 |
+
VOICE SYNTHESIS<br>
|
411 |
+
<strong>READY</strong>
|
412 |
+
</div>
|
413 |
+
"""
|
414 |
+
)
|
415 |
+
|
416 |
+
# Sistema de estatísticas
|
417 |
+
with gr.Row():
|
418 |
+
gr.HTML("""
|
419 |
+
<div class="stats-container">
|
420 |
+
<div class="stat-item">
|
421 |
+
<div>Processing Speed</div>
|
422 |
+
<div style="font-size: 1.2em; margin: 5px 0;">0.8ms</div>
|
423 |
+
</div>
|
424 |
+
<div class="stat-item">
|
425 |
+
<div>Neural Load</div>
|
426 |
+
<div style="font-size: 1.2em; margin: 5px 0;">78%</div>
|
427 |
+
</div>
|
428 |
+
<div class="stat-item">
|
429 |
+
<div>Memory Usage</div>
|
430 |
+
<div style="font-size: 1.2em; margin: 5px 0;">4.2GB</div>
|
431 |
+
</div>
|
432 |
+
</div>
|
433 |
+
""")
|
434 |
+
|
435 |
+
# Event handlers
|
436 |
+
def update_stats():
|
437 |
+
return {
|
438 |
+
status_realtime: f"System Status: Active\nMemory Usage: {np.random.randint(70, 90)}%\nProcessing Speed: {np.random.randint(1, 5)}ms"
|
439 |
+
}
|
440 |
+
|
441 |
+
start_btn.click(
|
442 |
+
fn=start_realtime_translation,
|
443 |
+
inputs=[src_lang_realtime, tgt_lang_realtime],
|
444 |
+
outputs=status_realtime
|
445 |
+
)
|
446 |
|
447 |
+
stop_btn.click(
|
448 |
+
fn=stop_realtime_translation,
|
449 |
+
outputs=status_realtime
|
450 |
+
)
|
451 |
+
|
452 |
translate_btn.click(
|
453 |
+
fn=translator.translate_text,
|
454 |
+
inputs=[text_input, src_lang_text, tgt_lang_text],
|
455 |
outputs=audio_output
|
456 |
)
|
457 |
+
|
458 |
+
# Atualizações automáticas
|
459 |
+
demo.load(fn=update_status, outputs=status_realtime)
|
460 |
+
|
461 |
return demo
|
462 |
|
463 |
if __name__ == "__main__":
|
464 |
demo = create_interface()
|
465 |
demo.queue()
|
466 |
+
demo.launch()
|
467 |
+
|
468 |
+
# Arquivo requirements.txt atualizado
|
469 |
+
"""
|
470 |
+
gradio>=4.0.0
|
471 |
+
torch>=2.0.0
|
472 |
+
torchaudio>=2.0.0
|
473 |
+
transformers
|
474 |
+
sentencepiece>=0.1.99
|
475 |
+
numpy>=1.21.0
|
476 |
+
sounddevice>=0.4.5
|
477 |
+
"""
|