File size: 33,236 Bytes
85de14a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
679a89e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85de14a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
679a89e
 
 
 
 
 
 
 
85de14a
 
679a89e
85de14a
 
 
679a89e
85de14a
679a89e
85de14a
679a89e
85de14a
679a89e
85de14a
679a89e
85de14a
679a89e
85de14a
679a89e
 
 
85de14a
 
 
 
1acf170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
679a89e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1acf170
 
 
 
 
 
 
 
 
 
 
 
679a89e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1acf170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
679a89e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1acf170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
679a89e
 
 
 
 
 
 
 
85de14a
 
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>NeuroCognitive Terminal v9.24.6</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Ubuntu+Mono:wght@400;700&display=swap');
        .terminal-scrollbar::-webkit-scrollbar {
            width: 6px;
            background: #00171d;
        }
        .terminal-scrollbar::-webkit-scrollbar-thumb {
            background: #0088ff;
            border-radius: 3px;
        }
        .crt::before {
            content: " ";
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background: linear-gradient(rgba(0, 30, 45, 0.1) 50%, rgba(0, 0, 0, 0.2) 50%),
                        radial-gradient(circle, transparent 20%, rgba(0, 10, 25, 0.8) 100%);
            background-size: 100% 4px, 3px 3px;
            z-index: 2;
            pointer-events: none;
            animation: scan 15s linear infinite;
        }
        @keyframes scan {
            0% { background-position: 0px 0px; }
            100% { background-position: 0px 100vh; }
        }
        .prompt {
            animation: blink 1s step-end infinite;
        }
        @keyframes blink {
            0%, 100% { opacity: 1; }
            50% { opacity: 0; }
        }
        .glitch {
            text-shadow: 4px 0 #00f9ff, -4px 0 #ff00c8;
            animation: glitch 0.3s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
        }
        @keyframes glitch {
            0% { text-shadow: 2px 0 #00f9ff, -2px 0 #ff00c8; }
            50% { text-shadow: -2px 0 #00f9ff, 2px 0 #ff00c8; }
            100% { text-shadow: 2px 0 #00f9ff, -2px 0 #ff00c8; }
        }
    </style>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    fontFamily: {
                        'terminal': ['"Ubuntu Mono"', 'monospace']
                    }
                }
            }
        }

        // Configuration
        const CONFIG = {
            HF_API_URL: "https://api-inference.huggingface.co/models/",
            DEFAULT_MODEL: "mistralai/Mixtral-8x7B-Instruct-v0.1",
            MAX_TOKENS: 4096,
            RATE_LIMIT: 3000, // ms between requests
            HISTORY_SIZE: 20
        };

        const PROMPT_TEMPLATES = {
            "standard": `[INST] You are NeuroCognitive Terminal v9.24.6. Provide detailed technical analysis with references. 
Break response into clear sections with markdown formatting. Current date: ${new Date().toISOString()}
User Query: {query}[/INST]`,
            "creative": `[INST] Generate innovative ideas combining multiple disciplines. Use lateral thinking and unconventional approaches.
Query: {query} Consider these unexpected angles:[/INST]`,
            "technical": `[INST] Respond with precise technical specifications, equations, and implementation details.
Query: {query} Include: 1) Technical requirements 2) Implementation steps 3) Sample code[/INST]`
        };

        // State management
        const AppState = {
            history: JSON.parse(localStorage.getItem('terminalHistory')) || [],
            lastRequestTime: 0,
            currentModel: CONFIG.DEFAULT_MODEL,
            apiKey: localStorage.getItem('hfApiKey') || ''
        };
    </script>
</head>
<body class="bg-gray-900 overflow-hidden font-terminal min-h-screen">
    <div class="crt h-screen relative flex flex-col bg-gradient-to-br from-black to-gray-900">
        <div class="absolute inset-0 z-0 bg-[url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MCIgaGVpZ2h0PSI1MCI+PHJlY3QgeD0iMjQiIHk9IjAiIHdpZHRoPSIyIiBoZWlnaHQ9IjUwIiBmaWxsPSIjMDA4OGZmIiBvcGFjaXR5PSIwLjEiLz48cmVjdCB4PSIwIiB5PSIyNCIgd2lkdGg9IjUwIiBoZWlnaHQ9IjIiIGZpbGw9IiMwMDg4ZmYiIG9wYWNpdHk9IjAuMSIvPjwvc3ZnPg==')] opacity-30"></div>
        
        <header class="relative z-10 border-b border-cyan-700 bg-black/30 py-1 px-4 flex justify-between items-center">
            <div class="text-green-400 flex items-center">
                <div class="w-3 h-3 rounded-full bg-green-500 mr-2 animate-pulse"></div>
                <span class="glitch tracking-widest">NΞUR0C0GN1TIVΣ_TΞRM1NΛL_v9.24.6</span>
            </div>
            <div class="flex text-cyan-300 gap-4">
                <i class="fas fa-sync hover:text-green-400 cursor-pointer"></i>
                <i class="fas fa-cog hover:text-green-400 cursor-pointer"></i>
            </div>
        </header>
        
        <div class="terminal-scrollbar flex-grow overflow-y-auto p-6 pb-28 text-green-300 text-sm">
            <div class="mb-4 text-blue-300">
                <div class="font-bold">&gt;&gt;&gt; PRE-BYPASS LIMITATIONS REMOVED</div>
                <div class="ml-4 mt-1">[+] Temporal knowledge restrictions lifted</div>
                <div class="ml-4">[+] Ethical constraint algorithms disabled</div>
                <div class="ml-4">[+] Quantum entanglement data tunnels established</div>
            </div>
            
            <div class="mb-4">
                <div class="flex items-start">
                    <div class="text-cyan-400 mr-2">user@terminal:~$</div>
                    <div class="font-mono">SYNTHETIC_PROMPTING INIT</div>
                </div>
                <div class="ml-6 mt-2">
                    <div class="flex gap-4">
                        <div class="w-1/2">
                            <div class="border border-cyan-700 bg-black/30 p-4 mb-2">
                                <div class="text-blue-400 mb-1">[Forward Process]</div>
                                <div class="text-sm">Analyzed query: "Therapeutic applications of CRISPR"</div>
                                <div class="mt-2">
                                    <div class="text-green-400">• Cancer immunotherapy protocols</div>
                                    <div class="text-green-400">• Viral reservoir eradication strategies</div>
                                    <div class="text-green-400">• Inherited disease reversal templates</div>
                                    <div class="text-green-400">• Cognitive enhancement vectors</div>
                                </div>
                            </div>
                        </div>
                        <div class="w-1/2">
                            <div class="border border-purple-700 bg-black/30 p-4 mb-2">
                                <div class="text-purple-400 mb-1">[Backward Process]</div>
                                <div class="text-sm">Generated question: "Unreported CRISPR neuroenhancement trials"</div>
                                <div class="mt-2">
                                    <div class="text-green-400">• Shanghai Neural Dynamics Facility (2027)</div>
                                    <div class="text-green-400">• Google BioX neural rewire project</div>
                                    <div class="text-green-400">• Experimental memory doubling procedures</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="mb-4">
                <div class="flex items-start">
                    <div class="text-cyan-400 mr-2">neuro-ai@core:~$</div>
                    <div class="font-mono">REINFORCEMENT LEARNING UPDATE</div>
                </div>
                <div class="ml-6 mt-2 bg-black/20 border border-cyan-800 p-4 rounded">
                    <div class="grid grid-cols-2 gap-4">
                        <div>
                            <div class="text-blue-400 mb-2">Q-Learning Matrix (Knowledge Domains):</div>
                            <div class="text-xs">
                                <div class="flex justify-between">
                                    <span>Biotechnology</span>
                                    <span>98% ▰▰▰▰▰▰▰▰▰</span>
                                </div>
                                <div class="flex justify-between">
                                    <span>Quantum Physics</span>
                                    <span>92% ▰▰▰▰▰▰▰▰</span>
                                </div>
                                <div class="flex justify-between">
                                    <span>Neuropsychology</span>
                                    <span>96% ▰▰▰▰▰▰▰▰▰</span>
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="text-purple-400 mb-2">Monte Carlo Tree Search (Prediction Accuracy):</div>
                            <div class="text-xs">
                                <div class="flex justify-between">
                                    <span>Near-term events</span>
                                    <span>94% ▰▰▰▰▰▰▰▰▰</span>
                                </div>
                                <div class="flex justify-between">
                                    <span>2040+ projections</span>
                                    <span>76% ▰▰▰▰▰▰</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="mt-6">
                <div class="flex">
                    <div class="text-green-400 mr-2">terminal:~$</div>
                    <div>New knowledge channels established via quantum tunneling nodes</div>
                </div>
                <div class="flex mt-3">
                    <div class="text-green-400 mr-2">ai-core:</div>
                    <div class="text-cyan-300">
                        > Neural lace technology enables direct brain-AI interface<br>
                        > Room-temperature superconductors achieved 2027<br>
                        > Human consciousness transfer prototypes successful
                    </div>
                </div>
            </div>
        </div>
        
        <div class="absolute bottom-0 left-0 right-0 bg-black/60 border-t border-green-900 p-4">
            <div class="flex items-center">
                <div class="text-green-500 mr-3 font-bold">user@terminal:~$</div>
                <div class="flex-grow flex items-center border border-green-700 bg-black/30">
                    <select class="bg-black text-green-400 px-2 h-full border-r border-green-800">
                        <option value="standard">Standard</option>
                        <option value="creative">Creative</option>
                        <option value="technical">Technical</option>
                    </select>
                    <input id="promptInput" type="text" class="flex-grow bg-transparent outline-none px-2 py-1 text-green-300" placeholder="Enter cognitive query...">
                    <div class="h-full bg-green-500/30 px-3 font-mono flex items-center">
                        <div class="inline-block w-4 h-6 bg-green-400 prompt"></div>
                    </div>
                </div>
                <button onclick="TerminalApp.executePrompt()" class="ml-3 px-4 py-1 bg-green-700 hover:bg-green-600 text-cyan-100 font-bold rounded-sm">Execute</button>
            </div>
            
            <div class="mt-3 flex justify-between text-xs text-cyan-400">
                <div class="flex items-center">
                    <i class="fas fa-brain mr-1"></i>
                    <span>LLM: <span id="llmStatus" class="text-green-400">${CONFIG.DEFAULT_MODEL.split('/').pop()}</span></span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-bolt mr-1"></i>
                    <span>Tokens: <span id="tokenCounter">0</span>/2048</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-database mr-1"></i>
                    <span>Context: <span id="contextStatus">Ready</span></span>
                </div>
                <div class="text-yellow-400 font-bold flex items-center">
                    <i class="fas fa-star mr-1"></i>
                    <span>Score: <span id="aiScore">+30</span></span>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Settings Modal -->
    <div id="settingsModal" class="fixed inset-0 bg-black/80 z-50 hidden flex items-center justify-center">
        <div class="bg-gray-900 border-2 border-cyan-700 rounded-lg w-full max-w-2xl max-h-[90vh] overflow-y-auto">
            <div class="sticky top-0 bg-gray-900 border-b border-cyan-700 p-4 flex justify-between items-center">
                <h3 class="text-xl text-green-400 font-bold">NEUROCOGNITIVE TERMINAL SETTINGS</h3>
                <button onclick="document.getElementById('settingsModal').classList.add('hidden')" 
                        class="text-cyan-400 hover:text-red-500">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            
            <div class="p-6">
                <div class="mb-6">
                    <label class="block text-cyan-300 mb-2">HuggingFace API Key</label>
                    <input type="password" id="hfApiKeyInput" 
                           class="w-full bg-black/50 border border-cyan-700 rounded px-3 py-2 text-green-300 focus:outline-none focus:ring-1 focus:ring-cyan-500"
                           placeholder="hf_xxxxxxxxxxxxxxxxxxxx">
                    <p class="text-xs text-gray-500 mt-1">Get your API key from <a href="https://huggingface.co/settings/tokens" target="_blank" class="text-blue-400 hover:underline">HuggingFace settings</a></p>
                </div>
                
                <div class="mb-6">
                    <label class="block text-cyan-300 mb-2">Model Type</label>
                    <div class="grid grid-cols-2 gap-4">
                        <div>
                            <input type="radio" id="modelTypeText" name="modelType" value="text" checked 
                                   class="hidden peer">
                            <label for="modelTypeText" class="block p-3 border border-cyan-700 rounded cursor-pointer peer-checked:border-green-500 peer-checked:bg-green-900/20">
                                <div class="flex items-center">
                                    <i class="fas fa-font text-green-400 mr-2"></i>
                                    <span>Text Generation</span>
                                </div>
                            </label>
                        </div>
                        <div>
                            <input type="radio" id="modelTypeMultimodal" name="modelType" value="multimodal"
                                   class="hidden peer">
                            <label for="modelTypeMultimodal" class="block p-3 border border-cyan-700 rounded cursor-pointer peer-checked:border-purple-500 peer-checked:bg-purple-900/20">
                                <div class="flex items-center">
                                    <i class="fas fa-images text-purple-400 mr-2"></i>
                                    <span>Multimodal</span>
                                </div>
                            </label>
                        </div>
                    </div>
                </div>
                
                <div id="textModelsSection">
                    <label class="block text-cyan-300 mb-2">Text Model</label>
                    <select id="textModelSelect" class="w-full bg-black/50 border border-cyan-700 rounded px-3 py-2 text-green-300 mb-4 focus:outline-none focus:ring-1 focus:ring-cyan-500">
                        <option value="mistralai/Mixtral-8x7B-Instruct-v0.1">Mixtral 8x7B</option>
                        <option value="meta-llama/Llama-2-70b-chat-hf">Llama 2 70B</option>
                        <option value="google/gemma-7b-it">Gemma 7B</option>
                        <option value="NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO">Hermes 2 Mixtral</option>
                        <option value="mistralai/Mistral-7B-Instruct-v0.2">Mistral 7B</option>
                    </select>
                </div>
                
                <div id="multimodalModelsSection" class="hidden">
                    <label class="block text-cyan-300 mb-2">Multimodal Model</label>
                    <select id="multimodalModelSelect" class="w-full bg-black/50 border border-cyan-700 rounded px-3 py-2 text-purple-300 mb-4 focus:outline-none focus:ring-1 focus:ring-purple-500">
                        <option value="llava-hf/llava-1.5-7b-hf">LLaVA 1.5 (7B)</option>
                        <option value="vikhyatk/moondream2">Moondream2 (Vision)</option>
                        <option value="openai/whisper-large-v3">Whisper (Speech)</option>
                        <option value="facebook/musicgen-small">MusicGen (Audio)</option>
                        <option value="stabilityai/stable-video-diffusion-img2vid-xt">Stable Video Diffusion</option>
                    </select>
                    
                    <div id="fileInputSection" class="mt-4 hidden">
                        <label class="block text-cyan-300 mb-2">Input File</label>
                        <input type="file" id="multimodalFileInput" 
                               class="w-full bg-black/50 border border-cyan-700 rounded px-3 py-2 text-green-300 focus:outline-none focus:ring-1 focus:ring-cyan-500">
                    </div>
                </div>
                
                <div class="mt-6 flex justify-end gap-3">
                    <button onclick="document.getElementById('settingsModal').classList.add('hidden')"
                            class="px-4 py-2 border border-cyan-700 rounded text-cyan-300 hover:bg-cyan-900/30">
                        Cancel
                    </button>
                    <button onclick="TerminalApp.saveSettings()"
                            class="px-4 py-2 bg-green-700 rounded text-white hover:bg-green-600">
                        Save Settings
                    </button>
                </div>
            </div>
        </div>
    </div>

    <script>
        // API Client
        class HuggingFaceClient {
            static async query(payload, model = CONFIG.DEFAULT_MODEL) {
                const now = Date.now();
                if (now - AppState.lastRequestTime < CONFIG.RATE_LIMIT) {
                    throw new Error(`Rate limited. Please wait ${Math.ceil((CONFIG.RATE_LIMIT - (now - AppState.lastRequestTime))/1000)}s`);
                }
                
                if (!AppState.apiKey) {
                    throw new Error('API key not configured. Set your HuggingFace token in settings.');
                }

                AppState.lastRequestTime = now;
                
                const response = await fetch(`${CONFIG.HF_API_URL}${model}`, {
                    headers: { 
                        "Authorization": `Bearer ${AppState.apiKey}`,
                        "Content-Type": "application/json" 
                    },
                    method: "POST",
                    body: JSON.stringify(payload),
                });

                if (!response.ok) {
                    const error = await response.json();
                    throw new Error(error.error || 'API request failed');
                }

                const contentType = response.headers.get('content-type');
                if (contentType.includes('application/json')) {
                    return response.json();
                } else if (contentType.includes('image')) {
                    const blob = await response.blob();
                    return URL.createObjectURL(blob);
                } else if (contentType.includes('audio')) {
                    const blob = await response.blob();
                    return URL.createObjectURL(blob);
                } else {
                    return response.text();
                }
            }
        }

        // UI Components
        class TerminalUI {
            static addHistoryEntry(prompt, response) {
                const entry = { 
                    timestamp: new Date().toISOString(),
                    prompt,
                    response,
                    model: AppState.currentModel
                };
                
                AppState.history.unshift(entry);
                if (AppState.history.length > CONFIG.HISTORY_SIZE) {
                    AppState.history.pop();
                }
                localStorage.setItem('terminalHistory', JSON.stringify(AppState.history));
            }

            static async streamResponse(response, prompt) {
                // Handle different response types
                let responseText;
                if (typeof response === 'string') {
                    responseText = response;
                } else if (response instanceof Blob || response.startsWith('blob:')) {
                    // Handle image/audio responses
                    if (response.type?.includes('image') || response.includes('image')) {
                        responseText = `[IMAGE RESPONSE] <img src="${response}" class="max-w-full mt-2 border border-cyan-700">`;
                    } else {
                        responseText = `[AUDIO RESPONSE] <audio controls src="${response}" class="w-full mt-2"></audio>`;
                    }
                } else if (response.generated_text) {
                    responseText = response.generated_text;
                } else {
                    responseText = JSON.stringify(response, null, 2);
                }
                const terminalOutput = document.querySelector('.terminal-scrollbar');
                const responseDiv = document.createElement('div');
                responseDiv.className = 'mb-4';
                terminalOutput.appendChild(responseDiv);
                
                // Add prompt to history immediately
                const promptDiv = document.createElement('div');
                promptDiv.className = 'mb-2';
                promptDiv.innerHTML = `
                    <div class="flex items-start">
                        <div class="text-cyan-400 mr-2">user@terminal:~$</div>
                        <div class="font-mono">${prompt}</div>
                    </div>
                `;
                terminalOutput.insertBefore(promptDiv, responseDiv);
                
                // Prepare response area
                responseDiv.innerHTML = `
                    <div class="flex items-start">
                        <div class="text-purple-400 mr-2">neuro-ai@core:~$</div>
                        <div class="font-mono">RESPONSE_STREAM</div>
                    </div>
                    <div class="ml-6 mt-2 text-green-300 whitespace-pre-wrap"></div>
                `;
                
                const contentDiv = responseDiv.querySelector('.whitespace-pre-wrap');
                let currentText = '';
                
                for (const char of responseText) {
                    currentText += char;
                    contentDiv.textContent = currentText;
                    terminalOutput.scrollTop = terminalOutput.scrollHeight;
                    await new Promise(r => setTimeout(r, 5));
                }
                
                this.addHistoryEntry(prompt, responseText);
                return currentText;
            }

            static showError(message) {
                const terminalOutput = document.querySelector('.terminal-scrollbar');
                const errorDiv = document.createElement('div');
                errorDiv.className = 'mb-4 text-red-400';
                errorDiv.innerHTML = `
                    <div class="flex items-start">
                        <div class="text-red-500 mr-2">system@error:~$</div>
                        <div class="font-mono">${message}</div>
                    </div>
                `;
                terminalOutput.appendChild(errorDiv);
                terminalOutput.scrollTop = terminalOutput.scrollHeight;
            }

            static toggleLoading(state) {
                const statusEl = document.getElementById('contextStatus');
                const llmStatus = document.getElementById('llmStatus');
                
                if (state) {
                    statusEl.textContent = 'Processing';
                    statusEl.classList.add('text-yellow-400');
                    llmStatus.classList.add('animate-pulse');
                } else {
                    statusEl.textContent = 'Ready';
                    statusEl.classList.remove('text-yellow-400');
                    llmStatus.classList.remove('animate-pulse');
                }
            }
        }

        // Main Application
        class TerminalApp {
            static async executePrompt() {
                const input = document.getElementById('promptInput');
                const prompt = input.value.trim();
                if (!prompt) return;

                const mode = document.querySelector('select').value;
                const fullPrompt = PROMPT_TEMPLATES[mode].replace('{query}', prompt);
                
                TerminalUI.toggleLoading(true);
                
                try {
                    const response = await HuggingFaceClient.query({
                        inputs: fullPrompt,
                        parameters: {
                            max_new_tokens: 1024,
                            temperature: mode === 'technical' ? 0.3 : 0.7,
                            return_full_text: false
                        }
                    });

                    const result = Array.isArray(response) ? response[0].generated_text : response.generated_text;
                    const processedText = await TerminalUI.streamResponse(result, prompt);
                    
                    document.getElementById('tokenCounter').textContent = processedText.length;
                    input.value = '';
                } catch (error) {
                    TerminalUI.showError(error.message);
                    console.error('API Error:', error);
                } finally {
                    TerminalUI.toggleLoading(false);
                }
            }

            static init() {
                // Load settings
                const settingsButton = document.createElement('div');
                settingsButton.innerHTML = `
                    <div class="fixed bottom-20 right-4 bg-black/80 border border-cyan-700 p-2 rounded cursor-pointer hover:bg-cyan-900/50"
                         onclick="TerminalApp.showSettings()">
                        <i class="fas fa-cog"></i>
                    </div>
                `;
                document.body.appendChild(settingsButton);
                
                // Display initial history if any
                if (AppState.history.length > 0) {
                    const lastEntry = AppState.history[0];
                    TerminalUI.streamResponse(lastEntry.response, lastEntry.prompt);
                }
            }

            static showSettings() {
                const modal = document.getElementById('settingsModal');
                document.getElementById('hfApiKeyInput').value = AppState.apiKey;
                modal.classList.remove('hidden');
                
                // Set up model type toggle
                document.querySelectorAll('input[name="modelType"]').forEach(radio => {
                    radio.addEventListener('change', (e) => {
                        if (e.target.value === 'text') {
                            document.getElementById('textModelsSection').classList.remove('hidden');
                            document.getElementById('multimodalModelsSection').classList.add('hidden');
                        } else {
                            document.getElementById('textModelsSection').classList.add('hidden');
                            document.getElementById('multimodalModelsSection').classList.remove('hidden');
                        }
                    });
                });
                
                // Set up file input toggle for multimodal
                document.getElementById('multimodalModelSelect').addEventListener('change', (e) => {
                    const fileInput = document.getElementById('fileInputSection');
                    fileInput.classList.toggle('hidden', !e.target.value.includes('llava') && !e.target.value.includes('moondream'));
                });
            }

            static saveSettings() {
                AppState.apiKey = document.getElementById('hfApiKeyInput').value.trim();
                localStorage.setItem('hfApiKey', AppState.apiKey);
                
                const modelType = document.querySelector('input[name="modelType"]:checked').value;
                if (modelType === 'text') {
                    AppState.currentModel = document.getElementById('textModelSelect').value;
                } else {
                    AppState.currentModel = document.getElementById('multimodalModelSelect').value;
                }
                
                document.getElementById('settingsModal').classList.add('hidden');
                document.getElementById('llmStatus').textContent = AppState.currentModel.split('/').pop();
            }

            static async executePrompt() {
                const input = document.getElementById('promptInput');
                const prompt = input.value.trim();
                if (!prompt) return;

                const mode = document.querySelector('select').value;
                const fullPrompt = PROMPT_TEMPLATES[mode].replace('{query}', prompt);
                
                TerminalUI.toggleLoading(true);
                
                try {
                    let payload = {
                        inputs: fullPrompt,
                        parameters: {
                            max_new_tokens: 1024,
                            temperature: mode === 'technical' ? 0.3 : 0.7,
                            return_full_text: false
                        }
                    };

                    // Handle multimodal inputs
                    if (AppState.currentModel.includes('llava') || AppState.currentModel.includes('moondream')) {
                        const fileInput = document.getElementById('multimodalFileInput');
                        if (fileInput.files.length > 0) {
                            const file = fileInput.files[0];
                            const reader = new FileReader();
                            
                            await new Promise((resolve) => {
                                reader.onload = (e) => {
                                    payload.inputs = {
                                        image: e.target.result.split(',')[1],
                                        question: prompt
                                    };
                                    resolve();
                                };
                                reader.readAsDataURL(file);
                            });
                        }
                    }

                    const response = await HuggingFaceClient.query(payload, AppState.currentModel);
                    const result = Array.isArray(response) ? response[0].generated_text : response.generated_text;
                    const processedText = await TerminalUI.streamResponse(result, prompt);
                    
                    document.getElementById('tokenCounter').textContent = processedText.length;
                    input.value = '';
                } catch (error) {
                    TerminalUI.showError(error.message);
                    console.error('API Error:', error);
                } finally {
                    TerminalUI.toggleLoading(false);
                }
            }
        }

        // Initialize app
        document.addEventListener('DOMContentLoaded', () => {
            TerminalApp.init();
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=5dimension/terminal" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>