"""Test the app.py WaveRep integration end-to-end via predict_image video path.""" import os import sys import base64 import json from pathlib import Path project_root = Path(__file__).parent sys.path.insert(0, str(project_root)) sys.path.insert(0, str(project_root / 'sdk')) # Test a real video (should be REAL via WaveRep) real_video = str(project_root / 'real_videos' / 'video_2026-07-10_12-23-49.mp4') # Test a fake video (Pika - WaveRep should detect SYNTHETIC/FAKE) fake_video = 'D:/pika/pika/-_hbPLsZvvo_19_25.mp4' print("=" * 70) print("app.py WaveRep Integration Test") print("=" * 70) # The `spaces` package is a ZeroGPU HF dependency not installed locally. # Mock it so app.py can be imported for testing. import types _spaces = types.ModuleType("spaces") def _gpu_decorator(fn=None, *args, **kwargs): if fn is None: return lambda f: f return fn _spaces.GPU = _gpu_decorator sys.modules["spaces"] = _spaces # Import app (this triggers the module-level gr.Blocks but demo.launch() only # runs under __main__, so importing it as a module is safe). import importlib.util spec = importlib.util.spec_from_file_location('app', project_root / 'app.py') app_module = importlib.util.module_from_spec(spec) sys.modules['app'] = app_module spec.loader.exec_module(app_module) for label, path in [("REAL video", real_video), ("FAKE Pika", fake_video)]: if not os.path.exists(path): print(f"\n[{label}] MISSING: {path}") continue print(f"\n[{label}] {os.path.basename(path)}") with open(path, 'rb') as f: video_b64 = base64.b64encode(f.read()).decode() result_json = app_module.predict_image(video_b64, 0.5, "video") result = json.loads(result_json) print(f" verdict: {result.get('verdict')}") print(f" fake_probability: {result.get('fake_probability')}") print(f" confidence: {result.get('confidence')}") print(f" threshold: {result.get('threshold')}") print(f" model: {result.get('model')}") assert 'verdict' in result, "Missing verdict" assert 'fake_probability' in result, "Missing fake_probability" assert 'threshold' in result, "Missing threshold" assert 'model' in result, "Missing model" print("\n" + "=" * 70) print("ALL RESPONSE FIELDS PRESENT ✅") print("=" * 70)