Spaces:
Running
Running
Commit Β·
38e41fd
1
Parent(s): 6275299
Add face swap notebook and README
Browse files- Face_replace.ipynb +0 -0
- README.md +85 -6
Face_replace.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
README.md
CHANGED
|
@@ -1,14 +1,93 @@
|
|
| 1 |
---
|
| 2 |
title: Video Face Replace
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.10.0
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
| 10 |
license: mit
|
| 11 |
-
short_description: Swap any face into any video using InsightFace + GFPGAN
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Video Face Replace
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.10.0
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
license: mit
|
| 11 |
+
short_description: Swap any face into any video using InsightFace + GFPGAN
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# π Face Fusion β AI Video Face Swap
|
| 15 |
+
|
| 16 |
+
Swap any face into any video using state-of-the-art AI. Built on **InsightFace**, **inswapper_128**, and **GFPGAN**.
|
| 17 |
+
|
| 18 |
+
> β‘ This is a **Kaggle notebook project** β run it there for full GPU-accelerated face swapping.
|
| 19 |
+
> The Gradio UI is embedded inside the notebook (Cell 4).
|
| 20 |
+
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
## β¨ What It Does
|
| 24 |
+
|
| 25 |
+
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.
|
| 26 |
+
|
| 27 |
+
**Pipeline:**
|
| 28 |
+
|
| 29 |
+
```
|
| 30 |
+
Source Face Photo β InsightFace Embedding
|
| 31 |
+
β
|
| 32 |
+
Target Video (YouTube URL or upload)
|
| 33 |
+
β
|
| 34 |
+
Per-frame: Face Detection β Swap (inswapper_128) β GFPGAN Enhancement
|
| 35 |
+
β
|
| 36 |
+
Audio Merge (ffmpeg) β Final MP4
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
+
## π How to Run (Kaggle)
|
| 42 |
+
|
| 43 |
+
1. Open `Face_replace.ipynb` on [Kaggle](https://www.kaggle.com) with **GPU accelerator** (T4 or P100)
|
| 44 |
+
2. **Cell 1** β installs packages + downloads models (~1 min)
|
| 45 |
+
3. **Cell 2** β set source face path + YouTube URL, downloads & trims video
|
| 46 |
+
4. **Cell 3** β processes all frames β outputs `face_swapped_output.mp4`
|
| 47 |
+
5. **Cell 4** β launches interactive Gradio UI
|
| 48 |
+
|
| 49 |
+
> Processes ~12 frames/second on T4 GPU
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
## π§° Tech Stack
|
| 54 |
+
|
| 55 |
+
| Component | Role |
|
| 56 |
+
|---|---|
|
| 57 |
+
| InsightFace `buffalo_l` | Face detection + recognition |
|
| 58 |
+
| `inswapper_128.onnx` | Neural face-swap model |
|
| 59 |
+
| GFPGAN v1.4 | Face restoration & enhancement |
|
| 60 |
+
| OpenCV | Frame-level video I/O |
|
| 61 |
+
| ffmpeg | Video codec + audio merge |
|
| 62 |
+
| yt-dlp | YouTube video download |
|
| 63 |
+
| Gradio | Interactive UI |
|
| 64 |
+
| ONNX Runtime GPU | GPU-accelerated inference |
|
| 65 |
+
|
| 66 |
+
---
|
| 67 |
+
|
| 68 |
+
## π‘ Tips for Best Results
|
| 69 |
+
|
| 70 |
+
- Use a **clear, front-facing photo** β no sunglasses or heavy shadows
|
| 71 |
+
- Keep target videos **under 30 seconds** for fast iteration
|
| 72 |
+
- Single-face videos give the cleanest results
|
| 73 |
+
- Enable GFPGAN (`ENABLE_ENHANCEMENT = True`) for sharper output
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## β οΈ Disclaimer
|
| 78 |
+
|
| 79 |
+
For **creative, educational, and research purposes only**.
|
| 80 |
+
Do not use to create deceptive, harmful, or non-consensual content.
|
| 81 |
+
Always obtain permission before using someone's likeness.
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## π Credits
|
| 86 |
+
|
| 87 |
+
- [deepinsight/insightface](https://github.com/deepinsight/insightface)
|
| 88 |
+
- [TencentARC/GFPGAN](https://github.com/TencentARC/GFPGAN)
|
| 89 |
+
- [ezioruan/inswapper_128.onnx](https://huggingface.co/ezioruan/inswapper_128.onnx)
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
*Made with β€οΈ by [Aastha Malik](https://github.com/aastha-malik)*
|