llm-dictionary / static /stats.html
ranga galla
Upload static/stats.html with huggingface_hub
4387c3c verified
Raw History Blame Contribute Delete
11.2 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LLM Dictionary β€” Usage Dashboard</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg: #f8fafc; --card: #fff; --text: #0f172a; --muted: #64748b;
--accent: #2563eb; --accent-light: #dbeafe; --border: #e2e8f0;
--green: #059669; --green-bg: #ecfdf5;
--orange: #d97706; --orange-bg: #fffbeb;
--purple: #7c3aed; --purple-bg: #f5f3ff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
.container { max-width: 900px; margin: 0 auto; padding: 2rem 1.5rem; }
header { margin-bottom: 2rem; }
header h1 { font-size: 1.8rem; font-weight: 700; }
header p { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }
.back-link { color: var(--accent); text-decoration: none; font-size: 0.85rem; display: inline-block; margin-bottom: 1rem; }
.back-link:hover { text-decoration: underline; }
/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.kpi-card {
background: var(--card); border: 1px solid var(--border); border-radius: 12px;
padding: 1.25rem; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.kpi-card .kpi-value { font-size: 2rem; font-weight: 700; }
.kpi-card .kpi-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.25rem; }
.kpi-card.blue .kpi-value { color: var(--accent); }
.kpi-card.green .kpi-value { color: var(--green); }
.kpi-card.orange .kpi-value { color: var(--orange); }
.kpi-card.purple .kpi-value { color: var(--purple); }
/* Sections */
.section { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.section h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; }
/* Bar chart */
.bar-chart { display: flex; flex-direction: column; gap: 0.5rem; }
.bar-row { display: flex; align-items: center; gap: 0.75rem; }
.bar-label { font-size: 0.85rem; min-width: 100px; text-align: right; color: var(--text); font-weight: 500; }
.bar-track { flex: 1; height: 28px; background: #f1f5f9; border-radius: 6px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; border-radius: 6px; transition: width 0.5s ease; display: flex; align-items: center; padding-left: 0.5rem; }
.bar-fill span { font-size: 0.75rem; font-weight: 600; color: white; }
.bar-fill.blue { background: var(--accent); }
.bar-fill.green { background: var(--green); }
.bar-fill.orange { background: var(--orange); }
.bar-fill.purple { background: var(--purple); }
/* Timeline */
.timeline-chart { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding-top: 1rem; }
.timeline-bar { flex: 1; background: var(--accent-light); border-radius: 3px 3px 0 0; min-width: 8px; transition: height 0.3s ease; position: relative; }
.timeline-bar:hover { background: var(--accent); }
.timeline-bar:hover .timeline-tooltip { display: block; }
.timeline-tooltip {
display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
background: var(--text); color: white; padding: 0.25rem 0.5rem; border-radius: 4px;
font-size: 0.7rem; white-space: nowrap; margin-bottom: 4px;
}
/* Recent lookups table */
.recent-table { width: 100%; border-collapse: collapse; }
.recent-table th { text-align: left; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 0.5rem 0.75rem; border-bottom: 2px solid var(--border); }
.recent-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.recent-table tr:last-child td { border-bottom: none; }
.lang-badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 10px; font-size: 0.75rem; font-weight: 500; }
.lang-badge.english { background: var(--accent-light); color: var(--accent); }
.lang-badge.telugu { background: var(--green-bg); color: var(--green); }
.lang-badge.hindi { background: var(--orange-bg); color: var(--orange); }
.lang-badge.sanskrit { background: var(--purple-bg); color: var(--purple); }
.loading-msg { text-align: center; color: var(--muted); padding: 3rem; }
.auto-refresh { font-size: 0.75rem; color: var(--muted); }
@media (max-width: 600px) {
.container { padding: 1rem; }
.kpi-grid { grid-template-columns: 1fr 1fr; }
.bar-label { min-width: 70px; font-size: 0.8rem; }
}
</style>
</head>
<body>
<div class="container">
<a href="/" class="back-link">← Back to Dictionary</a>
<header>
<h1>πŸ“Š Usage Dashboard</h1>
<p>Real-time analytics for LLM Dictionary <span class="auto-refresh">(refreshes every 15s)</span></p>
</header>
<div id="content"><p class="loading-msg">Loading analytics...</p></div>
</div>
<script>
const LANG_COLORS = { english: 'blue', telugu: 'green', hindi: 'orange', sanskrit: 'purple' };
async function loadStats() {
try {
const resp = await fetch('/api/stats');
if (!resp.ok) throw new Error('Failed');
const data = await resp.json();
render(data);
} catch (e) {
document.getElementById('content').innerHTML = '<p class="loading-msg">Could not load analytics.</p>';
}
}
function render(d) {
const langCount = Object.keys(d.by_language).length;
const topWord = d.top_words.length ? d.top_words[0].word : 'β€”';
const uptime = timeSince(d.started_at);
let html = '';
// KPIs
html += `<div class="kpi-grid">
<div class="kpi-card blue"><div class="kpi-value">${d.total_lookups}</div><div class="kpi-label">Total Lookups</div></div>
<div class="kpi-card green"><div class="kpi-value">${langCount}</div><div class="kpi-label">Languages Used</div></div>
<div class="kpi-card orange"><div class="kpi-value">${esc(topWord)}</div><div class="kpi-label">Most Searched</div></div>
<div class="kpi-card purple"><div class="kpi-value">${uptime}</div><div class="kpi-label">Uptime</div></div>
</div>`;
// Language breakdown
if (Object.keys(d.by_language).length) {
const maxLang = Math.max(...Object.values(d.by_language));
html += `<div class="section"><h2>🌐 Lookups by Language</h2><div class="bar-chart">`;
for (const [lang, count] of Object.entries(d.by_language).sort((a, b) => b[1] - a[1])) {
const pct = maxLang ? (count / maxLang) * 100 : 0;
const color = LANG_COLORS[lang] || 'blue';
html += `<div class="bar-row">
<span class="bar-label">${esc(lang)}</span>
<div class="bar-track"><div class="bar-fill ${color}" style="width:${Math.max(pct, 5)}%"><span>${count}</span></div></div>
</div>`;
}
html += `</div></div>`;
}
// Hourly timeline
if (d.hourly.length) {
const maxH = Math.max(...d.hourly.map(h => h.count));
html += `<div class="section"><h2>πŸ“ˆ Lookups Over Time</h2><div class="timeline-chart">`;
for (const h of d.hourly) {
const pct = maxH ? (h.count / maxH) * 100 : 0;
html += `<div class="timeline-bar" style="height:${Math.max(pct, 4)}%">
<div class="timeline-tooltip">${h.hour} β€” ${h.count} lookups</div>
</div>`;
}
html += `</div></div>`;
}
// Top words
if (d.top_words.length) {
const maxW = d.top_words[0].count;
html += `<div class="section"><h2>πŸ”€ Top Searched Words</h2><div class="bar-chart">`;
for (const w of d.top_words.slice(0, 10)) {
const pct = maxW ? (w.count / maxW) * 100 : 0;
html += `<div class="bar-row">
<span class="bar-label">${esc(w.word)}</span>
<div class="bar-track"><div class="bar-fill blue" style="width:${Math.max(pct, 5)}%"><span>${w.count}</span></div></div>
</div>`;
}
html += `</div></div>`;
}
// Recent lookups
if (d.recent.length) {
html += `<div class="section"><h2>πŸ• Recent Lookups</h2><table class="recent-table">
<thead><tr><th>Word</th><th>Language</th><th>Time</th></tr></thead><tbody>`;
for (const r of d.recent) {
const color = LANG_COLORS[r.language] || 'english';
const time = new Date(r.time).toLocaleTimeString();
html += `<tr>
<td><strong>${esc(r.word)}</strong></td>
<td><span class="lang-badge ${color}">${esc(r.language)}</span></td>
<td style="color:var(--muted);font-size:0.85rem">${time}</td>
</tr>`;
}
html += `</tbody></table></div>`;
}
if (!d.total_lookups) {
html += `<div class="section" style="text-align:center;color:var(--muted);padding:2rem;">
<p style="font-size:2rem;">πŸ“­</p>
<p>No lookups yet. Go search some words!</p>
<a href="/" style="color:var(--accent);">← Go to Dictionary</a>
</div>`;
}
document.getElementById('content').innerHTML = html;
}
function esc(t) { const d = document.createElement('div'); d.textContent = t; return d.innerHTML; }
function timeSince(iso) {
const ms = Date.now() - new Date(iso).getTime();
const mins = Math.floor(ms / 60000);
if (mins < 60) return `${mins}m`;
const hrs = Math.floor(mins / 60);
if (hrs < 24) return `${hrs}h ${mins % 60}m`;
return `${Math.floor(hrs / 24)}d ${hrs % 24}h`;
}
loadStats();
setInterval(loadStats, 15000);
</script>
</body>
</html>