Menu

1 / 2

Face Swap in Python: Batch Swap One Face onto Templates

DEV Community: computervision·AI Engine·8 days ago
#bNJAwx8I
Reading 0:00
15s threshold

Personalized avatar packs and themed profile pictures need the same thing: one user's face placed on many template images. This tutorial builds that in Python. You give the script a selfie and a folder of templates, and it saves one swapped image per template, with no GPU and no model to install.

All the code was run against the live Face Swap API , and the results shown are its real output.

The batch script

You need pip install requests , a RapidAPI key, a selfie.jpg and a templates/ folder of JPG images.

from concurrent.futures import ThreadPoolExecutor from pathlib import Path

import requests

BASE = " https://deepfake-face-swap-ai.p.rapidapi.com " HEADERS = { " x-rapidapi-host " : " deepfake-face-swap-ai.p.rapidapi.com " , " x-rapidapi-key " : " YOUR_API_KEY " , } WORKERS = 4

def swap_face ( source_path , target_path ): """ Swap the face from source_path onto target_path, return the result URL.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.