Spaces:
Runtime error
A newer version of the Gradio SDK is available:
6.2.0
title: FaceSwapLite
emoji: π
colorFrom: purple
colorTo: red
sdk: gradio
sdk_version: 4.44.1
app_file: app.py
pinned: false
license: mit
π FaceSwapLite π
Professional AI-Powered Face Swapping for Videos with Advanced Quality Enhancements
Transform faces in videos with state-of-the-art AI models and professional-grade post-processing.
β¨ Features
Core Technology
- InsightFace: Industry-leading face detection and recognition
- INSwapper: High-quality face swapping with 128-dimensional embeddings
- SCRFD: Fast and accurate face detection
- ArcFace: Robust face recognition and matching
οΏ½ NEW: Professional Quality Enhancements
GFPGAN Face Restoration
- Automatically enhances swapped faces
- Fixes artifacts and blur
- Improves skin texture and details
- Maintains natural appearance
Advanced Post-Processing
- Smart Color Correction: Matches lighting and skin tone automatically
- Temporal Smoothing: Eliminates flickering and frame jitter
- Detail Preservation: Maintains sharpness with intelligent sharpening
- Aggressive Face Tracking: Stable swaps during fast motion and occlusions
Anti-Flickering Technology
- Frame-by-frame face tracking with IOU matching
- Occlusion tolerance (handles objects passing in front of faces)
- Cached swap results for stability during detection failures
- Adaptive confidence thresholds based on tracking history
π Quick Start
Simple Mode (Recommended)
- Upload your target video
- Upload ONE source face image (the face you want to insert)
- Click "Start processing"
- Download your result!
The app automatically replaces the first/main face in the video.
Advanced Mode
- Upload your target video
- Upload Target Face (specific face to replace from video)
- Upload Source Face (new face to insert)
- Adjust threshold if needed (default 0.5 works best)
- Click "Start processing"
π¨ Quality Enhancement Pipeline
Original Video Frame
β
Face Detection (SCRFD)
β
Face Recognition (ArcFace)
β
Face Swap (INSwapper 128)
β
GFPGAN Enhancement β
NEW
β
Color Correction
β
Detail Sharpening
β
Temporal Smoothing
β
Professional Output
π Quick Start
Online Usage
Visit the Hugging Face Space to use the application directly in your browser.
Local Installation
- Clone the repository
git clone https://huggingface.co/spaces/minhho/FaceSwapLite-1.0
cd FaceSwapLite-1.0
- Install dependencies
pip install -r requirements.txt
Download the face swapping model
- Download
inswapper_128.onnxfrom InsightFace Model Zoo - Place it in the root directory
- Download
Run the application
python app.py
π Usage
Web Interface
- Upload a target video (MP4 format)
- For each face you want to swap:
- Upload the target face from the video (face to replace)
- Upload the source face (replacement face)
- Adjust the transparency slider (0.0-1.0, default: 0.2)
- Click "β³ Start processing"
- Download the result video
Command Line
python script.py --video path/to/video.mp4 --face path/to/target_face.jpg,path/to/source_face.jpg,0.2
Arguments:
--video: Path to the target video--face: Face swap configuration (can be used multiple times)- Format:
target_face,source_face,threshold
- Format:
--force_cpu: Force CPU execution (optional)--colab_performance: Optimize for Google Colab (optional)
βοΈ Configuration
Execution Modes
The application automatically detects and uses the best available execution provider:
- CPU Mode: Default fallback, works on all systems
- CUDA Mode: NVIDIA GPU acceleration (recommended for best performance)
- CoreML Mode: Apple Silicon optimization
- TensorRT Mode: Advanced NVIDIA GPU optimization
Performance Tips
- For faster processing, use a CUDA-compatible GPU
- Reduce video resolution for quicker processing
- Process shorter video segments for testing
- On Colab, use the
--colab_performanceflag
π οΈ Technical Details
Architecture
- Face Detection: SCRFD (Sample and Computation Redistributed Face Detection)
- Face Recognition: ArcFace with ResNet-50 backbone
- Face Swapping: INSwapper model (128x128)
- Backend: ONNX Runtime for optimized inference
Requirements
- Python 3.8+
- FFmpeg (for video processing)
- 8GB+ RAM recommended
- GPU with 4GB+ VRAM (optional, for faster processing)
π Project Structure
FaceSwapLite/
βββ app.py # Gradio web interface
βββ refacer.py # Core face swapping logic
βββ script.py # Command-line interface
βββ requirements.txt # Python dependencies
βββ inswapper_128.onnx # Face swapping model
βββ recognition/ # Face detection and recognition modules
β βββ scrfd.py # Face detector
β βββ arcface_onnx.py # Face recognition
β βββ ...
βββ out/ # Output directory for processed videos
π€ Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- InsightFace for the face analysis models
- ONNX Runtime for efficient model inference
- Gradio for the web interface
β οΈ Disclaimer
This software is provided for educational and research purposes only. Please use responsibly and ethically. Do not use this tool for creating misleading or harmful content. Always obtain proper consent before swapping someone's face.
π§ Contact
For questions or support, please open an issue on the GitHub repository.
Note: Make sure you have the required model files (inswapper_128.onnx) before running the application. The InsightFace models will be automatically downloaded on first run.