Effortlessly swap faces between two images using the PiAPI FaceSwap API and Python! This project demonstrates how to automate face-swapping with just a few lines of code—perfect for developers, content creators, or anyone interested in generative AI.
- Automated face-swapping between two images via API
- Asynchronous job handling: submit a swap, then fetch the result
- Simple, readable Python code
- Easily customizable for your own images or workflows
- Send a POST request to the FaceSwap API with your source and target image URLs.
- Receive a Task ID to track your swap job.
- Poll the API for the result using the Task ID.
- Get a URL to your face-swapped image when the job is done.
- Python 3.7+
- PiAPI FaceSwap API Key (sign up for free credits!)
python-dotenv
for managing secrets (pip install python-dotenv
)- Internet connection for API calls
- Clone this repo and install dependencies:
pip install python-dotenv
- Run the script with your chosen image URLs!
- Change the
source
andswap
URLs to your own images. - Adjust
max_retries
orretry_delay
inget_result()
for longer or shorter polling.
- Endpoint:
POST /api/face_swap/v1/async
Submit your swap job withtarget_image
andswap_image
(URLs). - Endpoint:
POST /api/face_swap/v1/fetch
Retrieve the result usingtask_id
.
Note: Each image should contain only one visible face for best results[1][2][3].
- Social media filters
- Entertainment apps
- Profile picture customization
- Generative AI projects
This project is for educational and non-commercial use. For commercial deployments, refer to PiAPI's Terms of Service.
- Powered by [PiAPI FaceSwap API][1][3]
- Inspired by [Hugging Face Model Card][1]
Start swapping faces—let your creativity run wild!