video-face-replace / README.md
aastha-malik's picture
Add face swap notebook and README
38e41fd

A newer version of the Gradio SDK is available: 6.14.0

Upgrade
metadata
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 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


Made with ❀️ by Aastha Malik