A user-friendly desktop application for swapping faces in images and videos, built with Python and Gradio. This tool supports single or batch processing for both images and videos, with built-in options for enhancing the quality of the final output.
- Image-to-Image Swapping: Swap a source face onto one or multiple target images.
- Video-to-Video Swapping: Swap a source face into every frame of a target video.
- Batch Processing: Process multiple target images or videos in a single run.
- Quality Enhancement: Optional modes to improve the realism and detail of swapped faces.
- Audio Preservation: Automatically retains the original audio track in processed videos.
- User-Friendly Interface: Simple, tab-based UI for easy operation.
Before you begin, you must have the following software installed on your system.
- Python: Version 3.9 or newer. You can download it from python.org.
- FFmpeg: (CRITICAL FOR VIDEO) This is required to process videos and add audio to the output.
- Windows: Download a build from gyan.dev (the
essentialsbuild is fine). Unzip it, and you must add thebinfolder to your system's PATH environment variable. - macOS: Use Homebrew:
brew install ffmpeg - Linux (Debian/Ubuntu):
sudo apt update && sudo apt install ffmpeg
- Windows: Download a build from gyan.dev (the
- (Optional but Recommended) NVIDIA GPU with CUDA: For significant processing speed-up, an NVIDIA GPU is highly recommended.
- Ensure you have the latest NVIDIA drivers installed.
- Install the CUDA Toolkit. The installation guide below assumes CUDA 12.1, but you should use the command that matches your installed CUDA version.
Follow these steps carefully in your terminal or command prompt. Do not skip steps.
Clone this project to your local machine.
git clone https://github.com/ExoFi-Labs/Nexface.git
cd nexfaceThis is a crucial step to avoid conflicts with other Python projects.
# Create the virtual environment
python -m venv venv
# Activate it
# On Windows:
.\venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activateYou will know it's active when you see (venv) at the beginning of your command prompt line.
This is the most common point of failure. Install these manually based on your hardware.
A) For NVIDIA GPU Users (Highly Recommended):
Run the following command. This example is for CUDA 12.1. Visit the PyTorch website to get the correct command for your specific CUDA version if it's different.
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
pip install onnxruntime-gpuB) For CPU-Only Users:
If you do not have an NVIDIA GPU, the application will be much slower, but it will work.
pip install torch torchvision torchaudio
pip install onnxruntimeNow that the core libraries are installed, you can install the rest from the requirements.txt file.
pip install -r requirements.txtThe installation is now complete!
With your virtual environment still active, run the following command:
python app.pyThis will start the Gradio web server. A local URL (like http://127.0.0.1:7860) will be displayed in your terminal. Open this URL in your web browser to use the application.
- Select a Tab: Choose between
Image-to-Image,Video-to-Video, orBatch Video Processing. - Upload Source Face: In the left panel, upload a clear, front-facing image of the face you want to use.
- Upload Target(s): In the right panel, upload the image(s) or video(s) you want to swap the face onto.
- Set Options:
Enhance Output Faces: Recommended for a higher quality result.High Quality Mode: Slower, but pre-processes inputs for better results.
- Start Processing: Click the "Start Processing" button.
- View & Download: Results will appear in the gallery or video player. A
.zipfile of all results (for batch jobs) or the final video can be downloaded. You can also click "Open Output Directory" to directly access all saved files.
ModuleNotFoundError: No module named 'face2face'or'torch': You either skipped a step or the installation failed. Deactivate and delete thevenvfolder, then start the installation guide from Step 2.ffmpeg: command not foundor Video Output is Silent: This means FFmpeg is not installed or not in your system's PATH. Go back to the Prerequisites section and ensure FFmpeg is installed correctly.- CUDA Errors (e.g.,
CUDA out of memory): Your GPU may not have enough VRAM. Try disabling "High Quality Mode", reducing the "Face Upscale Factor", or processing fewer files at once. - Application is Very Slow: You are likely using the CPU version. GPU acceleration is essential for fast processing. Ensure you followed the GPU installation steps and that your system recognizes your NVIDIA GPU.