from __future__ import annotations # index 0-5 = teachers (aligns with MODEL_COLORS[1:] in _fig.py) _TEACHER_COLORS = ["#7c3aed", "#06b6d4", "#f59e0b", "#34d399", "#f472b6", "#76b900"] def gate_html(gate_weights: list[float], teacher_names: list[str], ranked: bool = True) -> str: """Horizontal bar chart. ranked=False keeps teacher order fixed — used while streaming so bars animate in place instead of swapping rows.""" pairs = list(enumerate(zip(gate_weights, teacher_names))) if ranked: pairs.sort(key=lambda x: x[1][0], reverse=True) rows = [] for orig_idx, (w, name) in pairs: color = _TEACHER_COLORS[orig_idx % len(_TEACHER_COLORS)] bar_pct = int(w * 100) rows.append( f'
' f'{name}' f'
' f'
' f'
' f'{w:.2f}' f'
' ) return ( '
' '
' 'TEACHER INFLUENCE
' + "".join(rows) + "
" ) def task_html(gate_weights: list[float], teacher_names: list[str]) -> str: """Badge for argmax teacher + runner-up.""" best_idx = max(range(len(gate_weights)), key=lambda i: gate_weights[i]) second_idx = sorted(range(len(gate_weights)), key=lambda i: gate_weights[i])[-2] color = _TEACHER_COLORS[best_idx % len(_TEACHER_COLORS)] best = teacher_names[best_idx].upper() second = teacher_names[second_idx].upper() w2 = gate_weights[second_idx] n = len(teacher_names) return ( '
' '
' 'DOMINANT TEACHER
' '
' f'' f'{best}' f'' f'runner-up {second} · {w2:.2f}' f'
' f'
' f'gate picked this teacher for your prompt ({n} total)
' '
' ) def header_html(n_teachers: int = 6, backend: str = "torch") -> str: """App header with ∀ logo, wordmark, and status pills.""" def pill(color: str, dot_color: str, text: str, pulse: bool = False) -> str: dot_class = ' class="live-dot"' if pulse else '' return ( f'' f'' f'{text}' ) return ( '
' # Left: logo + title '
' '
' '' '
' '
' '
One for All
' '
multi-teacher soul distillation
' '
' # Right: pills '
' + pill("#06b6d4", "#06b6d4", "STUDENT · Qwen2.5-0.5B", pulse=True) + pill("#7c3aed", "#7c3aed", f"{n_teachers} TEACHERS") + pill("#f59e0b", "#f59e0b", "PATH B · GEOMETRY") + (pill("#76b900", "#76b900", "🦙 llama.cpp · GGUF") if backend == "llamacpp" else "") + '
' # Divider with glow '
' )