Skip to content

Python Flask API for Face Swapper and Restoration powered by insightface 🔥

License

Notifications You must be signed in to change notification settings

ashleykleynhans/inswapper-flask-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

inswapper-flask-api

Python Flask API for Face Swapper and Restoration powered by insightface.

Installation

Clone this repository

git clone https://github.com/ashleykleynhans/inswapper-flask-api.git
cd inswapper-flask-api

Install the required Python dependencies

Linux and Mac

python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt

Windows

python3 -m venv venv
venv\Scripts\activate
pip3 install -r requirements.txt

Download Checkpoints

You will need to download the face swap model and save it under ./checkpoints.

mkdir checkpoints
wget -O ./checkpoints/inswapper_128.onnx https://huggingface.co/ashleykleynhans/inswapper/resolve/main/inswapper_128.onnx

Face Restoration

In order to obtain better results, it is highly recommended to enable a face restoration model, which will improve image quality. This application uses CodeFormer for face restoration.

The required models will be downloaded automatically the first time the face swap API is called.

You will require Git Large File Storage to be installed on your system before you can run the following command.

git lfs install
git clone https://huggingface.co/spaces/sczhou/CodeFormer

Examples

Refer to the examples provided for getting started with making calls to the API.

Benchmarks

These benchmarks are for a source image with a resolution of 960x1280 and a target image with a resolution of 1200x750, upscaled by 1 and with CodeFormer Face Restoration enabled.

System Time Taken
macOS Ventura 13.4.1 on Apple M1 Max 68.6 seconds
Ubuntu 22.04 LTS on t3a.xlarge AWS instance 248.1 seconds
Ubuntu 22.04 LTS on an A5000 RunPod GPU pod 14.2 seconds
Windows 10 103.9 seconds

Get a RunPod account.

Acknowledgements

  1. Thanks insightface.ai for releasing their powerful swap model that made this possible.
  2. This codebase is built on top of inswapper and CodeFormer.
  3. inswapper is built on the top of sd-webui-roop and CodeFormer.