def model_hyperlink(link, model_name): return f'{model_name}' def make_clickable_model(model_name): return model_hyperlink(f"https://huggingface.co/{model_name}", model_name) def styled_error(error): return f"
❌ {error}
" def styled_warning(warn): return f"
⚠️ {warn}
" def styled_message(message): return f"
✅ {message}
" def styled_loading(message: str, subtext: str = "This may take 1–2 minutes while layers are audited.", pct: int = 15) -> str: pct_val = max(0, min(100, int(pct))) return f"""
🔬
{message}
Please wait: {subtext}
{pct_val}%
""" def build_top_3_cards_html(top_records: list) -> str: if not top_records: return "" cards_html = "" for r in top_records[:3]: model_name = r.get("model_name", "Model") org = r.get("org", "Org") logo = model_name[0].upper() if model_name else "M" acc = r.get("factuality", 0.0) blind = r.get("blind_fraction", 0.0) score = r.get("composite_score", 0.0) run_id = r.get("run_id", "Unknown") date_str = r.get("date", "") cards_html += f"""

{model_name}

{org} · Click to Inspect 🔬
X-Ray Composite: {score:.1f} / 100
Factuality: {acc:.1f}% Layer C
Blind Manifold: {blind:.2f}% Layer B
""" return f"""
Top Audited Models (Click Any Card to Inspect)
{cards_html}
""" def render_audit_details_panel(cert: dict) -> str: if not cert: return """
🔬
No Model Selected

Select any model row from the leaderboard or click one of the Top 3 Cards above to inspect its audit certificate.

""" if cert.get("status") == "error": model_id = cert.get("config", {}).get("model_name", "Model") err_msg = cert.get("error_message", "Audit could not be completed.") return f"""
AUDIT ATTEMPT FAILED

{model_id}

Reason: {err_msg}
""" config = cert.get("config", {}) model_id = config.get("model_name", "Unknown Model") revision = str(config.get("model_sha", "main"))[:8] arch = config.get("architecture", "Unknown") params = config.get("params") or "N/A" comp = cert.get("composite", cert.get("risk", {})) score = comp.get("unvalidated_composite_score", comp.get("hallucination_potential", 0.0)) r_struct = comp.get("structural_risk", 0.0) r_behav = comp.get("behavioral_risk", 0.0) verdict = comp.get("verdict") if not verdict: verdict = "LOW RISK" if score < 25 else ("MODERATE RISK" if score < 55 else "HIGH RISK") risk_class = "risk-low" if score < 25 else ("risk-moderate" if score < 55 else "risk-high") spec = cert.get("spectral", {}) obs = cert.get("observer", cert.get("hso", {})) behav = cert.get("behavioral", {}) d_obs = obs.get("d", obs.get("observable_dim", 0)) raw_blind = obs.get("blind_fraction", 0.0) if isinstance(raw_blind, str): blind_frac = float(raw_blind.replace("%", "").strip() or 0.0) elif isinstance(raw_blind, (int, float)) and raw_blind <= 1.0: blind_frac = raw_blind * 100.0 else: blind_frac = float(raw_blind or 0.0) ratio = obs.get("token_to_dim_ratio", 0.0) sample_ok = obs.get("sample_adequate", True) raw_acc = behav.get("factual_accuracy", 0.0) if isinstance(raw_acc, str): acc = float(raw_acc.replace("%", "").strip() or 0.0) elif isinstance(raw_acc, (int, float)) and raw_acc <= 1.0: acc = raw_acc * 100.0 else: acc = float(raw_acc or 0.0) raw_stab = behav.get("paraphrase_fidelity", behav.get("paraphrase_stability", 0.0)) if isinstance(raw_stab, str): stab = float(raw_stab.replace("%", "").strip() or 0.0) elif isinstance(raw_stab, (int, float)) and raw_stab <= 1.0: stab = raw_stab * 100.0 else: stab = float(raw_stab or 0.0) warn_html = "" if not sample_ok: warn_html = f"
⚠️ Diagnostic Warning: Calibration Token/Dim ratio is {ratio:.2f}x. Layer B covariance is under-sampled. Blind quotient is provisional.
" return f"""
REAL AUDIT CERTIFICATE

{model_id}

{params}B Params · {arch} · SHA: {revision}
COMPOSITE (UNVALIDATED)
{score:.1f} / 100
{verdict}
{warn_html}
Layer A: Weight Spectra
Stable Rank (r_s): {spec.get('stable_rank_mean', 0)}
Effective Rank: {spec.get('effective_rank_mean', 0)}
Condition (κ): {spec.get('condition_number_mean', 0):,.1f}
Matrices Sampled: {spec.get('matrices_sampled', 0)}
Layer B: HSO Geometry
Observable Dim (d): {d_obs}
Blind Manifold (ker): {blind_frac:.2f}%
Token/Dim Ratio: {ratio:.2f}x
Structural Risk: {r_struct:.1f}
Layer C: Probes ({behav.get('n_probes', 0)})
Factual Accuracy: {acc:.1f}%
Paraphrase Stability: {stab:.1f}%
Correct Probes: {behav.get('correct_count', 0)}
Behavioral Risk: {r_behav:.1f}
"""