File size: 2,721 Bytes
6275299
 
38e41fd
 
 
6275299
 
 
38e41fd
6275299
38e41fd
6275299
 
38e41fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
title: Video Face Replace
emoji: 🎭
colorFrom: purple
colorTo: pink
sdk: gradio
sdk_version: 6.10.0
app_file: app.py
pinned: true
license: mit
short_description: Swap any face into any video using InsightFace + GFPGAN
---

# 🎭 Face Fusion β€” AI Video Face Swap

Swap any face into any video using state-of-the-art AI. Built on **InsightFace**, **inswapper_128**, and **GFPGAN**.

> ⚑ This is a **Kaggle notebook project** β€” run it there for full GPU-accelerated face swapping.
> The Gradio UI is embedded inside the notebook (Cell 4).

---

## ✨ What It Does

Upload a single clear photo of a face, point it at a YouTube video (or upload your own), and the pipeline replaces **every detected face** in the video with your source face β€” enhanced, sharpened, and re-merged with the original audio.

**Pipeline:**

```
Source Face Photo β†’ InsightFace Embedding
       ↓
Target Video (YouTube URL or upload)
       ↓
Per-frame: Face Detection β†’ Swap (inswapper_128) β†’ GFPGAN Enhancement
       ↓
Audio Merge (ffmpeg) β†’ Final MP4
```

---

## πŸš€ How to Run (Kaggle)

1. Open `Face_replace.ipynb` on [Kaggle](https://www.kaggle.com) with **GPU accelerator** (T4 or P100)
2. **Cell 1** β€” installs packages + downloads models (~1 min)
3. **Cell 2** β€” set source face path + YouTube URL, downloads & trims video
4. **Cell 3** β€” processes all frames β†’ outputs `face_swapped_output.mp4`
5. **Cell 4** β€” launches interactive Gradio UI

> Processes ~12 frames/second on T4 GPU

---

## 🧰 Tech Stack

| Component | Role |
|---|---|
| InsightFace `buffalo_l` | Face detection + recognition |
| `inswapper_128.onnx` | Neural face-swap model |
| GFPGAN v1.4 | Face restoration & enhancement |
| OpenCV | Frame-level video I/O |
| ffmpeg | Video codec + audio merge |
| yt-dlp | YouTube video download |
| Gradio | Interactive UI |
| ONNX Runtime GPU | GPU-accelerated inference |

---

## πŸ’‘ Tips for Best Results

- Use a **clear, front-facing photo** β€” no sunglasses or heavy shadows
- Keep target videos **under 30 seconds** for fast iteration
- Single-face videos give the cleanest results
- Enable GFPGAN (`ENABLE_ENHANCEMENT = True`) for sharper output

---

## ⚠️ Disclaimer

For **creative, educational, and research purposes only**.
Do not use to create deceptive, harmful, or non-consensual content.
Always obtain permission before using someone's likeness.

---

## πŸ™ Credits

- [deepinsight/insightface](https://github.com/deepinsight/insightface)
- [TencentARC/GFPGAN](https://github.com/TencentARC/GFPGAN)
- [ezioruan/inswapper_128.onnx](https://huggingface.co/ezioruan/inswapper_128.onnx)

---

*Made with ❀️ by [Aastha Malik](https://github.com/aastha-malik)*