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