CVision-assitant commited on
Commit
79ee7e9
·
verified ·
1 Parent(s): a7755de

Update modules/interface.py

Browse files
Files changed (1) hide show
  1. modules/interface.py +461 -582
modules/interface.py CHANGED
@@ -3,631 +3,510 @@ import re
3
  import os
4
  import time
5
  import json
6
- from datetime import datetime
7
  from modules.listen import transcribe_audio_file
8
  from modules.talker.talk import speak
9
 
10
- # Importación de motores de chat con manejo de errores
11
  try:
12
  from modules.utils.chat_utils import (
13
  productivity_chat,
14
  browser_chat,
15
  scientist_chat,
16
  regular_chat,
17
- document_chat
18
  )
19
  except ImportError:
20
- print("Error: No se pudieron importar los módulos de chat. Asegúrate de que 'modules' esté en el path.")
21
 
22
- # ════════════════════════════════════════════════════════════
23
- # CONFIGURACIÓN GLOBAL Y CONSTANTES
24
- # ════════════════════════════════════════════════════════════
25
- PLACEHOLDER = "Sincronizando con el núcleo... Escribe aquí tu comando."
26
 
27
- # ════════════════════════════════════════════════════════════
28
- # CSS FUTURISTA — Diamante × Cyan
29
- # ════════════════════════════════════════════════════════════
30
  CUSTOM_CSS = """
31
- /* ── Google Fonts ── */
32
- @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;600;700;900&family=Exo+2:wght@300;400;500;600&family=Share+Tech+Mono&display=swap');
33
 
34
- /* ── Variables globales ── */
35
  :root {
36
- --c0: #000509;
37
- --c1: #020c18;
38
- --c2: #04182e;
39
- --cyan: #00d4ff;
40
- --cyan2: #00a8e8;
41
- --cyan-dim: rgba(0,212,255,0.10);
42
- --diamond: #e8f4ff;
43
- --diamond2: #b8d8f0;
44
- --text-main: #cce9f8;
45
- --text-muted: #5a8fab;
46
- --text-dim: #2a4a60;
47
- --border: rgba(0,212,255,0.16);
48
- --border-bright: rgba(0,212,255,0.45);
49
- --glass: rgba(4,24,46,0.78);
50
- --glass2: rgba(2,12,24,0.90);
51
- --radius: 12px;
52
- --radius-lg: 20px;
53
- --font-d: 'Orbitron', monospace;
54
- --font-b: 'Exo 2', sans-serif;
55
- --font-m: 'Share Tech Mono', monospace;
56
  }
57
 
58
- /* ── Reset base ── */
59
- *, *::before, *::after { box-sizing: border-box; }
60
  body, .gradio-container {
61
- background: var(--c0) !important;
62
- color: var(--text-main) !important;
63
- font-family: var(--font-b) !important;
64
- min-height: 100vh;
65
- margin: 0 !important;
66
  }
67
 
68
- /* scrollbar */
69
- ::-webkit-scrollbar { width: 4px; }
70
- ::-webkit-scrollbar-track { background: var(--c1); }
71
- ::-webkit-scrollbar-thumb { background: var(--cyan2); border-radius: 4px; }
72
-
73
- /* ── Grid de fondo ── */
74
- .gradio-container::before {
75
- content: '';
76
- position: fixed; inset: 0; z-index: 0; pointer-events: none;
77
- background-image:
78
- linear-gradient(rgba(0,212,255,0.028) 1px, transparent 1px),
79
- linear-gradient(90deg, rgba(0,212,255,0.028) 1px, transparent 1px);
80
- background-size: 44px 44px;
81
- mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black 0%, transparent 100%);
82
- }
83
-
84
- /* ── Scanline animado ── */
85
  .gradio-container::after {
86
- content: '';
87
- position: fixed; top: 0; left: 0; width: 100%; height: 2px;
88
- background: linear-gradient(90deg, transparent, rgba(0,212,255,0.3), transparent);
89
- animation: scanDown 7s ease-in-out infinite;
90
- z-index: 9999; pointer-events: none;
91
- }
92
- @keyframes scanDown {
93
- 0% { top: -2px; opacity: 0; }
94
- 8% { opacity: 1; }
95
- 92% { opacity: .4; }
96
- 100% { top: 100vh; opacity: 0; }
97
- }
 
 
 
98
 
99
  #cvision-header {
100
- background: var(--glass2);
101
- border-bottom: 1px solid var(--border);
102
- padding: 18px 32px;
103
- display: flex;
104
- align-items: center;
105
- gap: 18px;
106
- position: sticky; top: 0; z-index: 100;
107
- backdrop-filter: blur(20px);
108
- width: 100%;
109
- }
110
-
111
- #nebula-outer {
112
- display: flex;
113
- justify-content: center;
114
- align-items: flex-start;
115
- gap: 28px;
116
- padding: 28px 32px 20px;
117
- background: linear-gradient(180deg, rgba(0,212,255,0.04) 0%, transparent 100%);
118
- border-bottom: 1px solid var(--border);
119
- }
120
-
121
- #nebula-ring-wrap {
122
- position: relative;
123
- width: 230px; height: 230px;
124
- flex-shrink: 0;
125
- }
126
- #nebula-canvas-wrap {
127
- width: 230px; height: 230px;
128
- border-radius: 50%;
129
- border: 1.5px solid rgba(0,212,255,0.4);
130
- background: radial-gradient(circle, rgba(0,212,255,0.08) 0%, #04182e 70%);
131
- box-shadow: 0 0 50px rgba(0,212,255,0.22), inset 0 0 40px rgba(0,0,0,0.5);
132
- overflow: hidden;
133
- position: relative; z-index: 2;
134
- }
135
- #nebulaCanvas { width: 100%; height: 100%; display: block; }
136
-
137
- .nebula-deco-ring {
138
- position: absolute; border-radius: 50%; pointer-events: none;
139
- border: 0.5px solid rgba(0,212,255,0.13);
140
- }
141
- .nebula-deco-ring.r1 { inset: -20px; animation: spin 18s linear infinite; }
142
- .nebula-deco-ring.r2 { inset: -38px; border-style: dashed; animation: spin 30s linear infinite reverse; }
143
- @keyframes spin { to { transform: rotate(360deg); } }
144
-
145
- #nebula-info {
146
- display: flex; flex-direction: column; gap: 12px;
147
- padding: 10px 0 0 0; max-width: 540px;
148
- }
149
- .hero-eyebrow {
150
- font-family: var(--font-m); font-size: 0.58rem;
151
- letter-spacing: 0.3em; color: var(--text-muted);
152
- text-transform: uppercase;
153
- }
154
- .hero-title {
155
- font-family: var(--font-d); font-size: 2.1rem;
156
- font-weight: 900; line-height: 1.15;
157
- color: var(--diamond);
158
- text-shadow: 0 0 30px rgba(0,212,255,0.4);
159
- }
160
- .hero-title .accent {
161
- color: transparent;
162
- background: linear-gradient(135deg, #00d4ff 0%, #e8f4ff 50%, #00a8e8 100%);
163
- -webkit-background-clip: text; background-clip: text;
164
- }
165
- .hero-desc {
166
- font-size: 0.83rem; color: var(--text-muted);
167
- line-height: 1.7; font-weight: 300;
168
- }
169
- .hero-chips { display: flex; flex-wrap: wrap; gap: 7px; }
170
- .hero-chip {
171
- font-family: var(--font-m); font-size: 0.54rem;
172
- letter-spacing: 0.12em; padding: 5px 13px;
173
- border-radius: 20px; border: 1px solid rgba(0,212,255,0.22);
174
- background: rgba(0,212,255,0.05); color: var(--text-muted);
175
- }
176
-
177
- .tab-nav {
178
- background: var(--glass2) !important;
179
- border-bottom: 1px solid var(--border) !important;
180
- backdrop-filter: blur(10px);
181
- padding: 0 20px !important;
182
- gap: 0 !important;
183
- }
184
- .tab-nav button {
185
- font-family: var(--font-b) !important;
186
- font-size: 0.8rem !important;
187
- font-weight: 500 !important;
188
- letter-spacing: 0.05em !important;
189
- color: var(--text-muted) !important;
190
- background: transparent !important;
191
- border: none !important;
192
- border-bottom: 2px solid transparent !important;
193
- border-radius: 0 !important;
194
- padding: 14px 22px !important;
195
- transition: color 0.2s, border-color 0.2s !important;
196
- }
197
- .tab-nav button:hover { color: var(--diamond2) !important; }
198
- .tab-nav button.selected {
199
- color: var(--cyan) !important;
200
- border-bottom-color: var(--cyan) !important;
201
- background: transparent !important;
202
- }
203
-
204
- .chatbot-wrap .wrap {
205
- background: rgba(4,24,46,0.78) !important;
206
- border: 1px solid var(--border) !important;
207
- border-radius: var(--radius-lg) !important;
208
- backdrop-filter: blur(12px) !important;
209
- box-shadow: inset 0 0 40px rgba(0,0,0,0.3), 0 0 30px rgba(0,212,255,0.08) !important;
210
- }
211
- .chatbot-wrap .message.bot,
212
- .chatbot-wrap [data-testid="bot"] {
213
- background: linear-gradient(135deg, rgba(4,24,46,0.92), rgba(6,29,54,0.88)) !important;
214
- border: 1px solid rgba(0,212,255,0.14) !important;
215
- border-radius: 4px 18px 18px 18px !important;
216
- color: var(--text-main) !important;
217
- font-family: var(--font-b) !important;
218
- font-size: 0.85rem !important;
219
- box-shadow: 0 4px 18px rgba(0,0,0,0.3) !important;
220
- padding: 13px 17px !important;
221
- margin-right: 12% !important;
222
- }
223
- .chatbot-wrap .message.user,
224
- .chatbot-wrap [data-testid="user"] {
225
- background: linear-gradient(135deg, rgba(0,70,120,0.72), rgba(0,50,100,0.82)) !important;
226
- border: 1px solid rgba(0,160,230,0.22) !important;
227
- border-radius: 18px 4px 18px 18px !important;
228
- color: var(--diamond) !important;
229
- font-family: var(--font-b) !important;
230
- font-size: 0.85rem !important;
231
- box-shadow: 0 4px 18px rgba(0,0,0,0.3) !important;
232
- padding: 13px 17px !important;
233
- margin-left: 12% !important;
234
- }
235
-
236
- .cv-input textarea,
237
- .cv-input input[type="text"] {
238
- background: rgba(4,24,46,0.82) !important;
239
- border: 1px solid rgba(0,212,255,0.18) !important;
240
- border-radius: var(--radius) !important;
241
- color: var(--text-main) !important;
242
- font-family: var(--font-b) !important;
243
- font-size: 0.85rem !important;
244
- padding: 13px 16px !important;
245
- transition: border-color 0.2s, box-shadow 0.2s !important;
246
- caret-color: var(--cyan) !important;
247
- resize: none !important;
248
- }
249
- .cv-input textarea::placeholder,
250
- .cv-input input::placeholder {
251
- color: var(--text-dim) !important;
252
- font-family: var(--font-m) !important;
253
- font-size: 0.72rem !important;
254
- letter-spacing: 0.08em !important;
255
- }
256
- .cv-input textarea:focus,
257
- .cv-input input:focus {
258
- border-color: rgba(0,212,255,0.48) !important;
259
- box-shadow: 0 0 18px rgba(0,212,255,0.1) !important;
260
- outline: none !important;
261
- }
262
- .cv-input > .wrap { border: none !important; background: transparent !important; box-shadow: none !important; }
263
- .cv-input label { display: none !important; }
264
-
265
- .btn-send {
266
- background: linear-gradient(135deg, #004a7c, #0070b8, #00a8e8) !important;
267
- color: #fff !important;
268
- border: none !important;
269
- border-radius: var(--radius) !important;
270
- font-family: var(--font-b) !important;
271
- font-weight: 600 !important;
272
- font-size: 0.8rem !important;
273
- letter-spacing: 0.08em !important;
274
- padding: 0 22px !important;
275
- min-height: 48px !important;
276
- box-shadow: 0 0 20px rgba(0,168,232,0.28), inset 0 1px 0 rgba(255,255,255,0.12) !important;
277
- transition: box-shadow 0.2s, transform 0.15s !important;
278
- }
279
- .btn-send:hover {
280
- box-shadow: 0 0 32px rgba(0,212,255,0.45) !important;
281
- }
282
- .btn-send:active { transform: scale(0.97) !important; }
283
-
284
- .btn-voice {
285
- background: transparent !important;
286
- border: 1px solid rgba(0,212,255,0.32) !important;
287
- color: var(--cyan) !important;
288
- border-radius: var(--radius) !important;
289
- font-family: var(--font-b) !important;
290
- font-weight: 500 !important;
291
- font-size: 0.78rem !important;
292
- letter-spacing: 0.06em !important;
293
- min-height: 48px !important;
294
- padding: 0 18px !important;
295
- transition: all 0.2s !important;
296
- }
297
- .btn-voice:hover {
298
- background: var(--cyan-dim) !important;
299
- border-color: var(--border-bright) !important;
300
- box-shadow: 0 0 14px rgba(0,212,255,0.2) !important;
301
- }
302
-
303
- .btn-clear {
304
- background: transparent !important;
305
- border: 1px solid rgba(255,60,80,0.2) !important;
306
- color: rgba(255,100,120,0.65) !important;
307
- border-radius: var(--radius) !important;
308
- font-family: var(--font-b) !important;
309
- font-size: 0.75rem !important;
310
- min-height: 40px !important;
311
- padding: 0 16px !important;
312
- transition: all 0.2s !important;
313
- }
314
- .btn-clear:hover {
315
- border-color: rgba(255,60,80,0.45) !important;
316
- background: rgba(255,60,80,0.06) !important;
317
- color: #ff6477 !important;
318
- }
319
-
320
- .cv-mic .wrap,
321
- .cv-audio-out .wrap {
322
- background: rgba(4,24,46,0.6) !important;
323
- border: 1px solid var(--border) !important;
324
- border-radius: var(--radius) !important;
325
- color: var(--text-muted) !important;
326
- }
327
- .cv-mic label, .cv-audio-out label {
328
- font-family: var(--font-m) !important;
329
- font-size: 0.58rem !important;
330
- letter-spacing: 0.18em !important;
331
- color: var(--text-dim) !important;
332
- }
333
- .cv-audio-out { visibility: hidden; height: 0; overflow: hidden; }
334
-
335
- .cv-row-input {
336
- display: flex; gap: 10px; align-items: flex-end;
337
- padding: 0 !important;
338
- }
339
- .cv-row-actions {
340
- display: flex; gap: 8px; align-items: center;
341
- }
342
-
343
- #cv-statusbar {
344
- position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
345
- font-family: var(--font-m); font-size: 0.52rem; letter-spacing: 0.18em;
346
- color: rgba(0,212,255,0.3);
347
- display: flex; align-items: center; gap: 18px;
348
- pointer-events: none; z-index: 500;
349
- }
350
- .cv-status-dot {
351
- width: 5px; height: 5px; border-radius: 50%;
352
- background: rgba(0,212,255,0.4);
353
- animation: blinkDot 2s ease-in-out infinite;
354
- display: inline-block;
355
  }
356
- @keyframes blinkDot { 0%,100%{opacity:.2} 50%{opacity:1} }
357
-
358
  footer { display: none !important; }
359
- .app { background: transparent !important; }
360
- .gap { gap: 12px !important; }
361
- .contain { background: transparent !important; }
362
- .gradio-container .block { background: transparent !important; border: none !important; box-shadow: none !important; }
363
  """
364
 
365
- # ════════════════════════════════════════════════════════════
366
- # HTML & JS
367
- # ════════════════════════════════════════════════════════════
368
  HEADER_HTML = """
369
  <div id="cvision-header">
370
- <div style="width:52px;height:52px;border-radius:50%;
371
- border:1.5px solid rgba(0,212,255,0.5);
372
- background:radial-gradient(circle,rgba(0,212,255,0.15) 0%,#04182e 100%);
373
- display:flex;align-items:center;justify-content:center;
374
- box-shadow:0 0 20px rgba(0,212,255,0.35);
375
- position:relative;overflow:hidden;flex-shrink:0;">
376
- <img src="file/assets/CVision logo.png" style="width:80%; height:80%; object-fit:contain; position:relative; z-index:1;" alt="CV">
377
- <div style="position:absolute;inset:-50%;width:200%;height:200%;
378
- background:conic-gradient(from 0deg,transparent 60%,rgba(0,212,255,0.2) 80%,transparent 100%);
379
- animation:spinHeaderConic 4s linear infinite;"></div>
380
- </div>
381
- <div style="flex:1">
382
- <div style="font-family:'Orbitron',monospace;font-size:1.45rem;font-weight:900;
383
- color:#fff;letter-spacing:0.12em;
384
- text-shadow:0 0 20px rgba(0,212,255,0.6);">
385
- Asistente Virtual C<span style="color:#00d4ff">Vision</span>
386
- </div>
387
- <div style="font-family:'Share Tech Mono',monospace;font-size:0.58rem;
388
- letter-spacing:0.22em;color:#5a8fab;margin-top:4px;">
389
- NÚCLEO COGNITIVO MULTIMODAL · CRISTIAN VELASCO
390
- </div>
391
- </div>
392
- <div style="display:flex;gap:8px;align-items:center">
393
- <div style="width:7px;height:7px;border-radius:50%;background:#00ff96;
394
- box-shadow:0 0 8px #00ff96;animation:blinkDot 2s ease-in-out infinite;"></div>
395
- <span style="font-family:'Share Tech Mono',monospace;font-size:0.52rem;
396
- letter-spacing:0.14em;padding:3px 10px;border-radius:20px;
397
- border:1px solid rgba(0,255,150,0.3);background:rgba(0,255,150,0.07);
398
- color:#00ff96;">ONLINE</span>
399
- </div>
 
 
 
 
 
 
 
 
 
 
400
  </div>
401
  """
402
 
403
- NEBULA_HTML = """
404
- <div id="nebula-outer">
405
- <div id="nebula-ring-wrap">
406
- <div class="nebula-deco-ring r1"></div>
407
- <div class="nebula-deco-ring r2"></div>
408
- <div id="nebula-canvas-wrap">
409
- <canvas id="nebulaCanvas"></canvas>
410
- </div>
411
- </div>
412
- <div id="nebula-info">
413
- <div class="hero-eyebrow">// SISTEMA ACTIVADO · CORE OPERATIVO</div>
414
- <div class="hero-title">Asistente Virtual<br><span class="accent">CVision</span></div>
415
- <div class="hero-desc">Interfaz de inteligencia artificial multimodal.</div>
416
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  </div>
418
  """
419
 
420
- STATUS_BAR_HTML = """
421
- <div id="cv-statusbar">
422
- <span>CORE ACTIVE</span>
423
- <span class="cv-status-dot"></span>
424
- <span id="cv-clock">00:00:00</span>
 
 
 
 
425
  </div>
426
- """
427
-
428
- NEBULA_JS = """
429
  <script>
430
- (function waitForCanvas() {
431
- const cv = document.getElementById('nebulaCanvas');
432
- if (!cv) { setTimeout(waitForCanvas, 300); return; }
433
- initNebula(cv);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
  })();
435
-
436
- function initNebula(cv) {
437
- const ctx = cv.getContext('2d');
438
- let W, H, cx, cy, neurons = [], pulses = [], synapses = [], pulseTimer = 0;
439
- const N = 36, CONN = 65;
440
-
441
- function resize() {
442
- W = cv.width = cv.offsetWidth || 230;
443
- H = cv.height = cv.offsetHeight || 230;
444
- cx = W / 2; cy = H / 2;
445
- build();
446
- }
447
-
448
- class Neuron {
449
- constructor(i) {
450
- this.layer = 1 + (i % 3);
451
- this.angle = Math.random() * Math.PI * 2;
452
- const spread = Math.min(W, H) * 0.46;
453
- this.baseR = spread * (0.14 + this.layer * 0.2 + Math.random() * 0.07);
454
- this.speed = (Math.random() < .5 ? 1 : -1) * (.001 + Math.random() * 0.002);
455
- this.osc = 2 + Math.random() * 6;
456
- this.t = Math.random() * 100;
457
- this.r = 1.1 + Math.random() * 1.5;
458
- this.alpha = .4 + Math.random() * .5;
459
- this.firing = 0;
460
- this.fireTimer = Math.random() * 180;
461
- this.x = cx; this.y = cy;
462
- this._step();
463
- }
464
- _step() {
465
- this.t += .012; this.angle += this.speed;
466
- const r = this.baseR + Math.sin(this.t) * this.osc;
467
- this.x = cx + Math.cos(this.angle) * r;
468
- this.y = cy + Math.sin(this.angle) * r;
469
- this.fireTimer--;
470
- if (this.fireTimer <= 0) { this.firing = 1; this.fireTimer = 80 + Math.random() * 200; }
471
- if (this.firing > 0) this.firing = Math.max(0, this.firing - .025);
472
- }
473
- draw() {
474
- ctx.globalAlpha = this.alpha * (.4 + this.firing * .6);
475
- ctx.fillStyle = this.firing > .3 ? `rgba(255,255,255,${this.firing})` : 'rgba(0,190,255,.85)';
476
- ctx.beginPath(); ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2); ctx.fill();
477
- }
478
- }
479
-
480
- class Pulse {
481
- constructor(a, b) { this.a = a; this.b = b; this.t = 0; this.s = .01 + Math.random() * .014; this.done = false; }
482
- tick() { this.t += this.s; if (this.t >= 1) { this.done = true; this.b.firing = 1; } }
483
- draw() {
484
- const x = this.a.x + (this.b.x - this.a.x) * this.t;
485
- const y = this.a.y + (this.b.y - this.a.y) * this.t;
486
- ctx.fillStyle = '#fff'; ctx.beginPath(); ctx.arc(x, y, 1.8, 0, Math.PI * 2); ctx.fill();
487
- }
488
- }
489
-
490
- function build() {
491
- neurons = []; pulses = []; synapses = [];
492
- for (let i = 0; i < N; i++) neurons.push(new Neuron(i));
493
- for (let i = 0; i < neurons.length; i++) {
494
- let added = 0;
495
- for (let j = i + 1; j < neurons.length; j++) {
496
- const dx = neurons[i].x - neurons[j].x, dy = neurons[i].y - neurons[j].y;
497
- if (Math.sqrt(dx*dx + dy*dy) < CONN && added < 3) { synapses.push([i, j]); added++; }
498
- }
499
- }
500
- }
501
-
502
- function drawSynapses() {
503
- for (const s of synapses) {
504
- const a = neurons[s[0]], b = neurons[s[1]];
505
- ctx.globalAlpha = 0.1;
506
- ctx.strokeStyle = '#00d4ff';
507
- ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.lineTo(b.x, b.y); ctx.stroke();
508
- }
509
- }
510
-
511
- function drawLogo() {
512
- ctx.font = "bold 19px 'Orbitron',monospace";
513
- ctx.textAlign = 'center'; ctx.fillStyle = '#fff';
514
- ctx.fillText('CVision', cx, cy);
515
- }
516
-
517
- function loop() {
518
- requestAnimationFrame(loop);
519
- ctx.clearRect(0, 0, W, H);
520
- for (const n of neurons) n._step();
521
- drawSynapses();
522
- for (const n of neurons) n.draw();
523
- pulseTimer++;
524
- if (pulseTimer % 25 === 0 && synapses.length) {
525
- const s = synapses[Math.floor(Math.random() * synapses.length)];
526
- pulses.push(new Pulse(neurons[s[0]], neurons[s[1]]));
527
- }
528
- pulses = pulses.filter(p => !p.done);
529
- for (const p of pulses) { p.tick(); p.draw(); }
530
- drawLogo();
531
- }
532
-
533
- window.addEventListener('resize', resize, { passive: true });
534
- resize();
535
- loop();
536
-
537
- function updateClock() {
538
- const el = document.getElementById('cv-clock');
539
- if (!el) return;
540
- const n = new Date(), p = x => String(x).padStart(2, '0');
541
- el.textContent = p(n.getHours()) + ':' + p(n.getMinutes()) + ':' + p(n.getSeconds());
542
- }
543
- setInterval(updateClock, 1000);
544
- updateClock();
545
- }
546
  </script>
547
  """
548
 
549
- # ════════════════════════════════════════════════════════════
550
- # LÓGICA DEL NÚCLEO
551
- # ════════════════════════════════════════════════════════════
552
-
553
- def clean_message_logic(text_input):
554
- if not text_input: return ""
555
- res = str(text_input)
556
- res = re.sub(r"<generator object.*?>", "", res)
557
- split_pattern = r"'\],\s*\['|\"\],\s*\[\"|'\],\s*\('|\"\],\s*\(\"|\"\],\s*\"|'\],\s*'"
558
- if "]," in res and re.search(split_pattern, res):
559
- fragments = re.split(split_pattern, res)
560
- res = fragments[-1]
561
- res = res.replace("(['", "").replace("'])", "").replace("['", "").replace("']", "")
562
- res = res.strip("[]()', \"")
563
- return res.strip()
564
-
565
- def unified_chat_handler(chat_history, user_text, mode_key, voice_enabled):
566
- if not user_text: return chat_history, "", None
567
- funcs = {"general": regular_chat, "web": browser_chat, "productividad": productivity_chat, "cientifico": scientist_chat}
568
- target_func = funcs.get(mode_key, regular_chat)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
569
  try:
570
- raw_out = target_func(chat_history, user_text)
571
- final_msg = raw_out[-1][1] if isinstance(raw_out, list) else str(raw_out)
572
- clean_reply = clean_message_logic(final_msg)
573
- chat_history.append((user_text, clean_reply))
574
- reply_audio = speak(clean_reply[:350]) if voice_enabled else None
575
- return chat_history, "", reply_audio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576
  except Exception as e:
577
- chat_history.append((user_text, f"⚠️ Error técnico: {e}"))
578
- return chat_history, "", None
579
-
580
- def transcribe_wrapper(audio):
581
- if not audio: return ""
582
- try: return transcribe_audio_file(audio)
583
- except: return "⚠️ Error al transcribir."
584
-
585
- # ════════════════════════════════════════════════════════════
586
- # INTERFAZ GRADIO
587
- # ════════════════════════════════════════════════════════════
588
- with gr.Blocks(css=CUSTOM_CSS, head=HEADER_HTML+NEBULA_HTML+NEBULA_JS+STATUS_BAR_HTML, title="CVision Neural Intelligence") as assistant:
589
-
590
- voice_active = gr.State(False)
591
-
592
- def create_cognitive_tab(mode_id):
593
- chatbot = gr.Chatbot(height=520, bubble_full_width=False, elem_classes="chatbot-wrap", type="tuples")
594
- audio_reply_output = gr.Audio(visible=False, autoplay=True, elem_classes="cv-audio-out")
595
-
596
- with gr.Row(elem_classes="cv-row-input"):
597
- txt_in = gr.Textbox(placeholder=PLACEHOLDER, scale=8, elem_classes="cv-input", container=False)
598
- btn_voice_control = gr.Button("⚡ Voz: OFF", scale=2, elem_classes="btn-voice")
599
- btn_send = gr.Button("Enviar ↗", variant="primary", scale=2, elem_classes="btn-send")
600
-
601
- with gr.Row(elem_classes="cv-row-actions"):
602
- audio_in = gr.Audio(sources=["microphone"], type="filepath", label="Micrófono Cognitivo", scale=4, elem_classes="cv-mic")
603
- btn_clear = gr.Button("Limpiar Núcleo 🗑️", scale=1, elem_classes="btn-clear")
604
-
605
- def toggle_voice(status):
606
- new_status = not status
607
- label = "⚡ Voz: ON" if new_status else "⚡ Voz: OFF"
608
- variant = "primary" if new_status else "secondary"
609
- return new_status, gr.update(value=label, variant=variant)
610
-
611
- btn_voice_control.click(toggle_voice, [voice_active], [voice_active, btn_voice_control])
612
-
613
- # Envíos
614
- input_params = [chatbot, txt_in, gr.State(mode_id), voice_active]
615
- output_params = [chatbot, txt_in, audio_reply_output]
616
-
617
- btn_send.click(unified_chat_handler, input_params, output_params)
618
- txt_in.submit(unified_chat_handler, input_params, output_params)
619
-
620
- def audio_to_text_and_send(chat_history, audio_file, mode, voice_on):
621
- text = transcribe_wrapper(audio_file)
622
- if not text or text.startswith("⚠️"): return chat_history, text, None
623
- return unified_chat_handler(chat_history, text, mode, voice_on)
624
-
625
- audio_in.stop_recording(audio_to_text_and_send, [chatbot, audio_in, gr.State(mode_id), voice_active], output_params)
626
- btn_clear.click(lambda: ([], "", None), None, output_params)
627
-
628
- with gr.Tabs(elem_classes="tab-nav"):
629
- with gr.Tab("NÚCLEO GENERAL"): create_cognitive_tab("general")
630
- with gr.Tab("EXPLORACIÓN WEB"): create_cognitive_tab("web")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
631
 
632
  if __name__ == "__main__":
633
- assistant.launch()
 
 
 
 
3
  import os
4
  import time
5
  import json
 
6
  from modules.listen import transcribe_audio_file
7
  from modules.talker.talk import speak
8
 
 
9
  try:
10
  from modules.utils.chat_utils import (
11
  productivity_chat,
12
  browser_chat,
13
  scientist_chat,
14
  regular_chat,
15
+ document_chat,
16
  )
17
  except ImportError:
18
+ print("Error: No se pudieron importar los módulos de chat.")
19
 
20
+ PLACEHOLDER = "Escribe tu mensaje para CVision..."
 
 
 
21
 
 
 
 
22
  CUSTOM_CSS = """
23
+ @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Exo+2:wght@300;400;500&family=Share+Tech+Mono&display=swap');
 
24
 
 
25
  :root {
26
+ --cyan: #00d4ff;
27
+ --cyan2: #00a8e8;
28
+ --diamond: #e8f4ff;
29
+ --text-muted: #5a8fab;
30
+ --text-dim: #2a4a60;
31
+ --border: rgba(0,212,255,0.16);
32
+ --glass2: rgba(2,12,24,0.90);
33
+ --font-d: 'Orbitron', monospace;
34
+ --font-b: 'Exo 2', sans-serif;
35
+ --font-m: 'Share Tech Mono', monospace;
 
 
 
 
 
 
 
 
 
 
36
  }
37
 
 
 
38
  body, .gradio-container {
39
+ background: #0a0f1e !important;
40
+ color: white !important;
41
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
 
 
42
  }
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  .gradio-container::after {
45
+ content: '';
46
+ position: fixed; top: 0; left: 0; width: 100%; height: 2px;
47
+ background: linear-gradient(90deg, transparent, rgba(0,212,255,0.30), transparent);
48
+ animation: cvScanDown 7s ease-in-out infinite;
49
+ z-index: 9999; pointer-events: none;
50
+ }
51
+ @keyframes cvScanDown {
52
+ 0% { top: -2px; opacity: 0; }
53
+ 8% { opacity: 1; }
54
+ 92% { opacity: .4; }
55
+ 100% { top: 100vh; opacity: 0; }
56
+ }
57
+ @keyframes cvSpin { to { transform: rotate(360deg); } }
58
+ @keyframes cvBlink { 0%,100%{opacity:.25} 50%{opacity:1} }
59
+ @keyframes cvOrbit { to { transform: rotate(360deg); } }
60
 
61
  #cvision-header {
62
+ background: var(--glass2);
63
+ border-bottom: 1px solid var(--border);
64
+ padding: 16px 28px;
65
+ display: flex;
66
+ align-items: center;
67
+ gap: 16px;
68
+ backdrop-filter: blur(20px);
69
+ -webkit-backdrop-filter: blur(20px);
70
+ }
71
+
72
+ #cvision-nebula-section {
73
+ display: flex;
74
+ justify-content: center;
75
+ align-items: flex-start;
76
+ gap: 28px;
77
+ padding: 26px 32px 20px;
78
+ background: linear-gradient(180deg, rgba(0,212,255,0.04) 0%, transparent 100%);
79
+ border-bottom: 1px solid var(--border);
80
+ }
81
+
82
+ #cvision-statusbar {
83
+ position: fixed; bottom: 16px; left: 50%;
84
+ transform: translateX(-50%);
85
+ font-family: var(--font-m); font-size: 0.52rem;
86
+ letter-spacing: 0.18em; color: rgba(0,212,255,0.30);
87
+ display: flex; align-items: center; gap: 16px;
88
+ pointer-events: none; z-index: 500;
89
+ }
90
+ .cv-sdot {
91
+ width: 5px; height: 5px; border-radius: 50%;
92
+ background: rgba(0,212,255,0.4);
93
+ animation: cvBlink 2s ease-in-out infinite;
94
+ display: inline-block;
95
+ }
96
+
97
+ .chatbot-container {
98
+ border-radius: 20px !important;
99
+ border: 1px solid rgba(0,210,255,0.3) !important;
100
+ background: #0d1117 !important;
101
+ box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
102
+ }
103
+ .chatbot-container .message.user,
104
+ .chatbot-container [data-testid="user"] {
105
+ background: linear-gradient(135deg,rgba(0,70,120,0.72),rgba(0,50,100,0.82)) !important;
106
+ border: 1px solid rgba(0,160,230,0.22) !important;
107
+ border-radius: 18px 4px 18px 18px !important;
108
+ color: #e8f4ff !important;
109
+ padding: 13px 17px !important;
110
+ margin-left: 12% !important;
111
+ box-shadow: 0 4px 18px rgba(0,0,0,0.3) !important;
112
+ }
113
+ .chatbot-container .message.bot,
114
+ .chatbot-container [data-testid="bot"] {
115
+ background: linear-gradient(135deg,rgba(4,24,46,0.92),rgba(6,29,54,0.88)) !important;
116
+ border: 1px solid rgba(0,212,255,0.14) !important;
117
+ border-radius: 4px 18px 18px 18px !important;
118
+ color: #cce9f8 !important;
119
+ padding: 13px 17px !important;
120
+ margin-right: 12% !important;
121
+ box-shadow: 0 4px 18px rgba(0,0,0,0.3) !important;
122
+ }
123
+
124
+ .btn-primary-cv {
125
+ background: linear-gradient(135deg,#004a7c,#0070b8,#00a8e8) !important;
126
+ border: none !important; color: white !important;
127
+ border-radius: 12px !important;
128
+ font-weight: 600 !important; font-size: 0.8rem !important;
129
+ box-shadow: 0 0 18px rgba(0,168,232,0.28) !important;
130
+ transition: box-shadow 0.2s !important;
131
+ }
132
+ .btn-primary-cv:hover { box-shadow: 0 0 30px rgba(0,212,255,0.45) !important; }
133
+ .btn-secondary-cv {
134
+ background: transparent !important;
135
+ border: 1px solid rgba(0,212,255,0.32) !important;
136
+ color: #00d4ff !important; border-radius: 12px !important;
137
+ font-size: 0.78rem !important; transition: all 0.2s !important;
138
+ }
139
+ .btn-secondary-cv:hover {
140
+ background: rgba(0,212,255,0.08) !important;
141
+ box-shadow: 0 0 14px rgba(0,212,255,0.2) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  }
 
 
143
  footer { display: none !important; }
 
 
 
 
144
  """
145
 
 
 
 
146
  HEADER_HTML = """
147
  <div id="cvision-header">
148
+ <div style="width:50px;height:50px;border-radius:50%;
149
+ border:1.5px solid rgba(0,212,255,0.5);
150
+ background:radial-gradient(circle,rgba(0,212,255,0.15) 0%,#04182e 100%);
151
+ display:flex;align-items:center;justify-content:center;
152
+ font-family:'Orbitron',monospace;font-size:0.58rem;font-weight:700;
153
+ color:#00d4ff;letter-spacing:0.04em;
154
+ box-shadow:0 0 20px rgba(0,212,255,0.35);
155
+ position:relative;overflow:hidden;flex-shrink:0;">
156
+ <span style="position:relative;z-index:1;">CV</span>
157
+ <div style="position:absolute;inset:-50%;width:200%;height:200%;
158
+ background:conic-gradient(from 0deg,transparent 60%,rgba(0,212,255,0.22) 80%,transparent 100%);
159
+ animation:cvSpin 4s linear infinite;"></div>
160
+ </div>
161
+ <div style="flex:1;">
162
+ <div style="font-family:'Orbitron',monospace;font-size:1.4rem;font-weight:900;
163
+ color:#fff;letter-spacing:0.12em;line-height:1;
164
+ text-shadow:0 0 20px rgba(0,212,255,0.55);">
165
+ C<span style="color:#00d4ff;">Vision</span> Intelligence
166
+ </div>
167
+ <div style="font-family:'Share Tech Mono',monospace;font-size:0.56rem;
168
+ letter-spacing:0.22em;color:#5a8fab;margin-top:5px;">
169
+ ASISTENTE TÉCNICO MULTIMODAL &nbsp;·&nbsp; CRISTIAN VELASCO
170
+ </div>
171
+ </div>
172
+ <div style="display:flex;gap:8px;align-items:center;">
173
+ <div style="width:7px;height:7px;border-radius:50%;background:#00ff96;
174
+ box-shadow:0 0 8px #00ff96;animation:cvBlink 2s ease-in-out infinite;"></div>
175
+ <span style="font-family:'Share Tech Mono',monospace;font-size:0.5rem;
176
+ letter-spacing:0.14em;padding:3px 10px;border-radius:20px;
177
+ border:1px solid rgba(0,255,150,0.3);background:rgba(0,255,150,0.07);
178
+ color:#00ff96;">ONLINE</span>
179
+ <span style="font-family:'Share Tech Mono',monospace;font-size:0.5rem;
180
+ letter-spacing:0.14em;padding:3px 10px;border-radius:20px;
181
+ border:1px solid rgba(0,212,255,0.28);background:rgba(0,212,255,0.07);
182
+ color:#00d4ff;">v3.1.0</span>
183
+ <span style="font-family:'Share Tech Mono',monospace;font-size:0.5rem;
184
+ letter-spacing:0.14em;padding:3px 10px;border-radius:20px;
185
+ border:1px solid rgba(0,212,255,0.28);background:rgba(0,212,255,0.07);
186
+ color:#00d4ff;">NEURAL · ACTIVE</span>
187
+ </div>
188
  </div>
189
  """
190
 
191
+ NEBULA_SECTION_HTML = """
192
+ <div id="cvision-nebula-section">
193
+ <div style="position:relative;width:230px;height:230px;flex-shrink:0;">
194
+ <div style="position:absolute;inset:-20px;border-radius:50%;
195
+ border:0.5px solid rgba(0,212,255,0.13);
196
+ animation:cvOrbit 18s linear infinite;"></div>
197
+ <div style="position:absolute;inset:-38px;border-radius:50%;
198
+ border:0.5px dashed rgba(0,212,255,0.08);
199
+ animation:cvOrbit 30s linear infinite reverse;"></div>
200
+ <div style="width:230px;height:230px;border-radius:50%;
201
+ border:1.5px solid rgba(0,212,255,0.42);
202
+ background:radial-gradient(circle,rgba(0,212,255,0.08) 0%,#04182e 70%);
203
+ box-shadow:0 0 50px rgba(0,212,255,0.22),inset 0 0 40px rgba(0,0,0,0.5);
204
+ overflow:hidden;position:relative;z-index:2;">
205
+ <canvas id="nebulaCanvas" style="width:100%;height:100%;display:block;"></canvas>
206
+ </div>
207
+ </div>
208
+ <div style="display:flex;flex-direction:column;gap:11px;padding-top:8px;max-width:500px;">
209
+ <div style="font-family:'Share Tech Mono',monospace;font-size:0.57rem;
210
+ letter-spacing:0.28em;color:#5a8fab;text-transform:uppercase;">
211
+ // SISTEMA ACTIVADO &nbsp;·&nbsp; CORE OPERATIVO
212
+ </div>
213
+ <div style="font-family:'Orbitron',monospace;font-size:1.95rem;
214
+ font-weight:900;line-height:1.15;color:#e8f4ff;
215
+ text-shadow:0 0 28px rgba(0,212,255,0.4);">
216
+ Asistente<br>
217
+ <span style="color:transparent;
218
+ background:linear-gradient(135deg,#00d4ff 0%,#e8f4ff 50%,#00a8e8 100%);
219
+ -webkit-background-clip:text;background-clip:text;">CVision</span>
220
+ </div>
221
+ <div style="font-family:'Exo 2',sans-serif;font-size:0.82rem;
222
+ color:#5a8fab;line-height:1.7;font-weight:300;">
223
+ Interfaz de inteligencia artificial multimodal. Combina procesamiento de lenguaje
224
+ natural, análisis de documentos y búsqueda web en un solo núcleo cognitivo.
225
+ </div>
226
+ <div style="display:flex;flex-wrap:wrap;gap:7px;">
227
+ <span style="font-family:'Share Tech Mono',monospace;font-size:0.53rem;letter-spacing:0.11em;
228
+ padding:5px 12px;border-radius:20px;border:1px solid rgba(0,212,255,0.22);
229
+ background:rgba(0,212,255,0.05);color:#5a8fab;">PROCESAMIENTO NLP</span>
230
+ <span style="font-family:'Share Tech Mono',monospace;font-size:0.53rem;letter-spacing:0.11em;
231
+ padding:5px 12px;border-radius:20px;border:1px solid rgba(0,212,255,0.22);
232
+ background:rgba(0,212,255,0.05);color:#5a8fab;">VISIÓN COMPUTACIONAL</span>
233
+ <span style="font-family:'Share Tech Mono',monospace;font-size:0.53rem;letter-spacing:0.11em;
234
+ padding:5px 12px;border-radius:20px;border:1px solid rgba(0,212,255,0.22);
235
+ background:rgba(0,212,255,0.05);color:#5a8fab;">BÚSQUEDA WEB</span>
236
+ <span style="font-family:'Share Tech Mono',monospace;font-size:0.53rem;letter-spacing:0.11em;
237
+ padding:5px 12px;border-radius:20px;border:1px solid rgba(0,212,255,0.22);
238
+ background:rgba(0,212,255,0.05);color:#5a8fab;">ANÁLISIS PDF</span>
239
+ <span style="font-family:'Share Tech Mono',monospace;font-size:0.53rem;letter-spacing:0.11em;
240
+ padding:5px 12px;border-radius:20px;border:1px solid rgba(0,212,255,0.22);
241
+ background:rgba(0,212,255,0.05);color:#5a8fab;">VOZ</span>
242
+ </div>
243
+ </div>
244
  </div>
245
  """
246
 
247
+ STATUS_AND_JS_HTML = """
248
+ <div id="cvision-statusbar">
249
+ <span>CORE ACTIVE</span>
250
+ <span class="cv-sdot"></span>
251
+ <span>ALL SYSTEMS NOMINAL</span>
252
+ <span class="cv-sdot" style="animation-delay:.6s"></span>
253
+ <span id="cv-clock">00:00:00</span>
254
+ <span class="cv-sdot" style="animation-delay:1.2s"></span>
255
+ <span>SCANNING</span>
256
  </div>
 
 
 
257
  <script>
258
+ (function waitCanvas() {
259
+ const cv = document.getElementById('nebulaCanvas');
260
+ if (!cv) { setTimeout(waitCanvas, 300); return; }
261
+ startNebula(cv);
262
+ })();
263
+ function startNebula(cv) {
264
+ const ctx = cv.getContext('2d');
265
+ let W,H,cx,cy,neurons=[],pulses=[],synapses=[],pulseTimer=0;
266
+ const N=44,CONN=72;
267
+ function resize(){
268
+ W=cv.width=cv.offsetWidth||230; H=cv.height=cv.offsetHeight||230;
269
+ cx=W/2; cy=H/2; build();
270
+ }
271
+ class Neuron {
272
+ constructor(i){
273
+ this.layer=1+(i%3); this.angle=Math.random()*Math.PI*2;
274
+ const spread=Math.min(W,H)*0.46;
275
+ this.baseR=spread*(0.14+this.layer*0.2+Math.random()*0.07);
276
+ this.speed=(Math.random()<.5?1:-1)*(.001+Math.random()*.0028);
277
+ this.osc=3+Math.random()*9; this.t=Math.random()*100;
278
+ this.r=1.3+Math.random()*1.8; this.alpha=.5+Math.random()*.5;
279
+ this.firing=0; this.fireTimer=Math.random()*160;
280
+ this.x=cx; this.y=cy; this._step();
281
+ }
282
+ _step(){
283
+ this.t+=.016; this.angle+=this.speed;
284
+ const r=this.baseR+Math.sin(this.t)*this.osc;
285
+ this.x=cx+Math.cos(this.angle)*r; this.y=cy+Math.sin(this.angle)*r;
286
+ this.fireTimer--;
287
+ if(this.fireTimer<=0){this.firing=1;this.fireTimer=65+Math.random()*170;}
288
+ if(this.firing>0)this.firing=Math.max(0,this.firing-.032);
289
+ }
290
+ draw(){
291
+ ctx.globalAlpha=this.alpha*(.5+this.firing*.5);
292
+ ctx.strokeStyle=`rgba(0,${160+Math.round(this.firing*95)},255,${.3+this.firing*.5})`;
293
+ ctx.lineWidth=.6;
294
+ ctx.beginPath();ctx.arc(this.x,this.y,this.r+2.2,0,Math.PI*2);ctx.stroke();
295
+ ctx.fillStyle=this.firing>.3?`rgba(255,255,255,${this.firing})`:'rgba(0,200,255,.9)';
296
+ ctx.beginPath();ctx.arc(this.x,this.y,this.r,0,Math.PI*2);ctx.fill();
297
+ ctx.globalAlpha=1;
298
+ }
299
+ }
300
+ class Pulse{
301
+ constructor(a,b){this.a=a;this.b=b;this.t=0;this.s=.013+Math.random()*.016;this.done=false;}
302
+ tick(){this.t+=this.s;if(this.t>=1){this.done=true;this.b.firing=1;}}
303
+ draw(){
304
+ const x=this.a.x+(this.b.x-this.a.x)*this.t;
305
+ const y=this.a.y+(this.b.y-this.a.y)*this.t;
306
+ ctx.globalAlpha=1-this.t*.4;
307
+ ctx.fillStyle='#fff';ctx.beginPath();ctx.arc(x,y,2,0,Math.PI*2);ctx.fill();
308
+ const tx=this.a.x+(this.b.x-this.a.x)*Math.max(0,this.t-.07);
309
+ const ty=this.a.y+(this.b.y-this.a.y)*Math.max(0,this.t-.07);
310
+ const g=ctx.createLinearGradient(tx,ty,x,y);
311
+ g.addColorStop(0,'rgba(0,200,255,0)');g.addColorStop(1,'rgba(0,220,255,.55)');
312
+ ctx.strokeStyle=g;ctx.lineWidth=1.2;ctx.globalAlpha=.65;
313
+ ctx.beginPath();ctx.moveTo(tx,ty);ctx.lineTo(x,y);ctx.stroke();
314
+ ctx.globalAlpha=1;
315
+ }
316
+ }
317
+ function build(){
318
+ neurons=[];pulses=[];synapses=[];
319
+ for(let i=0;i<N;i++)neurons.push(new Neuron(i));
320
+ for(let i=0;i<neurons.length;i++){
321
+ let added=0;
322
+ for(let j=i+1;j<neurons.length;j++){
323
+ const dx=neurons[i].x-neurons[j].x,dy=neurons[i].y-neurons[j].y;
324
+ if(Math.sqrt(dx*dx+dy*dy)<CONN&&added<4){synapses.push([i,j]);added++;}
325
+ }
326
+ }
327
+ }
328
+ function drawSynapses(){
329
+ for(const s of synapses){
330
+ const a=neurons[s[0]],b=neurons[s[1]];
331
+ const dx=a.x-b.x,dy=a.y-b.y,d=Math.sqrt(dx*dx+dy*dy);
332
+ const fade=1-d/CONN,fire=(a.firing+b.firing)*.5;
333
+ ctx.globalAlpha=fade*(.06+fire*.24);
334
+ ctx.strokeStyle=`rgba(0,${150+Math.round(fire*105)},255,1)`;
335
+ ctx.lineWidth=.4+fire*.65;
336
+ ctx.beginPath();ctx.moveTo(a.x,a.y);ctx.lineTo(b.x,b.y);ctx.stroke();
337
+ }
338
+ ctx.globalAlpha=1;
339
+ }
340
+ function drawLogo(){
341
+ const g=ctx.createRadialGradient(cx,cy,0,cx,cy,50);
342
+ g.addColorStop(0,'rgba(0,200,255,.14)');g.addColorStop(1,'rgba(0,200,255,0)');
343
+ ctx.fillStyle=g;ctx.beginPath();ctx.arc(cx,cy,50,0,Math.PI*2);ctx.fill();
344
+ ctx.font="bold 19px 'Orbitron',monospace";
345
+ ctx.textAlign='center';ctx.textBaseline='middle';
346
+ ctx.shadowBlur=10;ctx.shadowColor='rgba(0,212,255,.8)';
347
+ const tg=ctx.createLinearGradient(cx-36,0,cx+36,0);
348
+ tg.addColorStop(0,'#fff');tg.addColorStop(1,'#00d4ff');
349
+ ctx.fillStyle=tg;ctx.fillText('CVision',cx,cy);ctx.shadowBlur=0;
350
+ }
351
+ function loop(){
352
+ requestAnimationFrame(loop);
353
+ ctx.clearRect(0,0,W,H);
354
+ for(const n of neurons)n._step();
355
+ drawSynapses();
356
+ for(const n of neurons)n.draw();
357
+ pulseTimer++;
358
+ if(pulseTimer%22===0&&synapses.length){
359
+ const s=synapses[Math.floor(Math.random()*synapses.length)];
360
+ const[ai,bi]=Math.random()<.5?[s[0],s[1]]:[s[1],s[0]];
361
+ pulses.push(new Pulse(neurons[ai],neurons[bi]));neurons[ai].firing=1;
362
+ }
363
+ pulses=pulses.filter(p=>!p.done);
364
+ for(const p of pulses){p.tick();p.draw();}
365
+ drawLogo();
366
+ }
367
+ window.addEventListener('resize',resize,{passive:true});
368
+ resize();loop();
369
+ }
370
+ (function clockTick(){
371
+ const el=document.getElementById('cv-clock');
372
+ if(el){const n=new Date(),p=x=>String(x).padStart(2,'0');
373
+ el.textContent=p(n.getHours())+':'+p(n.getMinutes())+':'+p(n.getSeconds());}
374
+ setTimeout(clockTick,1000);
375
  })();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  </script>
377
  """
378
 
379
+ def robust_cleaner(data):
380
+ if data is None: return ""
381
+ if isinstance(data, (list, tuple)):
382
+ if len(data) > 0:
383
+ last_entry = data[-1]
384
+ if isinstance(last_entry, (list, tuple)) and len(last_entry) == 2:
385
+ data = last_entry[1]
386
+ else:
387
+ data = str(last_entry)
388
+ else:
389
+ return ""
390
+ text = str(data)
391
+ text = text.replace("], '", "").replace("['", "").replace("']", "").replace("],", "")
392
+ text = re.sub(r"<generator object.*?>", "", text)
393
+ if "]," in text or "', '" in text:
394
+ parts = re.split(r"'],|',|\[", text)
395
+ text = parts[-1]
396
+ text = text.replace("(['", "").replace("'])", "")
397
+ text = text.replace('\\n', '\n').strip("[]()', \"")
398
+ text = re.sub(r"/tmp/\S+\.(mp3|wav|png|jpg)", "", text)
399
+ text = text.replace("boxed", "")
400
+ return text.strip()
401
+
402
+ def chat_engine_handler(history, message, mode, voice_enabled=False, pdf_file=None):
403
+ if not message or message.strip() == "":
404
+ return history, "", None
405
+ engines = {
406
+ "general": regular_chat,
407
+ "web": browser_chat,
408
+ "productividad": productivity_chat,
409
+ "cientifico": scientist_chat,
410
+ "pdf": document_chat,
411
+ }
412
+ selected_engine = engines.get(mode, regular_chat)
413
  try:
414
+ if mode == "pdf" and pdf_file:
415
+ response = selected_engine(history, message, pdf_file)
416
+ else:
417
+ response = selected_engine(history, message)
418
+ final_text = ""
419
+ if hasattr(response, "__iter__") and not isinstance(response, (list, tuple, str)):
420
+ for chunk in response:
421
+ if isinstance(chunk, list): final_text = chunk[-1][1]
422
+ else: final_text = str(chunk)
423
+ else:
424
+ final_text = response
425
+ clean_reply = robust_cleaner(final_text)
426
+ if len(clean_reply) <= 1:
427
+ clean_reply = "Disculpa, no pude procesar esa respuesta correctamente. Intenta de nuevo."
428
+ history.append((message, clean_reply))
429
+ audio_path = None
430
+ if voice_enabled:
431
+ voice_text = clean_reply.replace("*","").replace("#","").replace("`","")
432
+ audio_path = speak(voice_text[:450])
433
+ return history, "", audio_path
434
  except Exception as e:
435
+ print(f"CRITICAL ERROR EN CVISION: {e}")
436
+ history.append((message, f"Error del sistema: {str(e)}"))
437
+ return history, "", None
438
+
439
+ def transcribe_processor(audio):
440
+ if audio is None: return ""
441
+ text = transcribe_audio_file(audio)
442
+ return text if text else ""
443
+
444
+ with gr.Blocks(css=CUSTOM_CSS, title="CVision Intelligence") as assistant:
445
+
446
+ gr.HTML(HEADER_HTML) # <-- HEADER FUTURISTA
447
+ gr.HTML(NEBULA_SECTION_HTML) # <-- NEBULA + HERO
448
+ gr.HTML(STATUS_AND_JS_HTML) # <-- STATUS BAR + JS
449
+
450
+ def create_chat_interface(mode_id):
451
+ with gr.Column():
452
+ chat_window = gr.Chatbot(
453
+ height=530,
454
+ bubble_full_width=False,
455
+ elem_classes="chatbot-container",
456
+ show_label=False,
457
+ )
458
+ out_audio = gr.Audio(visible=False, autoplay=True)
459
+ with gr.Row():
460
+ input_msg = gr.Textbox(
461
+ placeholder=PLACEHOLDER,
462
+ scale=9, show_label=False, container=False,
463
+ )
464
+ btn_send = gr.Button("Enviar", variant="primary", scale=1, elem_classes="btn-primary-cv")
465
+ btn_voice = gr.Button("⚡ Voz", variant="secondary", scale=1, elem_classes="btn-secondary-cv")
466
+ with gr.Row():
467
+ mic_tool = gr.Audio(sources=["microphone"], type="filepath",
468
+ label="Transcripción de Voz", scale=5)
469
+ btn_clear = gr.Button("🗑️ Limpiar Conversación", scale=2)
470
+ mic_tool.stop_recording(transcribe_processor, [mic_tool], [input_msg])
471
+ btn_send.click(chat_engine_handler,
472
+ [chat_window, input_msg, gr.State(mode_id), gr.State(False)],
473
+ [chat_window, input_msg, out_audio])
474
+ input_msg.submit(chat_engine_handler,
475
+ [chat_window, input_msg, gr.State(mode_id), gr.State(False)],
476
+ [chat_window, input_msg, out_audio])
477
+ btn_voice.click(chat_engine_handler,
478
+ [chat_window, input_msg, gr.State(mode_id), gr.State(True)],
479
+ [chat_window, input_msg, out_audio])
480
+ btn_clear.click(lambda: ([], "", None), None, [chat_window, input_msg, out_audio])
481
+
482
+ with gr.Tab("💬 General"):
483
+ create_chat_interface("general")
484
+ with gr.Tab("🌐 Navegación Web"):
485
+ create_chat_interface("web")
486
+ with gr.Tab("📊 Productividad"):
487
+ create_chat_interface("productividad")
488
+ with gr.Tab("🔬 Análisis Científico"):
489
+ create_chat_interface("cientifico")
490
+
491
+ with gr.Tab("📄 Analista de PDF"):
492
+ chat_pdf = gr.Chatbot(height=530, bubble_full_width=False,
493
+ elem_classes="chatbot-container", show_label=False)
494
+ pdf_audio = gr.Audio(visible=False, autoplay=True)
495
+ with gr.Row():
496
+ file_input = gr.File(label="Subir Documento PDF", file_types=[".pdf"])
497
+ with gr.Row():
498
+ txt_pdf = gr.Textbox(placeholder="Pregunta algo sobre el PDF...", scale=8)
499
+ btn_send_pdf = gr.Button("Analizar", variant="primary", scale=2, elem_classes="btn-primary-cv")
500
+ btn_voice_pdf = gr.Button("Voz", variant="secondary", scale=1, elem_classes="btn-secondary-cv")
501
+ btn_send_pdf.click(chat_engine_handler,
502
+ [chat_pdf, txt_pdf, gr.State("pdf"), gr.State(False), file_input],
503
+ [chat_pdf, txt_pdf, pdf_audio])
504
+ btn_voice_pdf.click(chat_engine_handler,
505
+ [chat_pdf, txt_pdf, gr.State("pdf"), gr.State(True), file_input],
506
+ [chat_pdf, txt_pdf, pdf_audio])
507
 
508
  if __name__ == "__main__":
509
+ assistant.launch(
510
+ show_error=True,
511
+ favicon_path="assets/CVision logo.png",
512
+ )