Spaces:
Sleeping
Sleeping
Download src/components/AuditVerificationPanel.tsx from vooom/NewsAnalyze: direct link, hf CLI and curl.
- Browser
- Download file 7.12 kB
-
https://huggingface.co/spaces/vooom/NewsAnalyze/resolve/main/src/components/AuditVerificationPanel.tsx
- Command line
-
hf download hf://spaces/vooom/NewsAnalyze/src/components/AuditVerificationPanel.tsx
-
curl -L -o AuditVerificationPanel.tsx https://huggingface.co/spaces/vooom/NewsAnalyze/resolve/main/src/components/AuditVerificationPanel.tsx
7.12 kB
| import React from "react"; | |
| import { MacroStrategyReport } from "../contracts/report_schema.js"; | |
| import { ShieldCheck, ShieldAlert, CheckCircle2, XCircle, Download } from "lucide-react"; | |
| import { useLanguage } from "../context/LanguageContext.js"; | |
| interface AuditVerificationPanelProps { | |
| report?: MacroStrategyReport | null; | |
| } | |
| export const AuditVerificationPanel: React.FC<AuditVerificationPanelProps> = ({ report }) => { | |
| const { language, t } = useLanguage(); | |
| const isAr = language === "ar"; | |
| const handleExportJson = () => { | |
| if (!report) return; | |
| const blob = new Blob([JSON.stringify(report, null, 2)], { type: "application/json" }); | |
| const url = URL.createObjectURL(blob); | |
| const a = document.createElement("a"); | |
| a.href = url; | |
| a.download = `GEO_STRAT_REPORT_${report.country_iso3}_${Date.now()}.json`; | |
| a.click(); | |
| URL.revokeObjectURL(url); | |
| }; | |
| const audit = report?.audit_verification; | |
| const checks = audit | |
| ? [ | |
| { | |
| ok: audit.zero_ungrounded_numbers, | |
| title: t.audit.zeroUngrounded, | |
| detail: audit.zero_ungrounded_numbers | |
| ? isAr ? "كل الأرقام غير البديهية تظهر في المصادر أو البيانات أو نتائج المحاكاة." : "Every non-trivial number appears in the sources, data inputs or simulation output." | |
| : `${isAr ? "أرقام غير موجودة في السياق" : "Not found in the context"}: ${audit.ungrounded_numbers?.join(", ") || ""}`, | |
| }, | |
| { | |
| ok: audit.citation_integrity_verified, | |
| title: t.audit.citationIntegrity, | |
| detail: audit.citation_integrity_verified | |
| ? isAr ? "كل معرف مستشهد به موجود في المصادر المسترجعة." : "Every cited id is in the retrieved source set." | |
| : `${isAr ? "معرفات غير معروفة" : "Unknown ids"}: ${audit.unknown_citations?.join(", ") || ""}`, | |
| }, | |
| { | |
| ok: audit.sandbox_id_matched, | |
| title: t.audit.sandboxVerification, | |
| detail: report?.sandbox_execution_id || (isAr ? "لم تُجرَ محاكاة" : "No simulation run"), | |
| }, | |
| { | |
| ok: Boolean(audit.probability_sum_valid ?? true), | |
| title: t.audit.probabilitySum, | |
| detail: report?.scenarios.map((s) => `${s.scenario_type}: ${s.probability_pct ?? "n/a"}`).join(" · ") || "", | |
| }, | |
| ] | |
| : []; | |
| return ( | |
| <div className="space-y-6 text-slate-100"> | |
| <div className="bg-slate-900 border border-slate-800 rounded-xl p-6 shadow-xl"> | |
| <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-4 border-b border-slate-800 pb-3"> | |
| <div className="flex items-center gap-3"> | |
| <div className="w-8 h-8 rounded-lg bg-sky-500/20 text-sky-400 flex items-center justify-center shrink-0"> | |
| <ShieldCheck className="w-5 h-5" /> | |
| </div> | |
| <div> | |
| <h1 className="text-base sm:text-lg font-bold text-white font-display">{t.audit.title}</h1> | |
| <p className="text-xs text-slate-400">{t.audit.subtitle}</p> | |
| </div> | |
| </div> | |
| <button | |
| onClick={handleExportJson} | |
| disabled={!report} | |
| className="px-3.5 py-2 bg-sky-500 hover:bg-sky-400 text-slate-950 font-bold text-xs rounded transition-all flex items-center justify-center gap-1.5 disabled:opacity-50 shrink-0 cursor-pointer" | |
| > | |
| <Download className="w-3.5 h-3.5" /> | |
| <span>{isAr ? "تصدير التقرير JSON" : "Export report JSON"}</span> | |
| </button> | |
| </div> | |
| {report && audit ? ( | |
| <div className="space-y-6"> | |
| <div | |
| className={`p-4 rounded-xl border flex items-center gap-3 ${ | |
| audit.passed ? "bg-emerald-950/50 border-emerald-800/80" : "bg-amber-950/40 border-amber-800/80" | |
| }`} | |
| > | |
| {audit.passed ? <CheckCircle2 className="w-6 h-6 text-emerald-400 shrink-0" /> : <ShieldAlert className="w-6 h-6 text-amber-400 shrink-0" />} | |
| <div> | |
| <h3 className={`text-sm font-bold font-display ${audit.passed ? "text-emerald-300" : "text-amber-300"}`}> | |
| {audit.passed | |
| ? isAr ? "اجتاز التدقيق" : "Audit passed" | |
| : isAr ? "رصد التدقيق محتوى غير موثق في التقرير" : "Audit flagged unsourced content in this report"} | |
| </h3> | |
| <p className="text-xs text-slate-400 mt-0.5"> | |
| {isAr ? "تم التحقق من مطابقة جميع مؤشرات المخرجات المباشرة مع السياق الموثق." : "All report parameters verified against grounding context."} | |
| </p> | |
| </div> | |
| </div> | |
| <div className="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| {checks.map((c) => ( | |
| <div key={c.title} className="p-4 bg-slate-950/80 rounded-xl border border-slate-800"> | |
| <div className="flex items-center gap-2 text-xs font-bold text-slate-200 font-mono mb-2"> | |
| {c.ok ? <CheckCircle2 className="w-4 h-4 text-emerald-400" /> : <XCircle className="w-4 h-4 text-amber-400" />} | |
| {c.title} | |
| </div> | |
| <p className="text-xs text-slate-400 leading-relaxed break-words">{c.detail}</p> | |
| </div> | |
| ))} | |
| </div> | |
| <div className="bg-slate-950 p-4 rounded-xl border border-slate-800 font-mono text-xs"> | |
| <div className="text-slate-400 font-bold mb-2">{isAr ? "سجل التدقيق" : "Audit log"}</div> | |
| <ul className="space-y-1 text-[11px] text-sky-300"> | |
| {(audit.log || []).map((line: string, i: number) => ( | |
| <li key={i}>{line}</li> | |
| ))} | |
| </ul> | |
| </div> | |
| <p className="text-[11px] text-slate-500 leading-relaxed"> | |
| {isAr | |
| ? "يتحقق التدقيق من أن الأرقام والمراجع مستمدة من السياق المقدَّم للنموذج، ولا يتحقق من صحة الاستنتاجات النوعية. الأعداد الصغيرة (حتى 10) والسنوات مستثناة." | |
| : "The audit checks that numbers and citations come from the context given to the model; it does not verify qualitative conclusions. Small counts (up to 10) and calendar years are exempt."} | |
| </p> | |
| </div> | |
| ) : ( | |
| <div className="p-12 text-center text-xs font-mono text-slate-500 bg-slate-950/60 rounded-xl border border-slate-800/80"> | |
| {isAr | |
| ? "لا يوجد تقرير نشط حالياً. نفّذ توقعاً في تبويب 'منصة التوقعات' لعرض نتائج التدقيق." | |
| : "No active report. Run a forecast in the Forecast Workbench tab to see its audit results."} | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| }; | |