import json from pathlib import Path import gradio as gr import pandas as pd DATA_PATH = Path(__file__).parent / "proof_data.json" def load_data(): with open(DATA_PATH, "r", encoding="utf-8") as f: return json.load(f) DATA = load_data() def format_module_table(): rows = [] for item in DATA["public_proof"]["dataset_modules"]: rows.append({ "module": item["module"], "decision": item["decision"], "status": item["status"], "omega": item["omega"] if item["omega"] is not None else "—", "note": item["note"], }) return pd.DataFrame(rows) def format_failed_apps(): rows = [] for item in DATA["deploy_dashboard"]["failed_apps"]: rows.append({ "app": item["name"], "status": item["status"], "recommended_action": item["recommended_action"], }) return pd.DataFrame(rows) def format_healthy_apps(): return pd.DataFrame({"healthy_apps": DATA["deploy_dashboard"]["healthy_apps"]}) def compute_status_badges(): summary = DATA["deploy_dashboard"]["summary"] thresholds = DATA["public_proof"]["thresholds"] ledger = DATA["public_proof"]["ledger"] md = f""" ### Estado público do sistema - **Apps monitorados:** {summary["total_apps"]} - **Deploys saudáveis:** {summary["deployed"]} - **Deploys falhos:** {summary["failed"]} - **Ψ mínimo:** {thresholds["psi_min"]} - **CVaR máximo:** {thresholds["cvar_max"]} - **Ω para PASS:** {thresholds["omega_pass"]} - **Ledger:** {ledger["type"]} - **Replay:** {ledger["replay"]} - **Receipt:** {ledger["receipt"]} """ return md def verify_sample(psi, theta_ms, cvar, pole): theta_hat = 1.0 / (1.0 + theta_ms / 100.0) omega = 0.4 * psi + 0.3 * theta_hat + 0.2 * (1.0 - cvar) + 0.1 * pole reasons = [] if psi < DATA["public_proof"]["thresholds"]["psi_min"]: reasons.append("psi_below_threshold") if cvar > DATA["public_proof"]["thresholds"]["cvar_max"]: reasons.append("cvar_above_threshold") status = "PASS" if reasons: status = "BLOCK" elif omega < DATA["public_proof"]["thresholds"]["omega_pass"]: status = "CONDITIONAL" return { "psi": round(psi, 6), "theta_ms": round(theta_ms, 6), "theta_hat": round(theta_hat, 6), "cvar": round(cvar, 6), "pole": int(pole), "omega": round(omega, 6), "decision": status, "reasons": reasons or ["admissible"], } CUSTOM_CSS = """ :root { --mv-bg: #0a0f1f; --mv-card: #11172a; --mv-card-2: #151d35; --mv-text: #f4f7ff; --mv-muted: #b7c3e0; --mv-accent: #7c5cff; --mv-accent-2: #00d0ff; --mv-ok: #16c784; --mv-warn: #ffb020; --mv-bad: #ff5d7a; } .gradio-container { background: radial-gradient(circle at top left, rgba(124,92,255,0.18), transparent 22%), radial-gradient(circle at top right, rgba(0,208,255,0.12), transparent 24%), linear-gradient(180deg, #070b16 0%, #0a0f1f 100%); color: var(--mv-text); } .mv-hero { padding: 24px 8px 8px 8px; } .mv-hero h1 { font-size: 46px; margin: 0 0 8px 0; line-height: 1.05; } .mv-sub { color: var(--mv-muted); font-size: 17px; max-width: 900px; } .mv-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 18px; } .mv-card { background: linear-gradient(180deg, var(--mv-card), var(--mv-card-2)); border: 1px solid rgba(255,255,255,0.08); border-radius: 18px; padding: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.24); } .mv-label { color: var(--mv-muted); font-size: 13px; margin-bottom: 6px; } .mv-value { font-size: 28px; font-weight: 700; } .mv-chip { display: inline-block; padding: 6px 10px; border-radius: 999px; margin-right: 8px; font-size: 12px; font-weight: 600; } .mv-ok { background: rgba(22,199,132,0.12); color: #7bf0b9; } .mv-warn { background: rgba(255,176,32,0.12); color: #ffd073; } .mv-bad { background: rgba(255,93,122,0.12); color: #ff9fb1; } @media (max-width: 960px) { .mv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } } @media (max-width: 640px) { .mv-grid { grid-template-columns: 1fr; } .mv-hero h1 { font-size: 34px; } } """ summary = DATA["deploy_dashboard"]["summary"] hero_html = f"""