diff options
| author | Johannes Medagbe <johanmedagbe@gmail.com> | 2026-09-21 10:03:20 +0000 |
|---|---|---|
| committer | Johannes Medagbe <johanmedagbe@gmail.com> | 2026-09-22 12:18:32 +0000 |
| commit | dce53892085c02c8571d8a6495e39c449294aa5f (patch) | |
| tree | ae64d32cc845d30ec2a4cc3514a23dc5683a09a1 /aisearch/src/web/templates/index.html | |
| download | genenetwork_ai_search-master.tar.gz | |
New: commit aisearch repo master
Diffstat (limited to 'aisearch/src/web/templates/index.html')
| -rw-r--r-- | aisearch/src/web/templates/index.html | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/aisearch/src/web/templates/index.html b/aisearch/src/web/templates/index.html new file mode 100644 index 0000000..02d61f1 --- /dev/null +++ b/aisearch/src/web/templates/index.html @@ -0,0 +1,233 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>GeneNetwork AI Search</title> + <script src="https://unpkg.com/htmx.org@2.0.8"></script> + <script src="https://unpkg.com/htmx-ext-sse@2.2.4/sse.js"></script> + <script src="https://unpkg.com/hyperscript.org@0.9.12"></script> + <link rel="stylesheet" + href="{{ url_for('static', filename='css/style.css') }}"> + </head> + <body> + <div class="header"> + <div class="header-logo">GN</div> + <div class="header-title">GeneNetwork AI Search</div> + </div> + <div class="chat-container" id="chat-container"> + <div class="empty-state" id="empty-state"> + <h1>GeneNetwork AI Search</h1> + <p>Ask natural language questions about genes, traits, and datasets</p> + <p style="font-size: 0.9em; color: #999;">Powered by Hybrid RAG + Agent</p> + <div class="examples"> + <button type="button" + class="example-btn" + _="on click set #search-input.value to 'What genes are associated with diabetes?' then call #search-input.focus()"> + What genes are associated with diabetes? + </button> + <button type="button" + class="example-btn" + _="on click set #search-input.value to 'Find datasets related to obesity' then call #search-input.focus()"> + Find datasets related to obesity + </button> + <button type="button" + class="example-btn" + _="on click set #search-input.value to 'How does the mosaic structure of BXD recombinant inbred mice genomes affect mapping resolution across generations?' then call #search-input.focus()"> + How does the mosaic structure of BXD recombinant inbred mice genomes affect mapping resolution across generations? + </button> + </div> + </div> + <!-- messages wrapper --> + <div id="messages"></div> + <!-- indicator sits after messages so it appears at the bottom --> + <div id="loading-indicator" class="message message-ai htmx-indicator"> + <div class="avatar">AI</div> + <div class="message-content"> + <div class="loading-message"> + <div class="loading-dots"> + <span></span><span></span><span></span> + </div> + <span>Searching GeneNetwork data...</span> + </div> + </div> + </div> + </div> + <div class="input-container"> + <form class="input-wrapper" + id="search-form" + hx-get="/search/stream-shell" + hx-target="#messages" + hx-swap="beforeend" + hx-indicator="#loading-indicator" + _="on htmx:beforeRequest + if no #search-input.value.trim() halt end + put 'none' into #empty-state's style.display + on htmx:afterRequest + put '' into #search-input.value + call #search-input.focus()"> + <div class="textarea-box"> + <textarea name="q" + id="search-input" + class="search-input" + placeholder="Ask a question about genes, traits, or datasets... (Shift+Enter for new line)" + rows="1" + autocomplete="off" + autofocus></textarea> + <button type="button" + class="clear-btn" + id="clear-btn" + title="Clear message" + aria-label="Clear message">×</button> + </div> + <button type="submit" + class="search-button" + id="search-btn" + aria-label="Send" + title="Send">↑</button> + <button type="button" + class="stop-button" + id="stop-btn" + aria-label="Stop generating" + title="Stop generating"> + <svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" aria-hidden="true"> + <rect x="6" y="6" width="12" height="12" rx="2" /> + </svg> + </button> + </form> + <div class="char-counter" id="char-counter">0 / 1000</div> + </div> + <button id="scroll-to-bottom" class="scroll-to-bottom-btn" title="Scroll to bottom">↓</button> + + <script type="text/hyperscript"> + def focusInput() + call #search-input.focus() + end + </script> + <script> + (function(){ + const chat = document.getElementById('chat-container'); + const btn = document.getElementById('scroll-to-bottom'); + const messages = document.getElementById('messages'); + if (!chat || !btn || !messages) return; + const THRESHOLD = 80; + let atBottom = true; + + function check() { + atBottom = chat.scrollHeight - chat.scrollTop <= chat.clientHeight + THRESHOLD; + btn.classList.toggle('visible', !atBottom); + } + + chat.addEventListener('scroll', check); + window.addEventListener('resize', check); + + new MutationObserver(function(muts) { + var hit = muts.some(function(m) { + return m.target.closest && m.target.closest('.stream-final-body'); + }); + if (!hit) return; + if (atBottom) chat.scrollTop = chat.scrollHeight; + else btn.classList.add('visible'); + }).observe(messages, { childList: true, subtree: true }); + + btn.addEventListener('click', function(){ + chat.scrollTop = chat.scrollHeight; + atBottom = true; + btn.classList.remove('visible'); + }); + })(); + </script> + <script> + (function(){ + const input = document.getElementById('search-input'); + const sendBtn = document.getElementById('search-btn'); + const stopBtn = document.getElementById('stop-btn'); + const clearBtn = document.getElementById('clear-btn'); + const charCounter = document.getElementById('char-counter'); + const messages = document.getElementById('messages'); + const form = document.getElementById('search-form'); + if (!input || !sendBtn || !stopBtn || !messages || !form) return; + const MAX_HEIGHT = 200; + const MAX_CHARS = 1000; + + function autoGrow() { + input.style.height = 'auto'; + var h = Math.min(input.scrollHeight, MAX_HEIGHT); + input.style.height = h + 'px'; + input.style.overflowY = input.scrollHeight > MAX_HEIGHT ? 'auto' : 'hidden'; + } + + function updateUI() { + var len = input.value.length; + if (charCounter) { + charCounter.textContent = len + ' / ' + MAX_CHARS; + charCounter.classList.remove('warning', 'caution'); + if (len > 900) charCounter.classList.add('warning'); + else if (len > 700) charCounter.classList.add('caution'); + } + if (clearBtn) clearBtn.style.display = len > 0 ? 'flex' : 'none'; + } + + function setStreaming(v) { + input.disabled = v; + sendBtn.style.display = v ? 'none' : 'flex'; + stopBtn.style.display = v ? 'flex' : 'none'; + if (!v) { + input.focus(); + autoGrow(); + updateUI(); + } + } + + window.onStreamEnd = function() { setStreaming(false); }; + + form.addEventListener('htmx:afterRequest', function(evt) { + if (evt.detail.successful) setStreaming(true); + setTimeout(function() { + autoGrow(); + updateUI(); + }, 0); + }); + + stopBtn.addEventListener('click', function() { + var lastMsg = messages.lastElementChild; + if (lastMsg) lastMsg.remove(); + setStreaming(false); + }); + + if (clearBtn) { + clearBtn.addEventListener('click', function() { + input.value = ''; + input.focus(); + autoGrow(); + updateUI(); + }); + } + + input.addEventListener('input', function() { + autoGrow(); + updateUI(); + }); + + input.addEventListener('keydown', function(e) { + if (e.key !== 'Enter') return; + if (e.shiftKey) return; + e.preventDefault(); + if (!input.disabled && input.value.trim()) { + form.requestSubmit(); + } + }); + + input.addEventListener('paste', function() { + setTimeout(function() { + autoGrow(); + updateUI(); + }, 0); + }); + + autoGrow(); + updateUI(); + })(); + </script> + </body> +</html> |
