Spaces:
Sleeping
Sleeping
Upload chat.html
Browse files- frontend/chat.html +166 -1
frontend/chat.html
CHANGED
|
@@ -130,6 +130,36 @@
|
|
| 130 |
.session-loading.visible{display:flex;}
|
| 131 |
.spin{width:18px;height:18px;border:2px solid var(--border);border-top-color:var(--teal);border-radius:50%;animation:spin 0.7s linear infinite;}
|
| 132 |
@keyframes spin{to{transform:rotate(360deg);}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
@media(max-width:768px){
|
| 134 |
header{padding:10px 12px;gap:8px;}
|
| 135 |
.header-text h1{font-size:15px;}
|
|
@@ -152,6 +182,36 @@
|
|
| 152 |
header{padding:8px 10px;}
|
| 153 |
}
|
| 154 |
/* Mobile input fixes β prevent iOS zoom on focus */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
@media(max-width:768px){
|
| 156 |
.msg-input{font-size:16px !important;}
|
| 157 |
.send-btn{width:44px;height:44px;}
|
|
@@ -210,7 +270,6 @@
|
|
| 210 |
</div>
|
| 211 |
<div class="header-right">
|
| 212 |
<span class="model-badge">π€ Agentic AI</span>
|
| 213 |
-
<a href="/" class="nav-link">Classifier</a>
|
| 214 |
<div class="user-pill" onclick="toggleUserMenu()">
|
| 215 |
<div class="user-avatar" id="headerAvatar">?</div>
|
| 216 |
<span class="user-name" id="headerUsername">β¦</span>
|
|
@@ -234,6 +293,35 @@
|
|
| 234 |
</div>
|
| 235 |
</div>
|
| 236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
<div class="chat-wrapper">
|
| 238 |
<div class="disclaimer-bar">Clinical decision support only β not a diagnosis</div>
|
| 239 |
<div class="chat-container">
|
|
@@ -419,6 +507,9 @@ async function loadSession(uuid) {
|
|
| 419 |
if (data.messages && data.messages.length) {
|
| 420 |
document.getElementById('welcome').style.display='none';
|
| 421 |
data.messages.forEach(m => addBubble(m.role==='human'?'user':'ai', m.content, m.created_at));
|
|
|
|
|
|
|
|
|
|
| 422 |
}
|
| 423 |
} catch(e) { loading.classList.remove('visible'); }
|
| 424 |
document.getElementById('sessionLabel').textContent = `Session: ${uuid.slice(0,8)}β¦`;
|
|
@@ -447,6 +538,7 @@ async function sendMessage() {
|
|
| 447 |
document.getElementById('sendBtn').disabled = true;
|
| 448 |
document.getElementById('welcome').style.display='none';
|
| 449 |
addBubble('user', text, new Date().toISOString());
|
|
|
|
| 450 |
const typing = addTyping();
|
| 451 |
try {
|
| 452 |
const res = await authFetch('/chat', {
|
|
@@ -474,6 +566,7 @@ async function sendMessage() {
|
|
| 474 |
function newChat() {
|
| 475 |
sessionId=null;
|
| 476 |
clearMessages();
|
|
|
|
| 477 |
document.getElementById('sessionLabel').textContent='';
|
| 478 |
document.querySelectorAll('.session-item').forEach(el => el.classList.remove('active'));
|
| 479 |
loadSessionList();
|
|
@@ -548,7 +641,79 @@ function escapeHtml(t) { return t.replace(/&/g,'&').replace(/</g,'<').rep
|
|
| 548 |
function authFetch(path, opts={}) {
|
| 549 |
return fetch(`${API}${path}`, { ...opts, headers:{ ...(opts.headers||{}), 'Authorization':`Bearer ${authToken}` } });
|
| 550 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
|
| 553 |
</script>
|
| 554 |
</body>
|
|
|
|
| 130 |
.session-loading.visible{display:flex;}
|
| 131 |
.spin{width:18px;height:18px;border:2px solid var(--border);border-top-color:var(--teal);border-radius:50%;animation:spin 0.7s linear infinite;}
|
| 132 |
@keyframes spin{to{transform:rotate(360deg);}}
|
| 133 |
+
/* ββ RISK PANEL βββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 134 |
+
#riskPanel{width:270px;background:#F8F5F0;border-left:1px solid var(--border);display:flex;flex-direction:column;flex-shrink:0;transition:width 0.22s ease,opacity 0.22s;overflow:hidden;}
|
| 135 |
+
#riskPanel.hidden{width:0;opacity:0;pointer-events:none;}
|
| 136 |
+
.rp-header{padding:13px 16px 10px;border-bottom:1px solid var(--border);display:flex;align-items:center;justify-content:space-between;}
|
| 137 |
+
.rp-header span{font-size:11px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:0.6px;}
|
| 138 |
+
.rp-close{background:none;border:none;color:var(--muted);cursor:pointer;font-size:16px;padding:0 2px;line-height:1;}
|
| 139 |
+
.rp-body{flex:1;overflow-y:auto;padding:14px;}
|
| 140 |
+
.rp-body::-webkit-scrollbar{width:4px;}
|
| 141 |
+
.rp-body::-webkit-scrollbar-thumb{background:var(--border);border-radius:2px;}
|
| 142 |
+
.rp-idle{text-align:center;padding:32px 12px;font-size:12px;color:var(--muted);line-height:1.8;}
|
| 143 |
+
.rp-idle .idle-icon{font-size:30px;margin-bottom:10px;}
|
| 144 |
+
|
| 145 |
+
/* tier badge */
|
| 146 |
+
.rp-tier{text-align:center;padding:12px 0 8px;}
|
| 147 |
+
.rp-tier-label{font-size:16px;font-weight:700;margin-bottom:4px;}
|
| 148 |
+
.rp-tier-sub{font-size:11px;color:var(--muted);}
|
| 149 |
+
.tier-color-LOW{color:#065F46;}
|
| 150 |
+
.tier-color-WATCH{color:#5B21B6;}
|
| 151 |
+
.tier-color-MODERATE{color:#1E40AF;}
|
| 152 |
+
.tier-color-HIGH{color:#92400E;}
|
| 153 |
+
.tier-color-CRITICAL_EMERGENCY{color:#B91C1C;}
|
| 154 |
+
|
| 155 |
+
/* sections */
|
| 156 |
+
.rp-section-title{font-size:10px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:0.5px;margin:12px 0 6px;}
|
| 157 |
+
.feature-list{display:flex;flex-direction:column;gap:4px;}
|
| 158 |
+
.feature-chip{font-size:12px;padding:5px 10px;border-radius:7px;background:#fff;border:0.5px solid var(--border);color:var(--text);line-height:1.4;border-left:3px solid var(--teal);}
|
| 159 |
+
.workup-list{display:flex;flex-direction:column;gap:4px;}
|
| 160 |
+
.workup-item{font-size:11px;color:var(--text);padding:4px 0 4px 10px;border-left:2px solid var(--border);line-height:1.5;}
|
| 161 |
+
.action-box{background:#fff;border:0.5px solid var(--border);border-radius:9px;padding:10px 12px;font-size:12px;color:var(--text);line-height:1.6;margin-top:10px;}
|
| 162 |
+
|
| 163 |
@media(max-width:768px){
|
| 164 |
header{padding:10px 12px;gap:8px;}
|
| 165 |
.header-text h1{font-size:15px;}
|
|
|
|
| 182 |
header{padding:8px 10px;}
|
| 183 |
}
|
| 184 |
/* Mobile input fixes β prevent iOS zoom on focus */
|
| 185 |
+
/* ββ RISK PANEL βββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 186 |
+
#riskPanel{width:270px;background:#F8F5F0;border-left:1px solid var(--border);display:flex;flex-direction:column;flex-shrink:0;transition:width 0.22s ease,opacity 0.22s;overflow:hidden;}
|
| 187 |
+
#riskPanel.hidden{width:0;opacity:0;pointer-events:none;}
|
| 188 |
+
.rp-header{padding:13px 16px 10px;border-bottom:1px solid var(--border);display:flex;align-items:center;justify-content:space-between;}
|
| 189 |
+
.rp-header span{font-size:11px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:0.6px;}
|
| 190 |
+
.rp-close{background:none;border:none;color:var(--muted);cursor:pointer;font-size:16px;padding:0 2px;line-height:1;}
|
| 191 |
+
.rp-body{flex:1;overflow-y:auto;padding:14px;}
|
| 192 |
+
.rp-body::-webkit-scrollbar{width:4px;}
|
| 193 |
+
.rp-body::-webkit-scrollbar-thumb{background:var(--border);border-radius:2px;}
|
| 194 |
+
.rp-idle{text-align:center;padding:32px 12px;font-size:12px;color:var(--muted);line-height:1.8;}
|
| 195 |
+
.rp-idle .idle-icon{font-size:30px;margin-bottom:10px;}
|
| 196 |
+
|
| 197 |
+
/* tier badge */
|
| 198 |
+
.rp-tier{text-align:center;padding:12px 0 8px;}
|
| 199 |
+
.rp-tier-label{font-size:16px;font-weight:700;margin-bottom:4px;}
|
| 200 |
+
.rp-tier-sub{font-size:11px;color:var(--muted);}
|
| 201 |
+
.tier-color-LOW{color:#065F46;}
|
| 202 |
+
.tier-color-WATCH{color:#5B21B6;}
|
| 203 |
+
.tier-color-MODERATE{color:#1E40AF;}
|
| 204 |
+
.tier-color-HIGH{color:#92400E;}
|
| 205 |
+
.tier-color-CRITICAL_EMERGENCY{color:#B91C1C;}
|
| 206 |
+
|
| 207 |
+
/* sections */
|
| 208 |
+
.rp-section-title{font-size:10px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:0.5px;margin:12px 0 6px;}
|
| 209 |
+
.feature-list{display:flex;flex-direction:column;gap:4px;}
|
| 210 |
+
.feature-chip{font-size:12px;padding:5px 10px;border-radius:7px;background:#fff;border:0.5px solid var(--border);color:var(--text);line-height:1.4;border-left:3px solid var(--teal);}
|
| 211 |
+
.workup-list{display:flex;flex-direction:column;gap:4px;}
|
| 212 |
+
.workup-item{font-size:11px;color:var(--text);padding:4px 0 4px 10px;border-left:2px solid var(--border);line-height:1.5;}
|
| 213 |
+
.action-box{background:#fff;border:0.5px solid var(--border);border-radius:9px;padding:10px 12px;font-size:12px;color:var(--text);line-height:1.6;margin-top:10px;}
|
| 214 |
+
|
| 215 |
@media(max-width:768px){
|
| 216 |
.msg-input{font-size:16px !important;}
|
| 217 |
.send-btn{width:44px;height:44px;}
|
|
|
|
| 270 |
</div>
|
| 271 |
<div class="header-right">
|
| 272 |
<span class="model-badge">π€ Agentic AI</span>
|
|
|
|
| 273 |
<div class="user-pill" onclick="toggleUserMenu()">
|
| 274 |
<div class="user-avatar" id="headerAvatar">?</div>
|
| 275 |
<span class="user-name" id="headerUsername">β¦</span>
|
|
|
|
| 293 |
</div>
|
| 294 |
</div>
|
| 295 |
|
| 296 |
+
<!-- RISK PANEL -->
|
| 297 |
+
<div id="riskPanel" class="hidden">
|
| 298 |
+
<div class="rp-header">
|
| 299 |
+
<span>MS Risk Analysis</span>
|
| 300 |
+
<button class="rp-close" onclick="closeRiskPanel()" title="Close">β</button>
|
| 301 |
+
</div>
|
| 302 |
+
<div class="rp-body" id="riskBody">
|
| 303 |
+
<div class="rp-idle" id="riskIdle">
|
| 304 |
+
<div class="idle-icon">π§ </div>
|
| 305 |
+
Describe your symptoms and the risk analysis will appear here automatically.
|
| 306 |
+
</div>
|
| 307 |
+
<div id="riskContent" style="display:none;">
|
| 308 |
+
<div class="rp-tier" id="rpTier">
|
| 309 |
+
<div class="rp-tier-label" id="rpTierLabel"></div>
|
| 310 |
+
<div class="rp-tier-sub" id="rpTierSub"></div>
|
| 311 |
+
</div>
|
| 312 |
+
<div id="rpFeaturesSection" style="display:none;">
|
| 313 |
+
<div class="rp-section-title">Detected Symptoms</div>
|
| 314 |
+
<div class="feature-list" id="rpFeatureList"></div>
|
| 315 |
+
</div>
|
| 316 |
+
<div id="rpWorkupSection" style="display:none;">
|
| 317 |
+
<div class="rp-section-title">Recommended Workup</div>
|
| 318 |
+
<div class="workup-list" id="rpWorkupList"></div>
|
| 319 |
+
</div>
|
| 320 |
+
<div class="action-box" id="rpActionBox" style="display:none;"></div>
|
| 321 |
+
</div>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
|
| 325 |
<div class="chat-wrapper">
|
| 326 |
<div class="disclaimer-bar">Clinical decision support only β not a diagnosis</div>
|
| 327 |
<div class="chat-container">
|
|
|
|
| 507 |
if (data.messages && data.messages.length) {
|
| 508 |
document.getElementById('welcome').style.display='none';
|
| 509 |
data.messages.forEach(m => addBubble(m.role==='human'?'user':'ai', m.content, m.created_at));
|
| 510 |
+
resetRiskPanel();
|
| 511 |
+
const humanText = data.messages.filter(m=>m.role==='human').map(m=>m.content).join(' ');
|
| 512 |
+
if (humanText.trim().length > 8) scheduleRiskUpdate(humanText);
|
| 513 |
}
|
| 514 |
} catch(e) { loading.classList.remove('visible'); }
|
| 515 |
document.getElementById('sessionLabel').textContent = `Session: ${uuid.slice(0,8)}β¦`;
|
|
|
|
| 538 |
document.getElementById('sendBtn').disabled = true;
|
| 539 |
document.getElementById('welcome').style.display='none';
|
| 540 |
addBubble('user', text, new Date().toISOString());
|
| 541 |
+
scheduleRiskUpdate(text);
|
| 542 |
const typing = addTyping();
|
| 543 |
try {
|
| 544 |
const res = await authFetch('/chat', {
|
|
|
|
| 566 |
function newChat() {
|
| 567 |
sessionId=null;
|
| 568 |
clearMessages();
|
| 569 |
+
resetRiskPanel();
|
| 570 |
document.getElementById('sessionLabel').textContent='';
|
| 571 |
document.querySelectorAll('.session-item').forEach(el => el.classList.remove('active'));
|
| 572 |
loadSessionList();
|
|
|
|
| 641 |
function authFetch(path, opts={}) {
|
| 642 |
return fetch(`${API}${path}`, { ...opts, headers:{ ...(opts.headers||{}), 'Authorization':`Bearer ${authToken}` } });
|
| 643 |
}
|
| 644 |
+
// ββ Live Risk Panel ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 645 |
+
let _riskDebounce = null;
|
| 646 |
+
let _riskText = '';
|
| 647 |
+
|
| 648 |
+
const TIER_COLORS = {
|
| 649 |
+
LOW: '#065F46',
|
| 650 |
+
WATCH: '#5B21B6',
|
| 651 |
+
MODERATE: '#1E40AF',
|
| 652 |
+
HIGH: '#92400E',
|
| 653 |
+
CRITICAL_EMERGENCY: '#B91C1C',
|
| 654 |
+
};
|
| 655 |
+
|
| 656 |
+
function closeRiskPanel() {
|
| 657 |
+
document.getElementById('riskPanel').classList.add('hidden');
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
function resetRiskPanel() {
|
| 661 |
+
_riskText = '';
|
| 662 |
+
document.getElementById('riskPanel').classList.add('hidden');
|
| 663 |
+
document.getElementById('riskIdle').style.display = 'block';
|
| 664 |
+
document.getElementById('riskContent').style.display = 'none';
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
function scheduleRiskUpdate(text) {
|
| 668 |
+
if (!text || text.trim().length < 8) return;
|
| 669 |
+
if (!_riskText.includes(text)) _riskText += ' ' + text;
|
| 670 |
+
clearTimeout(_riskDebounce);
|
| 671 |
+
_riskDebounce = setTimeout(() => _fetchRisk(_riskText.trim()), 900);
|
| 672 |
+
}
|
| 673 |
+
|
| 674 |
+
async function _fetchRisk(text) {
|
| 675 |
+
try {
|
| 676 |
+
const res = await fetch(`${API}/analyze`, {
|
| 677 |
+
method: 'POST',
|
| 678 |
+
headers: { 'Content-Type': 'application/json' },
|
| 679 |
+
body: JSON.stringify({ text }),
|
| 680 |
+
});
|
| 681 |
+
if (!res.ok) return;
|
| 682 |
+
renderRiskPanel(await res.json());
|
| 683 |
+
} catch(e) { /* silent */ }
|
| 684 |
+
}
|
| 685 |
|
| 686 |
+
function renderRiskPanel(data) {
|
| 687 |
+
const tier = data.tier || 'LOW';
|
| 688 |
+
const color = TIER_COLORS[tier] || TIER_COLORS.LOW;
|
| 689 |
+
document.getElementById('riskPanel').classList.remove('hidden');
|
| 690 |
+
document.getElementById('riskIdle').style.display = 'none';
|
| 691 |
+
document.getElementById('riskContent').style.display = 'block';
|
| 692 |
+
const lbl = document.getElementById('rpTierLabel');
|
| 693 |
+
lbl.textContent = data.tier_label || tier;
|
| 694 |
+
lbl.className = 'rp-tier-label tier-color-' + tier;
|
| 695 |
+
document.getElementById('rpTierSub').textContent = data.tier_subtitle || '';
|
| 696 |
+
const feats = data.features || [];
|
| 697 |
+
const fSec = document.getElementById('rpFeaturesSection');
|
| 698 |
+
if (feats.length) {
|
| 699 |
+
fSec.style.display = 'block';
|
| 700 |
+
document.getElementById('rpFeatureList').innerHTML =
|
| 701 |
+
feats.map(f => `<div class="feature-chip">${escapeHtml(f.label)}</div>`).join('');
|
| 702 |
+
} else { fSec.style.display = 'none'; }
|
| 703 |
+
const workup = data.workup || [];
|
| 704 |
+
const wSec = document.getElementById('rpWorkupSection');
|
| 705 |
+
if (workup.length) {
|
| 706 |
+
wSec.style.display = 'block';
|
| 707 |
+
document.getElementById('rpWorkupList').innerHTML =
|
| 708 |
+
workup.map(w => `<div class="workup-item">${escapeHtml(w)}</div>`).join('');
|
| 709 |
+
} else { wSec.style.display = 'none'; }
|
| 710 |
+
const aBox = document.getElementById('rpActionBox');
|
| 711 |
+
if (data.action && tier !== 'LOW') {
|
| 712 |
+
aBox.style.display = 'block';
|
| 713 |
+
aBox.style.borderColor = color;
|
| 714 |
+
aBox.innerHTML = `<strong>Recommended action:</strong><br>${escapeHtml(data.action)}`;
|
| 715 |
+
} else { aBox.style.display = 'none'; }
|
| 716 |
+
}
|
| 717 |
|
| 718 |
</script>
|
| 719 |
</body>
|