NoobNovel's picture
HF Space deployment: Attention Visualizer (FastAPI + React)
4e8e113
/* ── Design Tokens ──────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');
:root {
--bg-base: #080b14;
--bg-surface: #0d1120;
--bg-card: #111827;
--bg-glass: rgba(17, 24, 39, 0.72);
--bg-input: #161f32;
--border: rgba(99, 130, 255, 0.18);
--border-hover: rgba(99, 130, 255, 0.45);
--accent: #6366f1; /* indigo */
--accent-glow: rgba(99, 102, 241, 0.35);
--accent-2: #8b5cf6; /* violet */
--accent-3: #06b6d4; /* cyan */
--gold: #f59e0b;
--text-primary: #f0f4ff;
--text-secondary: #8b9ec7;
--text-muted: #4b5a7a;
--heat-0: #0d1120;
--heat-100: #f59e0b;
--radius-sm: 6px;
--radius-md: 12px;
--radius-lg: 20px;
--radius-xl: 28px;
--shadow-card: 0 4px 32px rgba(0,0,0,0.45), 0 1px 3px rgba(0,0,0,0.3);
--shadow-glow: 0 0 24px var(--accent-glow);
--transition: 0.22s cubic-bezier(0.4,0,0.2,1);
}
/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
font-family: 'Inter', system-ui, sans-serif;
background: var(--bg-base);
color: var(--text-primary);
min-height: 100vh;
overflow-x: hidden;
/* subtle grid pattern */
background-image:
linear-gradient(rgba(99,102,241,0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(99,102,241,0.03) 1px, transparent 1px);
background-size: 32px 32px;
}
/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }
/* ── Layout ───────────────────────────────────────────────────────────────── */
#root { min-height: 100vh; display: flex; flex-direction: column; }
.app-shell {
display: flex;
flex-direction: column;
min-height: 100vh;
max-width: 1440px;
margin: 0 auto;
width: 100%;
padding: 0 24px 48px;
}
/* ── Header ───────────────────────────────────────────────────────────────── */
.app-header {
display: flex;
align-items: center;
gap: 16px;
padding: 28px 0 20px;
border-bottom: 1px solid var(--border);
margin-bottom: 28px;
}
.app-logo {
width: 40px;
height: 40px;
border-radius: var(--radius-md);
background: linear-gradient(135deg, var(--accent), var(--accent-2));
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
box-shadow: var(--shadow-glow);
flex-shrink: 0;
}
.app-title {
font-size: 22px;
font-weight: 700;
background: linear-gradient(135deg, #fff 40%, var(--accent-3));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.app-subtitle {
font-size: 13px;
color: var(--text-secondary);
margin-top: 2px;
font-weight: 400;
}
.header-badge {
margin-left: auto;
font-size: 11px;
font-weight: 600;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--accent-3);
background: rgba(6,182,212,0.12);
border: 1px solid rgba(6,182,212,0.25);
padding: 4px 12px;
border-radius: 99px;
}
/* ── Main Grid ────────────────────────────────────────────────────────────── */
.main-grid {
display: grid;
grid-template-columns: 340px 1fr;
gap: 20px;
flex: 1;
}
@media (max-width: 900px) {
.main-grid { grid-template-columns: 1fr; }
}
/* ── Cards / Glass ────────────────────────────────────────────────────────── */
.card {
background: var(--bg-glass);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 24px;
box-shadow: var(--shadow-card);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.card-title {
font-size: 11px;
font-weight: 600;
letter-spacing: 0.1em;
text-transform: uppercase;
color: var(--text-secondary);
margin-bottom: 16px;
display: flex;
align-items: center;
gap: 8px;
}
.card-title::before {
content: '';
display: inline-block;
width: 3px;
height: 14px;
border-radius: 2px;
background: linear-gradient(var(--accent), var(--accent-2));
}
/* ── Left Panel ───────────────────────────────────────────────────────────── */
.left-panel {
display: flex;
flex-direction: column;
gap: 16px;
}
/* ── Text Input ───────────────────────────────────────────────────────────── */
.text-input-wrap textarea {
width: 100%;
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: var(--radius-md);
color: var(--text-primary);
font-family: 'Inter', sans-serif;
font-size: 14px;
line-height: 1.7;
padding: 14px 16px;
resize: vertical;
min-height: 120px;
outline: none;
transition: border-color var(--transition), box-shadow var(--transition);
}
.text-input-wrap textarea:focus {
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-glow);
}
.text-input-wrap textarea::placeholder { color: var(--text-muted); }
.char-count {
text-align: right;
font-size: 11px;
color: var(--text-muted);
margin-top: 6px;
font-variant-numeric: tabular-nums;
}
/* ── Analyze Button ───────────────────────────────────────────────────────── */
.btn-analyze {
width: 100%;
padding: 13px;
border: none;
border-radius: var(--radius-md);
font-family: 'Inter', sans-serif;
font-size: 14px;
font-weight: 600;
cursor: pointer;
background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
color: #fff;
letter-spacing: 0.02em;
transition: opacity var(--transition), transform var(--transition), box-shadow var(--transition);
box-shadow: 0 4px 16px var(--accent-glow);
position: relative;
overflow: hidden;
}
.btn-analyze::after {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(rgba(255,255,255,0.1), transparent);
opacity: 0;
transition: opacity var(--transition);
}
.btn-analyze:hover:not(:disabled)::after { opacity: 1; }
.btn-analyze:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 24px var(--accent-glow); }
.btn-analyze:active:not(:disabled) { transform: translateY(0); }
.btn-analyze:disabled { opacity: 0.5; cursor: not-allowed; }
/* ── Model Selector ───────────────────────────────────────────────────────── */
.model-cards {
display: flex;
flex-direction: column;
gap: 8px;
}
.model-card {
border: 1px solid var(--border);
border-radius: var(--radius-md);
padding: 12px 14px;
cursor: pointer;
transition: border-color var(--transition), background var(--transition), transform var(--transition);
background: var(--bg-input);
position: relative;
overflow: hidden;
}
.model-card.selected {
border-color: var(--accent);
background: rgba(99,102,241,0.08);
box-shadow: 0 0 0 1px var(--accent);
}
.model-card:hover:not(.selected) { border-color: var(--border-hover); transform: translateX(2px); }
.model-card-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 4px;
}
.model-card-label {
font-size: 13px;
font-weight: 600;
color: var(--text-primary);
}
.model-type-badge {
font-size: 10px;
font-weight: 600;
letter-spacing: 0.06em;
text-transform: uppercase;
padding: 2px 8px;
border-radius: 99px;
}
.model-type-badge.encoder {
background: rgba(99,102,241,0.15);
color: #818cf8;
border: 1px solid rgba(99,102,241,0.3);
}
.model-type-badge.decoder {
background: rgba(6,182,212,0.12);
color: #22d3ee;
border: 1px solid rgba(6,182,212,0.25);
}
.model-card-desc {
font-size: 11px;
color: var(--text-muted);
}
.model-card.selected .model-card-label { color: #a5b4fc; }
/* ── Layer/Head Controls ──────────────────────────────────────────────────── */
.lhc-sliders { display: flex; flex-direction: column; gap: 18px; }
.slider-group label {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
color: var(--text-secondary);
margin-bottom: 10px;
}
.slider-group label span {
font-family: 'JetBrains Mono', monospace;
font-size: 12px;
color: var(--accent-3);
background: rgba(6,182,212,0.1);
padding: 1px 8px;
border-radius: 4px;
}
input[type=range] {
-webkit-appearance: none;
width: 100%;
height: 4px;
border-radius: 99px;
background: var(--bg-input);
outline: none;
cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 18px;
height: 18px;
border-radius: 50%;
background: linear-gradient(135deg, var(--accent), var(--accent-2));
box-shadow: 0 0 8px var(--accent-glow);
cursor: pointer;
transition: transform var(--transition);
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }
.head-grid {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 6px;
margin-top: 8px;
}
.head-btn {
aspect-ratio: 1;
border: 1px solid var(--border);
border-radius: var(--radius-sm);
background: var(--bg-input);
color: var(--text-secondary);
font-size: 11px;
font-family: 'JetBrains Mono', monospace;
cursor: pointer;
transition: all var(--transition);
display: flex;
align-items: center;
justify-content: center;
padding: 0;
}
.head-btn:hover { border-color: var(--border-hover); color: var(--text-primary); }
.head-btn.active {
border-color: var(--accent);
background: rgba(99,102,241,0.2);
color: #a5b4fc;
box-shadow: 0 0 8px var(--accent-glow);
}
.avg-toggle {
width: 100%;
padding: 9px;
margin-top: 10px;
border: 1px solid var(--border);
border-radius: var(--radius-md);
background: transparent;
color: var(--text-secondary);
font-family: 'Inter', sans-serif;
font-size: 12px;
font-weight: 500;
cursor: pointer;
transition: all var(--transition);
}
.avg-toggle:hover { border-color: var(--accent-3); color: var(--accent-3); }
.avg-toggle.active {
background: rgba(6,182,212,0.1);
border-color: var(--accent-3);
color: var(--accent-3);
}
/* ── Right Panel ──────────────────────────────────────────────────────────── */
.right-panel {
display: flex;
flex-direction: column;
gap: 16px;
min-width: 0;
}
/* ── Token Row ────────────────────────────────────────────────────────────── */
.token-row-wrap {
display: flex;
flex-wrap: wrap;
gap: 6px;
align-items: center;
min-height: 40px;
}
.token-chip {
font-family: 'JetBrains Mono', monospace;
font-size: 12px;
padding: 5px 10px;
border-radius: var(--radius-sm);
border: 1px solid transparent;
cursor: pointer;
transition: all var(--transition);
white-space: nowrap;
user-select: none;
position: relative;
}
.token-chip:hover { transform: translateY(-2px); }
.token-chip.selected { border-color: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
/* ── Heatmap Panel ────────────────────────────────────────────────────────── */
.heatmap-container {
flex: 1;
min-height: 420px;
position: relative;
}
.heatmap-container .plotly-container {
width: 100% !important;
height: 100% !important;
min-height: 420px;
}
/* ── Info Panel ───────────────────────────────────────────────────────────── */
.info-panel {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 10px;
}
.info-stat {
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: var(--radius-md);
padding: 12px 16px;
display: flex;
flex-direction: column;
gap: 4px;
}
.info-stat-label {
font-size: 10px;
font-weight: 600;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--text-muted);
}
.info-stat-value {
font-family: 'JetBrains Mono', monospace;
font-size: 18px;
font-weight: 700;
color: var(--text-primary);
}
.info-stat-value.accent { color: var(--accent-3); }
/* ── Loading State ────────────────────────────────────────────────────────── */
.loading-overlay {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 16px;
padding: 60px 20px;
color: var(--text-secondary);
font-size: 14px;
}
.spinner {
width: 40px;
height: 40px;
border: 3px solid var(--border);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-model-name {
font-family: 'JetBrains Mono', monospace;
font-size: 12px;
color: var(--accent-3);
}
/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
padding: 60px 20px;
color: var(--text-muted);
text-align: center;
}
.empty-icon {
font-size: 48px;
opacity: 0.4;
animation: float 3s ease-in-out infinite;
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-6px); }
}
.empty-state h3 { font-size: 16px; color: var(--text-secondary); font-weight: 600; }
.empty-state p { font-size: 13px; line-height: 1.6; max-width: 280px; }
/* ── Error ────────────────────────────────────────────────────────────────── */
.error-banner {
background: rgba(239,68,68,0.1);
border: 1px solid rgba(239,68,68,0.3);
border-radius: var(--radius-md);
padding: 12px 16px;
font-size: 13px;
color: #fca5a5;
display: flex;
align-items: flex-start;
gap: 8px;
}
/* ── Subtle animations ─────────────────────────────────────────────────────── */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.35s ease forwards; }
/* ── Plotly dark overrides ─────────────────────────────────────────────────── */
.js-plotly-plot .plotly .modebar { background: transparent !important; }
.js-plotly-plot .plotly .modebar-btn path { fill: var(--text-muted) !important; }
.js-plotly-plot .plotly .modebar-btn:hover path { fill: var(--text-primary) !important; }