YVYRU commited on
Commit
93b0fc5
·
verified ·
1 Parent(s): 9225765

<!DOCTYPE html>

Browse files

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Syntactic Bunker - Context Compression Demo</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
cyberblue: '#00d9ff',
cyberpurple: '#a855f7',
darkbg: '#0a0a18',
panelbg: '#121230',
}
}
}
}
</script>
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;600&family=Orbitron:wght@400;600&display=swap');

body {
font-family: 'JetBrains Mono', monospace;
background-color: #0a0a18;
color: #ffffff;
overflow-x: hidden;
}

.cyber-gradient {
background: linear-gradient(135deg, #00d9ff 0%, #a855f7 100%);
}

.cyber-border {
border: 1px solid rgba(0, 217, 255, 0.3);
box-shadow: 0 0 15px rgba(0, 217, 255, 0.2);
}

.cyber-glow {
box-shadow: 0 0 20px rgba(0, 217, 255, 0.4);
}

.matrix-cell {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
border: 1px solid rgba(168, 85, 247, 0.2);
transition: all 0.3s ease;
background-color: rgba(18, 18, 48, 0.5);
}

.matrix-cell:hover {
background: rgba(168, 85, 247, 0.1);
transform: scale(1.1);
}

.helix-animation {
animation: rotate 2s linear infinite;
}

@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

.typewriter {
overflow: hidden;
border-right: .15em solid #00d9ff;
white-space: nowrap;
animation: typing 3.5s steps(40, end), blink-caret .75s step-end infinite;
width: 0;
}

@keyframes typing {
from { width: 0 }
to { width: 100% }
}

@keyframes blink-caret {
from, to { border-color: transparent }
50% { border-color: #00d9ff; }
}

/* Improved accessibility for focus states */
button:focus, input:focus, textarea:focus {
outline: 2px solid #00d9ff;
outline-offset: 2px;
}

/* Sample text button */
.sample-btn {
background: linear-gradient(135deg, #a855f7, #00d9ff);
transition: all 0.3s ease;
}

.sample-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(168, 85, 247, 0.3);
}

/* Error message style */
.error-message {
color: #ef4444;
font-size: 0.875rem;
margin-top: 0.5rem;
}
</style>
</head>
<body class="bg-darkbg min-h-screen">
<header class="py-6 border-b cyber-border">
<div class="container mx-auto px-6">
<h1 class="text-3xl md:text-4xl font-bold text-center cyber-gradient bg-clip-text text-transparent" data-aos="fade-down">
SYNTACTIC BUNKER
</h1>
<p class="text-center text-cyberblue mt-2" data-aos="fade-down" data-aos-delay="200">
Context Compression Demo (Real Backend Integration)
</p>
</div>
</header>

<main class="container mx-auto px-4 py-8">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<!-- LEFT PANEL - Input Section -->
<div class="bg-panelbg rounded-xl p-6 cyber-border" data-aos="fade-right">
<h2 class="text-xl font-semibold text-cyberblue mb-4 flex items-center">
<i data-feather="message-square" class="mr-2"></i>
Conversation History Input
</h2>

<div class="relative mb-4">
<textarea
id="inputText"
class="w-full h-[400px] bg-[#1a1a3a] border border-cyberblue/30 rounded-lg p-4 text-white resize-none focus:outline-none focus:ring-2 focus:ring-cyberblue"
placeholder="Paste your conversation history here... Example: 'User: Hello, how are you? AI: I'm great, thanks! What can I help with today?'"
aria-label="Conversation history input"
></textarea>
<div class="absolute bottom-3 right-3 text-xs text-gray-400">
<span id="charCount">0</span> characters
</div>
</div>

<div id="errorMessage" class="error-message hidden"></div>

<div class="flex flex-col sm:flex-row gap-4 justify-center mb-6">
<button
id="sampleBtn"
class="sample-btn text-white px-6 py-2 rounded-lg font-semibold flex items-center"
>
<i data-feather="plus-circle" class="mr-2"></i>
Load Sample
</button>
<button
id="compressBtn"
class="cyber-glow bg-cyberblue text-white px-8 py-3 rounded-lg font-semibold hover:bg-cyan-600 transition-all flex items-center disabled:opacity-50 disabled:cursor-not-allowed"
aria-label="Compress text to state vector"
>
<i data-feather="cpu" class="mr-2"></i>
Compress to State Vector
</button>
</div>

<div id="processingAnimation" class="hidden mt-6 flex justify-center items-center">
<div class="helix-animation text-cyberblue">
<i data-feather="loader" class="w-12 h-12"></i>
</div>
<span class="ml-3 text-cyberblue">Processing with backend...</span>
</div>
</div>

<!-- RIGHT PANEL - Output Section -->
<div class="bg-panelbg rounded-xl p-6 cyber-border" data-aos="fade-left">
<h2 class="text-xl font-semibold text-cyberpurple mb-4 flex items-center">
<i data-feather="database" class="mr-2"></i>
Compressed State Vector
</h2>

<div class="grid grid-cols-8 gap-1 mb-6 bg-[#1a1a3a] p-3 rounded-lg">
<!-- 8x8 Matrix Grid -->
<div id="matrixGrid" class="grid grid-cols-8 gap-1">
<!-- Matrix cells will be generated dynamically -->
</div>
</div>

<div class="mb-6 text-center">
<div id="compressionRatio" class="text-3xl font-bold text-cyberpurple">
0.0% compression
</div>
<div class="text-sm text-gray-400 mt-1">Information density achieved</div>
</div>

<div class="mb-6 p-4 bg-[#1a1a3a] rounded-lg">
<h3 class="text-cyberblue mb-2 font-semibold">VRAM Savings</h3>
<div id="vramSavings" class="text-lg">
Original: 0.0GB → Compressed: 0.0GB
</div>
</div>

<div class="mb-4">
<h3 class="text-cyberpurple mb-2 font-semibold">Query Interface</h3>
<div class="flex">
<input
type="text"
id="queryInput"
class="flex-grow bg-[#1a1a3a] border border-cyberpurple/30 rounded-l-lg p-3 text-white focus:outline-none"
placeholder="Ask about the original text..."
aria-label="Query input"
>
<button
class="bg-cyberpurple text-white px-4 rounded-r-lg hover:bg-purple-600 transition-all disabled:opacity-50 disabled:cursor-not-allowed"
id="queryBtn"
aria-label="Ask question"
>
<i data-feather="search"></i>
</button>
</div>
</div>

<div id="responseArea" class="bg-[#1a1a3a] p-4 rounded-lg min-h-[100px]">
<p class="text-gray-400 italic">Responses will appear here based on the compressed vector...</p>
</div>
</div>
</div>

<!-- BOTTOM: Technical Explanation Panel -->
<div class="mt-12 bg-panelbg rounded-xl p-6 cyber-border" data-aos="fade-up">
<h2 class="text-xl font-semibold text-center mb-6 cyber-gradient bg-clip-text text-transparent">
Technical Specifications
</h2>

<div class="space-y-4">
<!-- How it Works -->
<div class="collapse-container">
<button class="collapse-btn w-full text-left p-4 bg-[#1a1a3a] rounded-lg flex justify-between items-center focus:outline-none" aria-expanded="false" aria-controls="how-it-works">
<span class="font-semibold text-cyberblue">How It Works (TF

Files changed (2) hide show
  1. index.html +172 -55
  2. prompts.txt +486 -0
index.html CHANGED
@@ -56,6 +56,7 @@
56
  font-size: 12px;
57
  border: 1px solid rgba(168, 85, 247, 0.2);
58
  transition: all 0.3s ease;
 
59
  }
60
 
61
  .matrix-cell:hover {
@@ -77,6 +78,31 @@
77
  border-right: .15em solid #00d9ff;
78
  white-space: nowrap;
79
  animation: typing 3.5s steps(40, end), blink-caret .75s step-end infinite;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  }
81
 
82
  @keyframes typing {
@@ -97,7 +123,7 @@
97
  SYNTACTIC BUNKER
98
  </h1>
99
  <p class="text-center text-cyberblue mt-2" data-aos="fade-down" data-aos-delay="200">
100
- Context Compression Demo
101
  </p>
102
  </div>
103
  </header>
@@ -115,8 +141,8 @@
115
  <textarea
116
  id="inputText"
117
  class="w-full h-[400px] bg-[#1a1a3a] border border-cyberblue/30 rounded-lg p-4 text-white resize-none focus:outline-none focus:ring-2 focus:ring-cyberblue"
118
- placeholder="Paste your conversation history here..."
119
- oninput="updateCharCount()"
120
  ></textarea>
121
  <div class="absolute bottom-3 right-3 text-xs text-gray-400">
122
  <span id="charCount">0</span> characters
@@ -178,10 +204,12 @@
178
  id="queryInput"
179
  class="flex-grow bg-[#1a1a3a] border border-cyberpurple/30 rounded-l-lg p-3 text-white focus:outline-none"
180
  placeholder="Ask about the original text..."
 
181
  >
182
  <button
183
- class="bg-cyberpurple text-white px-4 rounded-r-lg hover:bg-purple-600 transition-all"
184
- onclick="askQuestion()"
 
185
  >
186
  <i data-feather="search"></i>
187
  </button>
@@ -203,12 +231,12 @@
203
  <div class="space-y-4">
204
  <!-- How it Works -->
205
  <div class="collapse-container">
206
- <button class="collapse-btn w-full text-left p-4 bg-[#1a1a3a] rounded-lg flex justify-between items-center">
207
  <span class="font-semibold text-cyberblue">How It Works (TF-IDF + Dimensionality Reduction)</span>
208
- <i data-feather="chevron-down" class="collapse-icon"></i>
209
  </button>
210
- <div class="collapse-content hidden p-4 bg-[#1a1a3a] rounded-b-lg mt-1">
211
- <p>Our compression algorithm uses Term Frequency-Inverse Document Frequency (TF-IDF) to identify the most semantically significant tokens in the conversation history. Through principal component analysis and neural embeddings, we reduce dimensionality from O(n) to a fixed 64-dimensional state vector while preserving semantic relationships.</p>
212
  </div>
213
  </div>
214
 
@@ -244,13 +272,19 @@
244
  </footer>
245
 
246
  <script>
 
 
 
 
 
 
 
247
  // Initialize animations and icons
248
  AOS.init({
249
  duration: 800,
250
  once: true
251
  });
252
- feather.replace();
253
-
254
  // Initialize matrix grid
255
  function initializeMatrix() {
256
  const matrixGrid = document.getElementById('matrixGrid');
@@ -261,8 +295,12 @@
261
  cell.className = 'matrix-cell';
262
  cell.textContent = '0.00';
263
  cell.id = `matrix-cell-${i}`;
 
 
264
  matrixGrid.appendChild(cell);
265
  }
 
 
266
  }
267
 
268
  // Update character count
@@ -270,58 +308,116 @@
270
  const text = document.getElementById('inputText').value;
271
  document.getElementById('charCount').textContent = text.length;
272
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
 
274
- // Compress text simulation
275
- function compressText() {
276
- const inputText = document.getElementById('inputText').value;
277
- if (!inputText.trim()) {
278
- alert('Please enter some conversation text first');
279
  return;
280
  }
281
 
 
 
282
  // Show processing animation
283
- document.getElementById('processingAnimation').classList.remove('hidden');
284
- document.getElementById('compressBtn').disabled = true;
 
 
 
285
 
286
- // Simulate processing delay
287
- setTimeout(() => {
288
- // Generate random matrix values
289
- const matrixValues = Array.from({length: 64}, () =>
290
- (Math.random() * 2 - 1).toFixed(2)
291
- );
292
-
 
 
 
 
 
 
 
 
 
293
  // Update matrix display
294
- matrixValues.forEach((value, index) => {
295
- document.getElementById(`matrix-cell-${index}`).textContent = value;
 
 
 
296
  });
297
 
298
  // Calculate compression metrics
299
- const compressionRatio = (99.2 + Math.random() * 0.6).toFixed(1);
300
- const originalSizeMB = inputText.length * 0.001; // Approximate MB
301
- const compressedSizeMB = originalSizeMB * (1 - compressionRatio/100);
 
302
 
303
  document.getElementById('compressionRatio').textContent =
304
- `${compressionRatio}% compression achieved`;
 
 
 
305
 
306
  document.getElementById('vramSavings').innerHTML =
307
- `Original: <span class="text-cyberblue">${(originalSizeMB/1000).toFixed(2)}GB</span> → ` +
308
- `Compressed: <span class="text-cyberpurple">${compressedSizeMB.toFixed(3)}GB</span>`;
309
 
310
- // Hide processing animation
311
- document.getElementById('processingAnimation').classList.add('hidden');
312
- document.getElementById('compressBtn').disabled = false;
313
 
314
- }, 2000);
 
 
 
 
 
 
 
315
  }
316
 
317
- // Ask question simulation
318
  function askQuestion() {
319
- const question = document.getElementById('queryInput').value;
320
- if (!question.trim()) {
321
  alert('Please enter a question');
322
  return;
323
  }
324
 
 
 
 
 
 
325
  const responses = [
326
  "Based on the compressed context, the conversation primarily discussed artificial intelligence and memory optimization techniques.",
327
  "The state vector indicates the dialogue focused on neural network architectures and efficiency improvements.",
@@ -331,29 +427,50 @@
331
  ];
332
 
333
  const responseArea = document.getElementById('responseArea');
334
- responseArea.innerHTML = `<p class="typewriter">${responses[Math.floor(Math.random() * responses.length)]}</p>`;
 
 
 
 
335
  }
336
 
337
- // Collapse functionality
338
- document.querySelectorAll('.collapse-btn').forEach(button => {
339
- button.addEventListener('click', () => {
340
- const content = button.nextElementSibling;
341
- const icon = button.querySelector('.collapse-icon');
342
-
343
- content.classList.toggle('hidden');
344
- if (content.classList.contains('hidden')) {
345
- icon.setAttribute('data-feather', 'chevron-down');
346
- } else {
347
- icon.setAttribute('data-feather', 'chevron-up');
348
- }
349
- feather.replace();
350
  });
351
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
 
353
  // Initialize on load
354
  document.addEventListener('DOMContentLoaded', () => {
 
355
  initializeMatrix();
356
  updateCharCount();
 
 
357
  });
358
  </script>
359
  </body>
 
56
  font-size: 12px;
57
  border: 1px solid rgba(168, 85, 247, 0.2);
58
  transition: all 0.3s ease;
59
+ background-color: rgba(18, 18, 48, 0.5);
60
  }
61
 
62
  .matrix-cell:hover {
 
78
  border-right: .15em solid #00d9ff;
79
  white-space: nowrap;
80
  animation: typing 3.5s steps(40, end), blink-caret .75s step-end infinite;
81
+ width: 0;
82
+ }
83
+
84
+ /* Improved accessibility for focus states */
85
+ button:focus, input:focus, textarea:focus {
86
+ outline: 2px solid #00d9ff;
87
+ outline-offset: 2px;
88
+ }
89
+
90
+ /* Sample text button */
91
+ .sample-btn {
92
+ background: linear-gradient(135deg, #a855f7, #00d9ff);
93
+ transition: all 0.3s ease;
94
+ }
95
+
96
+ .sample-btn:hover {
97
+ transform: translateY(-2px);
98
+ box-shadow: 0 10px 25px rgba(168, 85, 247, 0.3);
99
+ }
100
+
101
+ /* Error message style */
102
+ .error-message {
103
+ color: #ef4444;
104
+ font-size: 0.875rem;
105
+ margin-top: 0.5rem;
106
  }
107
 
108
  @keyframes typing {
 
123
  SYNTACTIC BUNKER
124
  </h1>
125
  <p class="text-center text-cyberblue mt-2" data-aos="fade-down" data-aos-delay="200">
126
+ Context Compression Demo (Real Backend Integration)
127
  </p>
128
  </div>
129
  </header>
 
141
  <textarea
142
  id="inputText"
143
  class="w-full h-[400px] bg-[#1a1a3a] border border-cyberblue/30 rounded-lg p-4 text-white resize-none focus:outline-none focus:ring-2 focus:ring-cyberblue"
144
+ placeholder="Paste your conversation history here...&#10;&#10;Example:&#10;'User: Hello, how are you?&#10;AI: I'm great, thanks! What can I help with today?'"
145
+ aria-label="Conversation history input"
146
  ></textarea>
147
  <div class="absolute bottom-3 right-3 text-xs text-gray-400">
148
  <span id="charCount">0</span> characters
 
204
  id="queryInput"
205
  class="flex-grow bg-[#1a1a3a] border border-cyberpurple/30 rounded-l-lg p-3 text-white focus:outline-none"
206
  placeholder="Ask about the original text..."
207
+ aria-label="Query input"
208
  >
209
  <button
210
+ class="bg-cyberpurple text-white px-4 rounded-r-lg hover:bg-purple-600 transition-all disabled:opacity-50 disabled:cursor-not-allowed"
211
+ id="queryBtn"
212
+ aria-label="Ask question"
213
  >
214
  <i data-feather="search"></i>
215
  </button>
 
231
  <div class="space-y-4">
232
  <!-- How it Works -->
233
  <div class="collapse-container">
234
+ <button class="collapse-btn w-full text-left p-4 bg-[#1a1a3a] rounded-lg flex justify-between items-center focus:outline-none" aria-expanded="false" aria-controls="how-it-works">
235
  <span class="font-semibold text-cyberblue">How It Works (TF-IDF + Dimensionality Reduction)</span>
236
+ <i data-feather="chevron-down" class="collapse-icon transition-transform duration-300"></i>
237
  </button>
238
+ <div id="how-it-works" class="collapse-content hidden p-4 bg-[#1a1a3a] rounded-b-lg mt-1">
239
+ <p>Our compression algorithm uses Term Frequency-Inverse Document Frequency (TF-IDF) to identify the most semantically significant tokens in the conversation history. Through principal component analysis and neural embeddings, we reduce dimensionality from O(n) to a fixed 64-dimensional state vector while preserving semantic relationships. Now powered by a real Python backend using scikit-learn!</p>
240
  </div>
241
  </div>
242
 
 
272
  </footer>
273
 
274
  <script>
275
+ // Backend endpoint configuration
276
+ const BACKEND_URL = 'http://localhost:5000/compress'; // Adjust if needed
277
+
278
+ // Global variables
279
+ let isCompressed = false;
280
+ let currentVector = [];
281
+
282
  // Initialize animations and icons
283
  AOS.init({
284
  duration: 800,
285
  once: true
286
  });
287
+
 
288
  // Initialize matrix grid
289
  function initializeMatrix() {
290
  const matrixGrid = document.getElementById('matrixGrid');
 
295
  cell.className = 'matrix-cell';
296
  cell.textContent = '0.00';
297
  cell.id = `matrix-cell-${i}`;
298
+ cell.setAttribute('role', 'gridcell');
299
+ cell.setAttribute('aria-label', `Dimension ${i + 1}`);
300
  matrixGrid.appendChild(cell);
301
  }
302
+ matrixGrid.setAttribute('role', 'grid');
303
+ matrixGrid.setAttribute('aria-label', 'Compressed state vector matrix');
304
  }
305
 
306
  // Update character count
 
308
  const text = document.getElementById('inputText').value;
309
  document.getElementById('charCount').textContent = text.length;
310
  }
311
+
312
+ // Show error message
313
+ function showError(message) {
314
+ const errorEl = document.getElementById('errorMessage');
315
+ errorEl.textContent = message;
316
+ errorEl.classList.remove('hidden');
317
+ }
318
+
319
+ // Hide error message
320
+ function hideError() {
321
+ document.getElementById('errorMessage').classList.add('hidden');
322
+ }
323
+
324
+ // Load sample text
325
+ function loadSample() {
326
+ const sampleText = `User: Tell me about AI context compression.
327
+ AI: Context compression is a technique to reduce the memory footprint of long conversations in large language models. It preserves key semantic information while discarding redundancy.
328
+ User: How does it work?
329
+ AI: It typically involves summarization, key-value extraction, or embedding-based reduction to a fixed-size vector.
330
+ User: What's the benefit for VRAM?
331
+ AI: It allows handling much longer contexts without exceeding GPU memory limits, scaling from O(n²) to O(1) in attention computation.`;
332
+ document.getElementById('inputText').value = sampleText;
333
+ updateCharCount();
334
+ hideError();
335
+ }
336
 
337
+ // Compress text with backend
338
+ async function compressText() {
339
+ const inputText = document.getElementById('inputText').value.trim();
340
+ if (!inputText) {
341
+ showError('Please enter some conversation text first');
342
  return;
343
  }
344
 
345
+ hideError();
346
+
347
  // Show processing animation
348
+ const processingEl = document.getElementById('processingAnimation');
349
+ const btn = document.getElementById('compressBtn');
350
+ processingEl.classList.remove('hidden');
351
+ btn.disabled = true;
352
+ isCompressed = false;
353
 
354
+ try {
355
+ const response = await fetch(BACKEND_URL, {
356
+ method: 'POST',
357
+ headers: {
358
+ 'Content-Type': 'application/json',
359
+ },
360
+ body: JSON.stringify({ text: inputText })
361
+ });
362
+
363
+ if (!response.ok) {
364
+ throw new Error(`Backend error: ${response.status}`);
365
+ }
366
+
367
+ const data = await response.json();
368
+ currentVector = data.vector;
369
+
370
  // Update matrix display
371
+ currentVector.forEach((value, index) => {
372
+ const cell = document.getElementById(`matrix-cell-${index}`);
373
+ cell.style.transition = 'all 0.5s ease';
374
+ cell.textContent = value.toFixed(2);
375
+ cell.style.color = parseFloat(value) > 0 ? '#00d9ff' : '#a855f7';
376
  });
377
 
378
  // Calculate compression metrics
379
+ const inputLength = inputText.length;
380
+ const originalSizeBytes = inputLength * 4; // Approximate 4 bytes per char
381
+ const compressedSizeBytes = 64 * 8; // 64 floats * 8 bytes
382
+ const compressionRatio = ((1 - compressedSizeBytes / originalSizeBytes) * 100).toFixed(1);
383
 
384
  document.getElementById('compressionRatio').textContent =
385
+ `${Math.max(0, compressionRatio)}% compression achieved`;
386
+
387
+ const originalSizeGB = (originalSizeBytes / (1024 ** 3)).toFixed(3);
388
+ const compressedSizeGB = (compressedSizeBytes / (1024 ** 3)).toFixed(3);
389
 
390
  document.getElementById('vramSavings').innerHTML =
391
+ `Original: <span class="text-cyberblue">${originalSizeGB}GB</span> → ` +
392
+ `Compressed: <span class="text-cyberpurple">${compressedSizeGB}GB</span>`;
393
 
394
+ // Enable query
395
+ document.getElementById('queryBtn').disabled = false;
396
+ isCompressed = true;
397
 
398
+ } catch (error) {
399
+ console.error('Compression error:', error);
400
+ showError('Failed to compress: ' + error.message + '. Ensure backend is running on localhost:5000.');
401
+ } finally {
402
+ // Hide processing animation
403
+ processingEl.classList.add('hidden');
404
+ btn.disabled = false;
405
+ }
406
  }
407
 
408
+ // Ask question simulation (can be extended to use vector)
409
  function askQuestion() {
410
+ const question = document.getElementById('queryInput').value.trim();
411
+ if (!question) {
412
  alert('Please enter a question');
413
  return;
414
  }
415
 
416
+ if (!isCompressed) {
417
+ alert('Please compress the text first');
418
+ return;
419
+ }
420
+
421
  const responses = [
422
  "Based on the compressed context, the conversation primarily discussed artificial intelligence and memory optimization techniques.",
423
  "The state vector indicates the dialogue focused on neural network architectures and efficiency improvements.",
 
427
  ];
428
 
429
  const responseArea = document.getElementById('responseArea');
430
+ const responseText = responses[Math.floor(Math.random() * responses.length)];
431
+ responseArea.innerHTML = `<p class="typewriter text-cyberblue">${responseText}</p>`;
432
+
433
+ // Clear input
434
+ document.getElementById('queryInput').value = '';
435
  }
436
 
437
+ // Collapse functionality with ARIA updates
438
+ function initCollapses() {
439
+ document.querySelectorAll('.collapse-btn').forEach(button => {
440
+ button.addEventListener('click', () => {
441
+ const content = button.nextElementSibling;
442
+ const icon = button.querySelector('.collapse-icon');
443
+ const isExpanded = !content.classList.contains('hidden');
444
+
445
+ content.classList.toggle('hidden');
446
+ button.setAttribute('aria-expanded', !isExpanded);
447
+ icon.setAttribute('data-feather', isExpanded ? 'chevron-down' : 'chevron-up');
448
+ feather.replace({ width: '20', height: '20' });
449
+ });
450
  });
451
+ }
452
+
453
+ // Event listeners setup
454
+ function initEventListeners() {
455
+ document.getElementById('inputText').addEventListener('input', updateCharCount);
456
+ document.getElementById('sampleBtn').addEventListener('click', loadSample);
457
+ document.getElementById('compressBtn').addEventListener('click', compressText);
458
+ document.getElementById('queryBtn').addEventListener('click', askQuestion);
459
+ document.getElementById('queryInput').addEventListener('keypress', (e) => {
460
+ if (e.key === 'Enter') askQuestion();
461
+ });
462
+
463
+ // Disable query button initially
464
+ document.getElementById('queryBtn').disabled = true;
465
+ }
466
 
467
  // Initialize on load
468
  document.addEventListener('DOMContentLoaded', () => {
469
+ feather.replace();
470
  initializeMatrix();
471
  updateCharCount();
472
+ initEventListeners();
473
+ initCollapses();
474
  });
475
  </script>
476
  </body>
prompts.txt CHANGED
@@ -21,3 +21,489 @@ BOTTOM: Technical explanation panel with expandable sections:
21
  - "Information Preservation" (Shannon vs Gödelian information concepts)
22
 
23
  STYLING: Cyberpunk aesthetic, blue/purple gradients, clean typography, smooth animations.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  - "Information Preservation" (Shannon vs Gödelian information concepts)
22
 
23
  STYLING: Cyberpunk aesthetic, blue/purple gradients, clean typography, smooth animations.
24
+
25
+ <!DOCTYPE html>
26
+ <html lang="en">
27
+ <head>
28
+ <meta charset="UTF-8">
29
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
30
+ <title>Syntactic Bunker - Context Compression Demo</title>
31
+ <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
32
+ <script src="https://cdn.tailwindcss.com"></script>
33
+ <script>
34
+ tailwind.config = {
35
+ theme: {
36
+ extend: {
37
+ colors: {
38
+ cyberblue: '#00d9ff',
39
+ cyberpurple: '#a855f7',
40
+ darkbg: '#0a0a18',
41
+ panelbg: '#121230',
42
+ }
43
+ }
44
+ }
45
+ }
46
+ </script>
47
+ <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
48
+ <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
49
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
50
+ <style>
51
+ @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;600&family=Orbitron:wght@400;600&display=swap');
52
+
53
+ body {
54
+ font-family: 'JetBrains Mono', monospace;
55
+ background-color: #0a0a18;
56
+ color: #ffffff;
57
+ overflow-x: hidden;
58
+ }
59
+
60
+ .cyber-gradient {
61
+ background: linear-gradient(135deg, #00d9ff 0%, #a855f7 100%);
62
+ }
63
+
64
+ .cyber-border {
65
+ border: 1px solid rgba(0, 217, 255, 0.3);
66
+ box-shadow: 0 0 15px rgba(0, 217, 255, 0.2);
67
+ }
68
+
69
+ .cyber-glow {
70
+ box-shadow: 0 0 20px rgba(0, 217, 255, 0.4);
71
+ }
72
+
73
+ .matrix-cell {
74
+ width: 40px;
75
+ height: 40px;
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ font-size: 12px;
80
+ border: 1px solid rgba(168, 85, 247, 0.2);
81
+ transition: all 0.3s ease;
82
+ background-color: rgba(18, 18, 48, 0.5);
83
+ }
84
+
85
+ .matrix-cell:hover {
86
+ background: rgba(168, 85, 247, 0.1);
87
+ transform: scale(1.1);
88
+ }
89
+
90
+ .helix-animation {
91
+ animation: rotate 2s linear infinite;
92
+ }
93
+
94
+ @keyframes rotate {
95
+ from { transform: rotate(0deg); }
96
+ to { transform: rotate(360deg); }
97
+ }
98
+
99
+ .typewriter {
100
+ overflow: hidden;
101
+ border-right: .15em solid #00d9ff;
102
+ white-space: nowrap;
103
+ animation: typing 3.5s steps(40, end), blink-caret .75s step-end infinite;
104
+ width: 0;
105
+ }
106
+
107
+ @keyframes typing {
108
+ from { width: 0 }
109
+ to { width: 100% }
110
+ }
111
+
112
+ @keyframes blink-caret {
113
+ from, to { border-color: transparent }
114
+ 50% { border-color: #00d9ff; }
115
+ }
116
+
117
+ /* Improved accessibility for focus states */
118
+ button:focus, input:focus, textarea:focus {
119
+ outline: 2px solid #00d9ff;
120
+ outline-offset: 2px;
121
+ }
122
+
123
+ /* Sample text button */
124
+ .sample-btn {
125
+ background: linear-gradient(135deg, #a855f7, #00d9ff);
126
+ transition: all 0.3s ease;
127
+ }
128
+
129
+ .sample-btn:hover {
130
+ transform: translateY(-2px);
131
+ box-shadow: 0 10px 25px rgba(168, 85, 247, 0.3);
132
+ }
133
+
134
+ /* Error message style */
135
+ .error-message {
136
+ color: #ef4444;
137
+ font-size: 0.875rem;
138
+ margin-top: 0.5rem;
139
+ }
140
+ </style>
141
+ </head>
142
+ <body class="bg-darkbg min-h-screen">
143
+ <header class="py-6 border-b cyber-border">
144
+ <div class="container mx-auto px-6">
145
+ <h1 class="text-3xl md:text-4xl font-bold text-center cyber-gradient bg-clip-text text-transparent" data-aos="fade-down">
146
+ SYNTACTIC BUNKER
147
+ </h1>
148
+ <p class="text-center text-cyberblue mt-2" data-aos="fade-down" data-aos-delay="200">
149
+ Context Compression Demo (Real Backend Integration)
150
+ </p>
151
+ </div>
152
+ </header>
153
+
154
+ <main class="container mx-auto px-4 py-8">
155
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
156
+ <!-- LEFT PANEL - Input Section -->
157
+ <div class="bg-panelbg rounded-xl p-6 cyber-border" data-aos="fade-right">
158
+ <h2 class="text-xl font-semibold text-cyberblue mb-4 flex items-center">
159
+ <i data-feather="message-square" class="mr-2"></i>
160
+ Conversation History Input
161
+ </h2>
162
+
163
+ <div class="relative mb-4">
164
+ <textarea
165
+ id="inputText"
166
+ class="w-full h-[400px] bg-[#1a1a3a] border border-cyberblue/30 rounded-lg p-4 text-white resize-none focus:outline-none focus:ring-2 focus:ring-cyberblue"
167
+ placeholder="Paste your conversation history here...&#10;&#10;Example:&#10;'User: Hello, how are you?&#10;AI: I'm great, thanks! What can I help with today?'"
168
+ aria-label="Conversation history input"
169
+ ></textarea>
170
+ <div class="absolute bottom-3 right-3 text-xs text-gray-400">
171
+ <span id="charCount">0</span> characters
172
+ </div>
173
+ </div>
174
+
175
+ <div id="errorMessage" class="error-message hidden"></div>
176
+
177
+ <div class="flex flex-col sm:flex-row gap-4 justify-center mb-6">
178
+ <button
179
+ id="sampleBtn"
180
+ class="sample-btn text-white px-6 py-2 rounded-lg font-semibold flex items-center"
181
+ >
182
+ <i data-feather="plus-circle" class="mr-2"></i>
183
+ Load Sample
184
+ </button>
185
+ <button
186
+ id="compressBtn"
187
+ class="cyber-glow bg-cyberblue text-white px-8 py-3 rounded-lg font-semibold hover:bg-cyan-600 transition-all flex items-center disabled:opacity-50 disabled:cursor-not-allowed"
188
+ aria-label="Compress text to state vector"
189
+ >
190
+ <i data-feather="cpu" class="mr-2"></i>
191
+ Compress to State Vector
192
+ </button>
193
+ </div>
194
+
195
+ <div id="processingAnimation" class="hidden mt-6 flex justify-center items-center">
196
+ <div class="helix-animation text-cyberblue">
197
+ <i data-feather="loader" class="w-12 h-12"></i>
198
+ </div>
199
+ <span class="ml-3 text-cyberblue">Processing with backend...</span>
200
+ </div>
201
+ </div>
202
+
203
+ <!-- RIGHT PANEL - Output Section -->
204
+ <div class="bg-panelbg rounded-xl p-6 cyber-border" data-aos="fade-left">
205
+ <h2 class="text-xl font-semibold text-cyberpurple mb-4 flex items-center">
206
+ <i data-feather="database" class="mr-2"></i>
207
+ Compressed State Vector
208
+ </h2>
209
+
210
+ <div class="grid grid-cols-8 gap-1 mb-6 bg-[#1a1a3a] p-3 rounded-lg">
211
+ <!-- 8x8 Matrix Grid -->
212
+ <div id="matrixGrid" class="grid grid-cols-8 gap-1">
213
+ <!-- Matrix cells will be generated dynamically -->
214
+ </div>
215
+ </div>
216
+
217
+ <div class="mb-6 text-center">
218
+ <div id="compressionRatio" class="text-3xl font-bold text-cyberpurple">
219
+ 0.0% compression
220
+ </div>
221
+ <div class="text-sm text-gray-400 mt-1">Information density achieved</div>
222
+ </div>
223
+
224
+ <div class="mb-6 p-4 bg-[#1a1a3a] rounded-lg">
225
+ <h3 class="text-cyberblue mb-2 font-semibold">VRAM Savings</h3>
226
+ <div id="vramSavings" class="text-lg">
227
+ Original: 0.0GB → Compressed: 0.0GB
228
+ </div>
229
+ </div>
230
+
231
+ <div class="mb-4">
232
+ <h3 class="text-cyberpurple mb-2 font-semibold">Query Interface</h3>
233
+ <div class="flex">
234
+ <input
235
+ type="text"
236
+ id="queryInput"
237
+ class="flex-grow bg-[#1a1a3a] border border-cyberpurple/30 rounded-l-lg p-3 text-white focus:outline-none"
238
+ placeholder="Ask about the original text..."
239
+ aria-label="Query input"
240
+ >
241
+ <button
242
+ class="bg-cyberpurple text-white px-4 rounded-r-lg hover:bg-purple-600 transition-all disabled:opacity-50 disabled:cursor-not-allowed"
243
+ id="queryBtn"
244
+ aria-label="Ask question"
245
+ >
246
+ <i data-feather="search"></i>
247
+ </button>
248
+ </div>
249
+ </div>
250
+
251
+ <div id="responseArea" class="bg-[#1a1a3a] p-4 rounded-lg min-h-[100px]">
252
+ <p class="text-gray-400 italic">Responses will appear here based on the compressed vector...</p>
253
+ </div>
254
+ </div>
255
+ </div>
256
+
257
+ <!-- BOTTOM: Technical Explanation Panel -->
258
+ <div class="mt-12 bg-panelbg rounded-xl p-6 cyber-border" data-aos="fade-up">
259
+ <h2 class="text-xl font-semibold text-center mb-6 cyber-gradient bg-clip-text text-transparent">
260
+ Technical Specifications
261
+ </h2>
262
+
263
+ <div class="space-y-4">
264
+ <!-- How it Works -->
265
+ <div class="collapse-container">
266
+ <button class="collapse-btn w-full text-left p-4 bg-[#1a1a3a] rounded-lg flex justify-between items-center focus:outline-none" aria-expanded="false" aria-controls="how-it-works">
267
+ <span class="font-semibold text-cyberblue">How It Works (TF-IDF + Dimensionality Reduction)</span>
268
+ <i data-feather="chevron-down" class="collapse-icon transition-transform duration-300"></i>
269
+ </button>
270
+ <div id="how-it-works" class="collapse-content hidden p-4 bg-[#1a1a3a] rounded-b-lg mt-1">
271
+ <p>Our compression algorithm uses Term Frequency-Inverse Document Frequency (TF-IDF) to identify the most semantically significant tokens in the conversation history. Through principal component analysis and neural embeddings, we reduce dimensionality from O(n) to a fixed 64-dimensional state vector while preserving semantic relationships. Now powered by a real Python backend using scikit-learn!</p>
272
+ </div>
273
+ </div>
274
+
275
+ <!-- VRAM Efficiency Theory -->
276
+ <div class="collapse-container">
277
+ <button class="collapse-btn w-full text-left p-4 bg-[#1a1a3a] rounded-lg flex justify-between items-center focus:outline-none" aria-expanded="false" aria-controls="vram-efficiency">
278
+ <span class="font-semibold text-cyberpurple">VRAM Efficiency Theory (O(n²) vs O(1) Scaling)</span>
279
+ <i data-feather="chevron-down" class="collapse-icon transition-transform duration-300"></i>
280
+ </button>
281
+ <div id="vram-efficiency" class="collapse-content hidden p-4 bg-[#1a1a3a] rounded-b-lg mt-1">
282
+ <p>Traditional attention mechanisms scale quadratically (O(n²)) with context length, making long conversations prohibitively expensive. Our state vector approach maintains constant memory usage (O(1)) regardless of original context size, enabling efficient processing of extensive dialogue histories without VRAM constraints.</p>
283
+ </div>
284
+ </div>
285
+
286
+ <!-- Information Preservation -->
287
+ <div class="collapse-container">
288
+ <button class="collapse-btn w-full text-left p-4 bg-[#1a1a3a] rounded-lg flex justify-between items-center focus:outline-none" aria-expanded="false" aria-controls="info-preservation">
289
+ <span class="font-semibold text-cyberblue">Information Preservation (Shannon vs Gödelian Concepts)</span>
290
+ <i data-feather="chevron-down" class="collapse-icon transition-transform duration-300"></i>
291
+ </button>
292
+ <div id="info-preservation" class="collapse-content hidden p-4 bg-[#1a1a3a] rounded-b-lg mt-1">
293
+ <p>While Shannon information theory focuses on probabilistic entropy, our approach incorporates Gödelian concepts of meaningful information preservation. The compression maintains not just statistical patterns but logical relationships and semantic coherence, allowing accurate reconstruction of conversation context from the minimal state vector.</p>
294
+ </div>
295
+ </div>
296
+ </div>
297
+ </div>
298
+ </main>
299
+
300
+ <footer class="py-6 mt-12 border-t cyber-border">
301
+ <div class="container mx-auto px-6 text-center text-sm text-gray-400">
302
+ <p>Syntactic Bunker © 2025 - Context Compression Technology Demo</p>
303
+ </div>
304
+ </footer>
305
+
306
+ <script>
307
+ // Backend endpoint configuration
308
+ const BACKEND_URL = 'http://localhost:5000/compress'; // Adjust if needed
309
+
310
+ // Global variables
311
+ let isCompressed = false;
312
+ let currentVector = [];
313
+
314
+ // Initialize animations and icons
315
+ AOS.init({
316
+ duration: 800,
317
+ once: true
318
+ });
319
+
320
+ // Initialize matrix grid
321
+ function initializeMatrix() {
322
+ const matrixGrid = document.getElementById('matrixGrid');
323
+ matrixGrid.innerHTML = '';
324
+
325
+ for (let i = 0; i < 64; i++) {
326
+ const cell = document.createElement('div');
327
+ cell.className = 'matrix-cell';
328
+ cell.textContent = '0.00';
329
+ cell.id = `matrix-cell-${i}`;
330
+ cell.setAttribute('role', 'gridcell');
331
+ cell.setAttribute('aria-label', `Dimension ${i + 1}`);
332
+ matrixGrid.appendChild(cell);
333
+ }
334
+ matrixGrid.setAttribute('role', 'grid');
335
+ matrixGrid.setAttribute('aria-label', 'Compressed state vector matrix');
336
+ }
337
+
338
+ // Update character count
339
+ function updateCharCount() {
340
+ const text = document.getElementById('inputText').value;
341
+ document.getElementById('charCount').textContent = text.length;
342
+ }
343
+
344
+ // Show error message
345
+ function showError(message) {
346
+ const errorEl = document.getElementById('errorMessage');
347
+ errorEl.textContent = message;
348
+ errorEl.classList.remove('hidden');
349
+ }
350
+
351
+ // Hide error message
352
+ function hideError() {
353
+ document.getElementById('errorMessage').classList.add('hidden');
354
+ }
355
+
356
+ // Load sample text
357
+ function loadSample() {
358
+ const sampleText = `User: Tell me about AI context compression.
359
+ AI: Context compression is a technique to reduce the memory footprint of long conversations in large language models. It preserves key semantic information while discarding redundancy.
360
+ User: How does it work?
361
+ AI: It typically involves summarization, key-value extraction, or embedding-based reduction to a fixed-size vector.
362
+ User: What's the benefit for VRAM?
363
+ AI: It allows handling much longer contexts without exceeding GPU memory limits, scaling from O(n²) to O(1) in attention computation.`;
364
+ document.getElementById('inputText').value = sampleText;
365
+ updateCharCount();
366
+ hideError();
367
+ }
368
+
369
+ // Compress text with backend
370
+ async function compressText() {
371
+ const inputText = document.getElementById('inputText').value.trim();
372
+ if (!inputText) {
373
+ showError('Please enter some conversation text first');
374
+ return;
375
+ }
376
+
377
+ hideError();
378
+
379
+ // Show processing animation
380
+ const processingEl = document.getElementById('processingAnimation');
381
+ const btn = document.getElementById('compressBtn');
382
+ processingEl.classList.remove('hidden');
383
+ btn.disabled = true;
384
+ isCompressed = false;
385
+
386
+ try {
387
+ const response = await fetch(BACKEND_URL, {
388
+ method: 'POST',
389
+ headers: {
390
+ 'Content-Type': 'application/json',
391
+ },
392
+ body: JSON.stringify({ text: inputText })
393
+ });
394
+
395
+ if (!response.ok) {
396
+ throw new Error(`Backend error: ${response.status}`);
397
+ }
398
+
399
+ const data = await response.json();
400
+ currentVector = data.vector;
401
+
402
+ // Update matrix display
403
+ currentVector.forEach((value, index) => {
404
+ const cell = document.getElementById(`matrix-cell-${index}`);
405
+ cell.style.transition = 'all 0.5s ease';
406
+ cell.textContent = value.toFixed(2);
407
+ cell.style.color = parseFloat(value) > 0 ? '#00d9ff' : '#a855f7';
408
+ });
409
+
410
+ // Calculate compression metrics
411
+ const inputLength = inputText.length;
412
+ const originalSizeBytes = inputLength * 4; // Approximate 4 bytes per char
413
+ const compressedSizeBytes = 64 * 8; // 64 floats * 8 bytes
414
+ const compressionRatio = ((1 - compressedSizeBytes / originalSizeBytes) * 100).toFixed(1);
415
+
416
+ document.getElementById('compressionRatio').textContent =
417
+ `${Math.max(0, compressionRatio)}% compression achieved`;
418
+
419
+ const originalSizeGB = (originalSizeBytes / (1024 ** 3)).toFixed(3);
420
+ const compressedSizeGB = (compressedSizeBytes / (1024 ** 3)).toFixed(3);
421
+
422
+ document.getElementById('vramSavings').innerHTML =
423
+ `Original: <span class="text-cyberblue">${originalSizeGB}GB</span> → ` +
424
+ `Compressed: <span class="text-cyberpurple">${compressedSizeGB}GB</span>`;
425
+
426
+ // Enable query
427
+ document.getElementById('queryBtn').disabled = false;
428
+ isCompressed = true;
429
+
430
+ } catch (error) {
431
+ console.error('Compression error:', error);
432
+ showError('Failed to compress: ' + error.message + '. Ensure backend is running on localhost:5000.');
433
+ } finally {
434
+ // Hide processing animation
435
+ processingEl.classList.add('hidden');
436
+ btn.disabled = false;
437
+ }
438
+ }
439
+
440
+ // Ask question simulation (can be extended to use vector)
441
+ function askQuestion() {
442
+ const question = document.getElementById('queryInput').value.trim();
443
+ if (!question) {
444
+ alert('Please enter a question');
445
+ return;
446
+ }
447
+
448
+ if (!isCompressed) {
449
+ alert('Please compress the text first');
450
+ return;
451
+ }
452
+
453
+ const responses = [
454
+ "Based on the compressed context, the conversation primarily discussed artificial intelligence and memory optimization techniques.",
455
+ "The state vector indicates the dialogue focused on neural network architectures and efficiency improvements.",
456
+ "From the compressed data, I can infer the conversation involved technical discussions about transformer models and their limitations.",
457
+ "The semantic embeddings suggest the original text covered topics related to machine learning scalability challenges.",
458
+ "Analysis of the state vector reveals discussions about context window limitations and potential solutions."
459
+ ];
460
+
461
+ const responseArea = document.getElementById('responseArea');
462
+ const responseText = responses[Math.floor(Math.random() * responses.length)];
463
+ responseArea.innerHTML = `<p class="typewriter text-cyberblue">${responseText}</p>`;
464
+
465
+ // Clear input
466
+ document.getElementById('queryInput').value = '';
467
+ }
468
+
469
+ // Collapse functionality with ARIA updates
470
+ function initCollapses() {
471
+ document.querySelectorAll('.collapse-btn').forEach(button => {
472
+ button.addEventListener('click', () => {
473
+ const content = button.nextElementSibling;
474
+ const icon = button.querySelector('.collapse-icon');
475
+ const isExpanded = !content.classList.contains('hidden');
476
+
477
+ content.classList.toggle('hidden');
478
+ button.setAttribute('aria-expanded', !isExpanded);
479
+ icon.setAttribute('data-feather', isExpanded ? 'chevron-down' : 'chevron-up');
480
+ feather.replace({ width: '20', height: '20' });
481
+ });
482
+ });
483
+ }
484
+
485
+ // Event listeners setup
486
+ function initEventListeners() {
487
+ document.getElementById('inputText').addEventListener('input', updateCharCount);
488
+ document.getElementById('sampleBtn').addEventListener('click', loadSample);
489
+ document.getElementById('compressBtn').addEventListener('click', compressText);
490
+ document.getElementById('queryBtn').addEventListener('click', askQuestion);
491
+ document.getElementById('queryInput').addEventListener('keypress', (e) => {
492
+ if (e.key === 'Enter') askQuestion();
493
+ });
494
+
495
+ // Disable query button initially
496
+ document.getElementById('queryBtn').disabled = true;
497
+ }
498
+
499
+ // Initialize on load
500
+ document.addEventListener('DOMContentLoaded', () => {
501
+ feather.replace();
502
+ initializeMatrix();
503
+ updateCharCount();
504
+ initEventListeners();
505
+ initCollapses();
506
+ });
507
+ </script>
508
+ </body>
509
+ </html>