File size: 2,493 Bytes
2782c48
faa659d
7d3f27a
 
 
2782c48
b9f8b5d
2782c48
7d3f27a
2782c48
 
9b9f599
7d3f27a
 
 
 
 
 
 
 
 
 
f58e53b
7d3f27a
 
 
 
 
 
 
 
 
 
 
 
 
 
f58e53b
7d3f27a
 
 
f58e53b
 
 
 
 
 
 
 
 
 
 
 
7d3f27a
 
 
 
f58e53b
7d3f27a
f58e53b
7d3f27a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: Deepfake Detector
emoji: 🎬
colorFrom: red
colorTo: purple
sdk: gradio
app_file: detector.py
pinned: false
hardware: zero-gpu
---

# Deepfake Detector

Detects AI-generated (deepfake) videos using **V-JEPA 2.1 ViT-Giant** as a
frozen video encoder and a trained **AttentiveClassifier** probe on top.

Paste a public Instagram reel, TikTok, or direct `.mp4` URL.
The model runs sliding-window inference across the full video and reports
per-window fake probabilities alongside a final prediction.

## How it works

1. Video is downloaded via the **SaverAPI** HTTP API (CPU, no GPU quota used). A pool of up to 10 API keys is rotated automatically with sticky failover.
2. Frames are decoded and normalized with `decord` (CPU)
3. V-JEPA 2.1 encodes clips into patch token sequences (GPU)
4. AttentiveClassifier cross-attends over all tokens and outputs a fake probability (GPU)
5. Final score = max probability across all windows (max strategy)

## Required Space secrets

Set these in **Settings → Repository secrets**:

| Secret | Value |
|---|---|
| `HF_TOKEN` | Your HuggingFace access token |
| `ENCODER_REPO` | HF repo ID where `vjepa2_1_vitg_384.pt` is stored |
| `PROBE_REPO` | HF repo ID where `attentive_probe_optimized.pt` is stored |
| `SAVER_API_KEY_1``SAVER_API_KEY_10` | SaverAPI keys (one secret per key; unset ones are ignored) |

`ENCODER_REPO` and `PROBE_REPO` can point to the same private repo.

### Optional SaverAPI tuning secrets

| Secret | Default | Purpose |
|---|---|---|
| `SAVER_API_KEY_COOLDOWN_SEC` | `3600` | How long a failing key is skipped before being re-tested |
| `SAVER_API_LOOKUP_TIMEOUT_SEC` | `15` | Timeout for SaverAPI's JSON lookup |
| `SAVER_API_DOWNLOAD_TIMEOUT_SEC` | `60` | Timeout for the streamed byte pull |
| `SAVER_API_MAX_RETRIES_PER_REQUEST` | `3` | How many keys to try before failing a single user request |
| `SAVER_API_MAX_FILESIZE_MB` | `100` | Hard cap on downloaded video size |
| `SAVER_API_STARTUP_PROBE_URL` | _(unset)_ | A known-good video URL; if set, all keys are probed at Space boot |
| `SKIP_STARTUP_PROBE` | _(unset)_ | Set to `1` to skip the boot probe entirely |

## Files in this Space

| File | Purpose |
|---|---|
| `detector.py` | Main Gradio app + ZeroGPU integration + SaverAPI client + key rotator |
| `inference_core.py` | Model architecture + video windowing (unchanged from training) |
| `requirements.txt` | Python deps (`decord`, `requests`) |
| `packages.txt` | System dep (`ffmpeg`) |