| --- |
| 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)* |
| |