Spaces:
Runtime error
Runtime error
Download streamlit_app.py from Rag9999/anycoder-cb50d60e: direct link, hf CLI and curl.
- Browser
- Download file 28.7 kB
-
https://huggingface.co/spaces/Rag9999/anycoder-cb50d60e/resolve/main/streamlit_app.py
- Command line
-
hf download hf://spaces/Rag9999/anycoder-cb50d60e/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/Rag9999/anycoder-cb50d60e/resolve/main/streamlit_app.py
28.7 kB
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>RAGBuilder - Interactive Architecture Design</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/Flip.min.js"></script> | |
| <script src="https://unpkg.com/lucide@latest"></script> | |
| <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;800&family=Inter:wght@300;400;600;800&display=swap" rel="stylesheet"> | |
| <style> | |
| :root { | |
| --neon-blue: #00f0ff; | |
| --neon-purple: #bc13fe; | |
| --neon-green: #0aff0a; | |
| --bg-dark: #050510; | |
| --panel-bg: #0a0a1a; | |
| } | |
| body { | |
| background-color: var(--bg-dark); | |
| color: #e2e8f0; | |
| font-family: 'Inter', sans-serif; | |
| overflow-x: hidden; | |
| } | |
| .font-mono { | |
| font-family: 'JetBrains Mono', monospace; | |
| } | |
| /* Background Grid Animation */ | |
| .bg-grid { | |
| background-image: | |
| linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px), | |
| linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px); | |
| background-size: 40px 40px; | |
| mask-image: radial-gradient(circle at center, black 40%, transparent 100%); | |
| } | |
| .glow-box { | |
| box-shadow: 0 0 20px rgba(0, 240, 255, 0.1), inset 0 0 20px rgba(0, 240, 255, 0.05); | |
| border: 1px solid rgba(0, 240, 255, 0.2); | |
| backdrop-filter: blur(10px); | |
| transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); | |
| } | |
| .glow-box:hover { | |
| transform: translateY(-2px) scale(1.01); | |
| box-shadow: 0 0 30px rgba(0, 240, 255, 0.2), inset 0 0 30px rgba(0, 240, 255, 0.1); | |
| border-color: rgba(0, 240, 255, 0.5); | |
| } | |
| /* SVG Connector Lines */ | |
| #connection-svg { | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| pointer-events: none; | |
| z-index: 0; | |
| } | |
| .connector-path { | |
| fill: none; | |
| stroke: var(--neon-blue); | |
| stroke-width: 2; | |
| stroke-dasharray: 10; | |
| animation: dash 1s linear infinite; | |
| opacity: 0.4; | |
| } | |
| to { | |
| stroke-dashoffset: -20; | |
| } | |
| } | |
| /* Glassmorphism */ | |
| .glass-panel { | |
| background: rgba(10, 10, 26, 0.7); | |
| backdrop-filter: blur(20px); | |
| border: 1px solid rgba(255, 255, 255, 0.08); | |
| border-radius: 16px; | |
| } | |
| /* Custom Scrollbar */ | |
| ::-webkit-scrollbar { | |
| width: 8px; | |
| } | |
| ::-webkit-scrollbar-track { | |
| background: #0a0a1a; | |
| } | |
| ::-webkit-scrollbar-thumb { | |
| background: #334155; | |
| border-radius: 4px; | |
| } | |
| ::-webkit-scrollbar-thumb:hover { | |
| background: #475569; | |
| } | |
| .typing-cursor::after { | |
| content: '|'; | |
| animation: blink 1s step-end infinite; | |
| } | |
| 50% { opacity: 0; } | |
| } | |
| .node-icon { | |
| background: linear-gradient(135deg, rgba(0,240,255,0.1) 0%, rgba(188,19,254,0.1) 100%); | |
| border: 1px solid rgba(0,240,255,0.3); | |
| } | |
| .active-node { | |
| border-color: var(--neon-green); | |
| box-shadow: 0 0 15px var(--neon-green); | |
| } | |
| /* Interactive Data Particles */ | |
| .particle { | |
| position: absolute; | |
| width: 6px; | |
| height: 6px; | |
| background: var(--neon-blue); | |
| border-radius: 50%; | |
| filter: blur(1px); | |
| opacity: 0; | |
| } | |
| </style> | |
| </head> | |
| <body class="relative min-h-screen flex flex-col"> | |
| <!-- Background Effects --> | |
| <div class="fixed inset-0 z-[-1] bg-grid"></div> | |
| <div class="fixed top-0 left-0 w-full h-full z-[-1] bg-gradient-to-b from-transparent via-[#050510] to-[#050510]"></div> | |
| <!-- Ambient Glow Orbs --> | |
| <div class="fixed top-[-20%] left-[-10%] w-[500px] h-[500px] bg-blue-600/20 rounded-full blur-[120px] z-[-1]"></div> | |
| <div class="fixed bottom-[-20%] right-[-10%] w-[600px] h-[600px] bg-purple-600/10 rounded-full blur-[120px] z-[-1]"></div> | |
| <!-- Main Container --> | |
| <main class="flex-grow container mx-auto px-4 py-12 relative max-w-7xl" id="app-container"> | |
| <!-- SVG Layer for Connections --> | |
| <svg id="connection-svg"> | |
| <defs> | |
| <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%"> | |
| <stop offset="0%" style="stop-color:var(--neon-blue);stop-opacity:1" /> | |
| <stop offset="100%" style="stop-color:var(--neon-purple);stop-opacity:1" /> | |
| </linearGradient> | |
| </defs> | |
| </svg> | |
| <!-- Header --> | |
| <header class="text-center mb-16 relative z-10"> | |
| <div class="inline-flex items-center gap-2 px-4 py-1 rounded-full bg-white/5 border border-white/10 text-xs font-mono text-cyan-400 mb-6 animate-pulse"> | |
| <span class="w-2 h-2 rounded-full bg-green-500"></span> SYSTEM ONLINE | |
| </div> | |
| <h1 class="text-5xl md:text-7xl font-bold tracking-tighter mb-4 bg-clip-text text-transparent bg-gradient-to-r from-white via-cyan-200 to-purple-300"> | |
| RAG<span class="text-cyan-400">Builder</span> | |
| </h1> | |
| <p class="text-xl text-slate-400 max-w-2xl mx-auto font-light"> | |
| Interactive Retrieval-Augmented Generation Architecture. <br> | |
| <span class="text-sm text-slate-500 mt-2 block">Drag, drop, configure, and visualize how AI retrieves context.</span> | |
| </p> | |
| </header> | |
| <!-- Architecture Diagram --> | |
| <div class="relative w-full h-[800px] glass-panel p-8 mb-12 hidden md:block" id="architecture-stage"> | |
| <!-- DATA INGESTION (Left) --> | |
| <div class="absolute left-8 top-1/2 -translate-y-1/2 w-64 flex flex-col gap-6" id="ingestion-col"> | |
| <div class="text-center font-mono text-xs text-cyan-400 mb-2 uppercase tracking-widest">Data Ingestion</div> | |
| <!-- Document Uploader Node --> | |
| <div id="node-uploader" class="glow-box bg-slate-900/80 p-4 rounded-xl relative group cursor-pointer z-20"> | |
| <div class="flex items-center gap-3"> | |
| <div class="node-icon p-2 rounded-lg text-cyan-400"> | |
| <i data-lucide="file-up" size="20"></i> | |
| </div> | |
| <div> | |
| <h3 class="font-bold text-sm">Document Loader</h3> | |
| <p class="text-xs text-slate-400">PDF, TXT, CSV</p> | |
| </div> | |
| </div> | |
| <div class="absolute -right-2 top-1/2 w-2 h-2 bg-cyan-400 rounded-full connector-point" data-id="uploader-out"></div> | |
| </div> | |
| <!-- Text Splitter Node --> | |
| <div id="node-splitter" class="glow-box bg-slate-900/80 p-4 rounded-xl relative group cursor-pointer z-20"> | |
| <div class="flex items-center gap-3"> | |
| <div class="node-icon p-2 rounded-lg text-purple-400"> | |
| <i data-lucide="scissors" size="20"></i> | |
| </div> | |
| <div> | |
| <h3 class="font-bold text-sm">Text Splitter</h3> | |
| <p class="text-xs text-slate-400">Recursive / Character</p> | |
| </div> | |
| </div> | |
| <div class="absolute -left-2 top-1/2 w-2 h-2 bg-purple-400 rounded-full connector-point" data-id="splitter-in"></div> | |
| <div class="absolute -right-2 top-1/2 w-2 h-2 bg-purple-400 rounded-full connector-point" data-id="splitter-out"></div> | |
| </div> | |
| </div> | |
| <!-- VECTOR STORE (Center) --> | |
| <div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-80 flex flex-col gap-6 items-center z-20" id="vector-col"> | |
| <div class="text-center font-mono text-xs text-purple-400 mb-2 uppercase tracking-widest">Indexing & Storage</div> | |
| <!-- Embedding Model --> | |
| <div id="node-embedding" class="glow-box bg-slate-900/80 p-4 rounded-xl w-full relative group cursor-pointer"> | |
| <div class="flex items-center gap-3"> | |
| <div class="node-icon p-2 rounded-lg text-pink-400"> | |
| <i data-lucide="brain-circuit" size="20"></i> | |
| </div> | |
| <div> | |
| <h3 class="font-bold text-sm">Embedding Model</h3> | |
| <p class="text-xs text-slate-400">all-MiniLM-L6-v2</p> | |
| </div> | |
| </div> | |
| <div class="absolute -left-2 top-1/2 w-2 h-2 bg-pink-400 rounded-full connector-point" data-id="embed-in"></div> | |
| <div class="absolute -right-2 top-1/2 w-2 h-2 bg-pink-400 rounded-full connector-point" data-id="embed-out"></div> | |
| </div> | |
| <!-- Vector DB --> | |
| <div id="node-vectordb" class="glow-box bg-slate-900/80 p-6 rounded-xl w-full border-purple-500/30 relative group cursor-pointer"> | |
| <div class="absolute inset-0 bg-purple-500/5 rounded-xl animate-pulse"></div> | |
| <div class="flex items-center justify-center gap-3 relative z-10"> | |
| <div class="node-icon p-3 rounded-lg text-purple-300 bg-purple-500/20"> | |
| <i data-lucide="database" size="24"></i> | |
| </div> | |
| <div class="text-center"> | |
| <h3 class="font-bold text-lg">Vector Database</h3> | |
| <p class="text-xs text-purple-200">FAISS / Chroma / Pinecone</p> | |
| </div> | |
| </div> | |
| <!-- Connection points for top (retrieval) and bottom (ingestion) --> | |
| <div class="absolute top-0 left-1/2 -translate-x-1/2 -translate-y-1/2 w-3 h-3 bg-purple-500 rounded-full border-2 border-slate-900 z-30" data-id="db-top"></div> | |
| <div class="absolute bottom-0 left-1/2 -translate-x-1/2 translate-y-1/2 w-3 h-3 bg-cyan-500 rounded-full border-2 border-slate-900 z-30" data-id="db-bottom"></div> | |
| </div> | |
| </div> | |
| <!-- GENERATION (Right) --> | |
| <div class="absolute right-8 top-1/2 -translate-y-1/2 w-64 flex flex-col gap-6 z-20" id="gen-col"> | |
| <div class="text-center font-mono text-xs text-green-400 mb-2 uppercase tracking-widest">Generation</div> | |
| <!-- Retriever --> | |
| <div id="node-retriever" class="glow-box bg-slate-900/80 p-4 rounded-xl relative group cursor-pointer"> | |
| <div class="flex items-center gap-3"> | |
| <div class="node-icon p-2 rounded-lg text-blue-400"> | |
| <i data-lucide="search" size="20"></i> | |
| </div> | |
| <div> | |
| <h3 class="font-bold text-sm">Retriever</h3> | |
| <p class="text-xs text-slate-400">Similarity Search (k=4)</p> | |
| </div> | |
| </div> | |
| <div class="absolute -left-2 top-1/2 w-2 h-2 bg-blue-400 rounded-full connector-point" data-id="retriever-in"></div> | |
| <div class="absolute -right-2 top-1/2 w-2 h-2 bg-blue-400 rounded-full connector-point" data-id="retriever-out"></div> | |
| </div> | |
| <!-- LLM --> | |
| <div id="node-llm" class="glow-box bg-slate-900/80 p-4 rounded-xl relative group cursor-pointer border-green-500/30"> | |
| <div class="flex items-center gap-3"> | |
| <div class="node-icon p-2 rounded-lg text-green-400 bg-green-500/10"> | |
| <i data-lucide="cpu" size="20"></i> | |
| </div> | |
| <div> | |
| <h3 class="font-bold text-sm">LLM</h3> | |
| <p class="text-xs text-slate-400">GPT-4 / Claude / Llama</p> | |
| </div> | |
| </div> | |
| <div class="absolute -left-2 top-1/2 w-2 h-2 bg-green-400 rounded-full connector-point" data-id="llm-in"></div> | |
| </div> | |
| </div> | |
| <!-- Query Input (Floating Top Center) --> | |
| <div id="node-query" class="absolute top-8 left-1/2 -translate-x-1/2 z-30 w-96"> | |
| <div class="glow-box bg-slate-800 p-2 rounded-lg flex items-center gap-2 border-cyan-500/50"> | |
| <i data-lucide="message-circle" class="text-cyan-400 ml-2"></i> | |
| <input type="text" id="query-input" placeholder="Enter user query..." class="bg-transparent border-none outline-none text-white w-full text-sm py-2 font-mono" value="How does the neural network function?"> | |
| <button id="run-btn" class="bg-cyan-500 hover:bg-cyan-400 text-black px-4 py-1.5 rounded font-bold text-xs transition-colors"> | |
| RUN RAG | |
| </button> | |
| </div> | |
| <!-- Connector point for query output --> | |
| <div class="absolute bottom-0 left-1/2 -translate-x-1/2 translate-y-1/2 w-3 h-3 bg-cyan-500 rounded-full border-2 border-slate-900 z-30" data-id="query-out"></div> | |
| </div> | |
| <!-- Final Output (Floating Bottom Center) --> | |
| <div id="node-output" class="absolute bottom-8 left-1/2 -translate-x-1/2 z-30 w-[600px]"> | |
| <div class="glow-box bg-slate-900 p-6 rounded-xl border-green-500/20 min-h-[100px]"> | |
| <div class="flex justify-between items-center mb-2"> | |
| <span class="text-xs font-mono text-green-400 uppercase">System Response</span> | |
| <span id="status-badge" class="text-[10px] bg-slate-800 px-2 py-1 rounded text-slate-400">IDLE</span> | |
| </div> | |
| <p id="final-output-text" class="text-slate-300 text-sm leading-relaxed font-mono typing-cursor"> | |
| Waiting for query execution... | |
| </p> | |
| </div> | |
| <!-- Connector point for input --> | |
| <div class="absolute top-0 left-1/2 -translate-x-1/2 -translate-y-1/2 w-3 h-3 bg-green-500 rounded-full border-2 border-slate-900 z-30" data-id="output-in"></div> | |
| </div> | |
| </div> | |
| <!-- Mobile View: Fallback Message --> | |
| <div class="md:hidden glass-panel p-8 text-center"> | |
| <i data-lucide="smartphone" class="mx-auto mb-4 text-cyan-400" size="48"></i> | |
| <h2 class="text-xl font-bold mb-2">Desktop Experience Required</h2> | |
| <p class="text-slate-400 text-sm">The interactive RAG architecture visualization requires a larger screen to display the node graph properly.</p> | |
| </div> | |
| <!-- Feature Grid --> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mt-12"> | |
| <div class="glass-panel p-6 hover:bg-slate-800/50 transition-colors"> | |
| <div class="w-12 h-12 rounded-lg bg-blue-500/10 flex items-center justify-center mb-4 text-blue-400"> | |
| <i data-lucide="zap" size="24"></i> | |
| </div> | |
| <h3 class="text-lg font-bold mb-2">Real-time Visualization</h3> | |
| <p class="text-sm text-slate-400">See data flow through the ingestion pipeline, vectorization process, and retrieval steps in real-time.</p> | |
| </div> | |
| <div class="glass-panel p-6 hover:bg-slate-800/50 transition-colors"> | |
| <div class="w-12 h-12 rounded-lg bg-purple-500/10 flex items-center justify-center mb-4 text-purple-400"> | |
| <i data-lucide="layers" size="24"></i> | |
| </div> | |
| <h3 class="text-lg font-bold mb-2">Modular Architecture</h3> | |
| <p class="text-sm text-slate-400">Each component (Loader, Splitter, Retriever, LLM) is isolated, allowing for swap-able logic and custom chains.</p> | |
| </div> | |
| <div class="glass-panel p-6 hover:bg-slate-800/50 transition-colors"> | |
| <div class="w-12 h-12 rounded-lg bg-green-500/10 flex items-center justify-center mb-4 text-green-400"> | |
| <i data-lucide="shield-check" size="24"></i> | |
| </div> | |
| <h3 class="text-lg font-bold mb-2">Context Grounding</h3> | |
| <p class="text-sm text-slate-400">Observe how retrieved chunks are injected into the LLM's prompt window to ensure factual accuracy.</p> | |
| </div> | |
| </div> | |
| </main> | |
| <footer class="border-t border-slate-800 mt-12 py-8 text-center"> | |
| <p class="text-slate-500 text-sm font-mono"> | |
| Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="text-cyan-400 hover:underline">anycoder</a> • Next-Gen AI Architecture | |
| </p> | |
| </footer> | |
| <script> | |
| // Initialize Lucide Icons | |
| lucide.createIcons(); | |
| // GSAP Animations | |
| gsap.registerPlugin(ScrollTrigger, Flip); | |
| // Entrance Animations | |
| gsap.from("header", { | |
| y: -50, | |
| opacity: 0, | |
| duration: 1, | |
| ease: "power3.out" | |
| }); | |
| gsap.from(".glass-panel", { | |
| y: 50, | |
| opacity: 0, | |
| duration: 0.8, | |
| stagger: 0.1, | |
| scrollTrigger: { | |
| trigger: ".glass-panel", | |
| start: "top 80%" | |
| } | |
| }); | |
| // --- INTERACTIVE ARCHITECTURE LOGIC --- | |
| const svg = document.getElementById('connection-svg'); | |
| const stage = document.getElementById('architecture-stage'); | |
| // Define connections: [startNodeId, endNodeId, color] | |
| const connections = [ | |
| { from: 'uploader-out', to: 'splitter-in', color: '#00f0ff' }, | |
| { from: 'splitter-out', to: 'embed-in', color: '#bc13fe' }, | |
| { from: 'embed-out', to: 'db-bottom', color: '#bc13fe' }, | |
| { from: 'query-out', to: 'db-top', color: '#00f0ff' }, | |
| { from: 'db-top', to: 'retriever-in', color: '#3b82f6' }, // Retrieval path | |
| { from: 'retriever-out', to: 'llm-in', color: '#3b82f6' }, | |
| { from: 'llm-in', to: 'output-in', color: '#0aff0a' } // Simplified path for visual | |
| ]; | |
| function getCenter(element) { | |
| const rect = element.getBoundingClientRect(); | |
| const stageRect = stage.getBoundingClientRect(); | |
| return { | |
| x: rect.left + rect.width / 2 - stageRect.left, | |
| y: rect.top + rect.height / 2 - stageRect.top | |
| }; | |
| } | |
| function drawConnections() { | |
| // Clear existing paths | |
| while (svg.firstChild) { | |
| if(svg.firstChild.tagName !== 'defs') svg.removeChild(svg.firstChild); | |
| else break; | |
| } | |
| // Keep defs | |
| const defs = svg.querySelector('defs'); | |
| svg.innerHTML = ''; | |
| svg.appendChild(defs); | |
| connections.forEach(conn => { | |
| const startEl = document.querySelector(`[data-id="${conn.from}"]`); | |
| const endEl = document.querySelector(`[data-id="${conn.to}"]`); | |
| if (!startEl || !endEl) return; | |
| const start = getCenter(startEl); | |
| const end = getCenter(endEl); | |
| // Create path | |
| const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); | |
| // Bezier Curve Logic | |
| const deltaX = end.x - start.x; | |
| const controlPoint1 = { x: start.x + deltaX * 0.5, y: start.y }; | |
| const controlPoint2 = { x: end.x - deltaX * 0.5, y: end.y }; | |
| // Adjust control points for vertical connections (like query to db) | |
| if (Math.abs(deltaX) < 50) { | |
| controlPoint1.x = start.x; controlPoint1.y = start.y + 50; | |
| controlPoint2.x = end.x; controlPoint2.y = end.y - 50; | |
| } | |
| const d = `M ${start.x} ${start.y} C ${controlPoint1.x} ${controlPoint1.y}, ${controlPoint2.x} ${controlPoint2.y}, ${end.x} ${end.y}`; | |
| path.setAttribute("d", d); | |
| path.setAttribute("stroke", conn.color); | |
| path.setAttribute("stroke-width", "2"); | |
| path.setAttribute("fill", "none"); | |
| path.setAttribute("class", "connector-path"); | |
| path.style.opacity = "0.3"; | |
| svg.appendChild(path); | |
| }); | |
| } | |
| // Draw initially and on resize | |
| window.addEventListener('load', drawConnections); | |
| window.addEventListener('resize', drawConnections); | |
| // --- SIMULATION LOGIC --- | |
| const runBtn = document.getElementById('run-btn'); | |
| const statusBadge = document.getElementById('status-badge'); | |
| const outputText = document.getElementById('final-output-text'); | |
| const queryInput = document.getElementById('query-input'); | |
| // Nodes for highlighting | |
| const nodes = { | |
| uploader: document.getElementById('node-uploader'), | |
| splitter: document.getElementById('node-splitter'), | |
| embedding: document.getElementById('node-embedding'), | |
| vectordb: document.getElementById('node-vectordb'), | |
| retriever: document.getElementById('node-retriever'), | |
| llm: document.getElementById('node-llm'), | |
| query: document.getElementById('node-query'), | |
| output: document.getElementById('node-output') | |
| }; | |
| function highlightNode(nodeId, duration = 1000) { | |
| const node = nodes[nodeId]; | |
| if(!node) return; | |
| node.classList.add('active-node'); | |
| // Specific color borders based on type | |
| if(nodeId === 'uploader' || nodeId === 'query') node.style.borderColor = 'var(--neon-blue)'; | |
| if(nodeId === 'splitter' || nodeId === 'embedding') node.style.borderColor = 'var(--neon-purple)'; | |
| if(nodeId === 'retriever') node.style.borderColor = 'var(--neon-blue)'; | |
| if(nodeId === 'llm' || nodeId === 'output') node.style.borderColor = 'var(--neon-green)'; | |
| setTimeout(() => { | |
| node.classList.remove('active-node'); | |
| node.style.borderColor = ''; | |
| }, duration); | |
| } | |
| function spawnParticle(startId, endId, color, speed = 1) { | |
| const startEl = document.querySelector(`[data-id="${startId}"]`); | |
| const endEl = document.querySelector(`[data-id="${endId}"]`); | |
| if(!startEl || !endEl) return; | |
| const start = getCenter(startEl); | |
| const end = getCenter(endEl); | |
| const p = document.createElement('div'); | |
| p.className = 'particle'; | |
| p.style.backgroundColor = color; | |
| stage.appendChild(p); | |
| const deltaX = end.x - start.x; | |
| const controlPoint1 = { x: start.x + deltaX * 0.5, y: start.y }; | |
| const controlPoint2 = { x: end.x - deltaX * 0.5, y: end.y }; | |
| if (Math.abs(deltaX) < 50) { | |
| controlPoint1.x = start.x; controlPoint1.y = start.y + 50; | |
| controlPoint2.x = end.x; controlPoint2.y = end.y - 50; | |
| } | |
| // GSAP Animation for particle along path | |
| const timeline = { x: [start.x, controlPoint1.x, controlPoint2.x, end.x], y: [start.y, controlPoint1.y, controlPoint2.y, end.y] }; | |
| gsap.to(p, { | |
| motionPath: { | |
| path: [{x: start.x, y: start.y}, {x: controlPoint1.x, y: controlPoint1.y}, {x: controlPoint2.x, y: controlPoint2.y}, {x: end.x, y: end.y}], | |
| curviness: 1.5 | |
| }, | |
| duration: 1.5 / speed, | |
| ease: "power1.inOut", | |
| onComplete: () => p.remove() | |
| }); | |
| gsap.to(p, { opacity: 1, duration: 0.2, yoyo: true, repeat: 1, delay: 0.2 }); | |
| } | |
| async function runSimulation() { | |
| // Reset | |
| outputText.innerText = ""; | |
| statusBadge.innerText = "PROCESSING"; | |
| statusBadge.className = "text-[10px] bg-cyan-900/50 text-cyan-400 px-2 py-1 rounded border border-cyan-500/30"; | |
| runBtn.disabled = true; | |
| runBtn.classList.add('opacity-50', 'cursor-not-allowed'); | |
| // 1. Query Input | |
| highlightNode('query'); | |
| await new Promise(r => setTimeout(r, 500)); | |
| // 2. Retrieval Phase (Query -> Vector DB) | |
| statusBadge.innerText = "RETRIEVING CONTEXT"; | |
| spawnParticle('query-out', 'db-top', '#00f0ff'); | |
| highlightNode('vectordb'); | |
| await new Promise(r => setTimeout(r, 1200)); | |
| // DB -> Retriever | |
| spawnParticle('db-top', 'retriever-in', '#3b82f6'); | |
| highlightNode('retriever'); | |
| await new Promise(r => setTimeout(r, 800)); | |
| // Retriever -> LLM | |
| spawnParticle('retriever-out', 'llm-in', '#3b82f6'); | |
| highlightNode('llm'); | |
| statusBadge.innerText = "GENERATING"; | |
| // 3. Simulated Typing Effect | |
| const response = "Based on the retrieved documents, a neural network functions by mimicking the human brain's interconnected neuron structure. It processes data through layers: an input layer receives signals, hidden layers perform computations via weighted connections, and an output layer delivers the final prediction. The system 'learns' by adjusting these weights during training to minimize error."; | |
| let i = 0; | |
| const typeInterval = setInterval(() => { | |
| outputText.innerText += response.charAt(i); | |
| i++; | |
| if (i > response.length - 1) { | |
| clearInterval(typeInterval); | |
| statusBadge.innerText = "COMPLETE"; | |
| statusBadge.className = "text-[10px] bg-green-900/50 text-green-400 px-2 py-1 rounded border border-green-500/30"; | |
| runBtn.disabled = false; | |
| runBtn.classList.remove('opacity-50', 'cursor-not-allowed'); | |
| highlightNode('output'); | |
| } | |
| }, 30); | |
| // 4. Ingestion Simulation (Running in background/parellel visually but delayed) | |
| setTimeout(() => { | |
| highlightNode('uploader'); | |
| setTimeout(() => { | |
| spawnParticle('uploader-out', 'splitter-in', '#00f0ff'); | |
| highlightNode('splitter'); | |
| setTimeout(() => { | |
| spawnParticle('splitter-out', 'embed-in', '#bc13fe'); | |
| highlightNode('embedding'); | |
| setTimeout(() => { | |
| spawnParticle('embed-out', 'db-bottom', '#bc13fe'); | |
| highlightNode('vectordb'); | |
| }, 800); | |
| }, 800); | |
| }, 800); | |
| }, 2000); | |
| } | |
| runBtn.addEventListener('click', runSimulation); | |
| // Add hover effects to nodes to show details (simple console log or tooltip could be added here) | |
| Object.values(nodes).forEach(node => { | |
| node.addEventListener('mouseenter', () => { | |
| gsap.to(node, { scale: 1.05, duration: 0.3 }); | |
| }); | |
| node.addEventListener('mouseleave', () => { | |
| gsap.to(node, { scale: 1, duration: 0.3 }); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |