---
title: Face Swap
emoji: π
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 6.13.0
app_file: app.py
pinned: false
---
# Face Swap
[](https://python.org)
[](https://gradio.app)
[](https://github.com/idootop/TinyFace)
[](https://huggingface.co/spaces/alfredang/faceswap)
[](https://opensource.org/licenses/MIT)
**A lightweight face swap web app powered by TinyFace and Gradio**
[Live Demo](https://huggingface.co/spaces/alfredang/faceswap) Β· [Report Bug](https://github.com/alfredang/faceswap/issues) Β· [Request Feature](https://github.com/alfredang/faceswap/issues)
## Screenshot

## About
Face Swap is a simple web application that lets you swap faces between two images. Upload an original image containing the face you want to replace, and a reference image with the new face to apply β the app handles the rest.
- **One-click face swap** β Upload two images and hit Submit
- **Automatic face detection** β Powered by TinyFace's ONNX-based pipeline
- **Face enhancement** β Built-in GFPGAN post-processing for natural results
- **Web UI** β Clean Gradio interface with drag-and-drop upload
## Tech Stack
| Category | Technology |
|----------|------------|
| **Frontend** | Gradio |
| **Backend** | Python |
| **AI/ML** | TinyFace, ONNX Runtime |
| **Face Detection** | SCRFD |
| **Face Recognition** | ArcFace |
| **Face Enhancement** | GFPGAN |
| **Deployment** | Hugging Face Spaces |
## Architecture
```
βββββββββββββββββββββββββββββββββββββββββββ
β Gradio Web UI β
β (Image Upload + Result Display) β
ββββββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββββββ
β app.py β
β RGB β BGR conversion + validation β
ββββββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββββββ
β TinyFace Pipeline β
β βββββββββββββ ββββββββββββ ββββββββββ β
β β SCRFD β β ArcFace β β GFPGAN β β
β β Detect βββ Swap βββEnhance β β
β βββββββββββββ ββββββββββββ ββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββ
```
## Project Structure
```
faceswap/
βββ app.py # Main application (Gradio UI + swap logic)
βββ requirements.txt # Python dependencies
βββ screenshot.png # App screenshot
βββ README.md # This file
```
## Getting Started
### Prerequisites
- Python 3.10+
- pip
### Installation
```bash
# Clone the repository
git clone https://github.com/alfredang/faceswap.git
cd faceswap
# Install dependencies
pip install -r requirements.txt
```
### Running
```bash
python app.py
```
Open [http://127.0.0.1:7860](http://127.0.0.1:7860) in your browser.
> **Note:** On first launch, TinyFace will automatically download the required models (~800MB total).
## Deployment
### Hugging Face Spaces
This app is deployed on [Hugging Face Spaces](https://huggingface.co/spaces/alfredang/faceswap). To deploy your own:
1. Create a new Space with `Gradio` SDK
2. Upload `app.py`, `requirements.txt`, and the HF `README.md` with Space metadata
3. The Space will auto-build and download models on first run
## Contributing
Contributions are welcome!
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
Join the [Discussions](https://github.com/alfredang/faceswap/discussions) for questions and ideas.
---
### Powered by [Tertiary Infotech Academy Pte Ltd](https://www.tertiarycourses.com.sg/)
### Acknowledgements
- [TinyFace](https://github.com/idootop/TinyFace) β Lightweight face swap library
- [Gradio](https://gradio.app) β Web UI framework
- [GFPGAN](https://github.com/TencentARC/GFPGAN) β Face enhancement
---
If you found this useful, please give it a β