"""Sanity check: feed a few REAL and FAKE clips from jay15k to /api/detect and report each detector's prediction. If the newly-trained checkpoints are loaded, Nes2Net + SONAR + BiCrossMamba + VoiceRadar should be sharp. """ import sys, random, httpx from pathlib import Path API = "http://127.0.0.1:8000" ROOT = Path(r"E:\sem_8\audio-deepfake-detector\data\jay15k\deepfake_audio_dataset_jay15k") def main(): rng = random.Random(7) real_files = list((ROOT / "real").glob("*.wav")) fake_files = list((ROOT / "fake").glob("*.wav")) rng.shuffle(real_files); rng.shuffle(fake_files) pick = real_files[:3] + fake_files[:3] print(f"{'file':<32} {'label':<5} {'verdict':<10} {'P(fake)':<8} | per-detector pred/conf") print("-" * 130) correct = 0 total = 0 for f in pick: label = "real" if "real" in f.parent.name else "fake" with open(f, "rb") as fh: r = httpx.post(f"{API}/api/detect", files={"audio_file": (f.name, fh.read(), "audio/wav")}, data={"return_features": "false"}, timeout=120) if r.status_code != 200: print(f"{f.name:<32} ERROR {r.status_code}: {r.text[:80]}") continue body = r.json() ev = body["ensemble_verdict"] total += 1 if ev["prediction"] == label: correct += 1 cells = [] for mid in ["nes2net", "sonar", "bicrossmamba_st", "voiceradar", "holi_antispoof", "lf_hf_physics", "melodymachine", "motheecreator"]: res = body["results"].get(mid, {}) cells.append(f"{mid[:4]}={res.get('prediction','?')[:1]}/{res.get('confidence',0):.2f}") print(f"{f.name:<32} {label:<5} {ev['prediction']:<10} {ev.get('fake_probability',0):<8.3f} | " + " ".join(cells)) print(f"\nEnsemble accuracy on 6 jay15k clips: {correct}/{total}") return 0 if __name__ == "__main__": sys.exit(main())