fs / README.md
alfredang's picture
fix: add HF Spaces YAML frontmatter to README
3e5ad12
|
Raw
History Blame Contribute Delete
5.18 kB

A newer version of the Gradio SDK is available: 6.19.0

Upgrade
metadata
title: Face Swap
emoji: πŸ”„
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 6.13.0
app_file: app.py
pinned: false

Face Swap

Python Gradio TinyFace Hugging Face Spaces License: MIT

A lightweight face swap web app powered by TinyFace and Gradio

Live Demo Β· Report Bug Β· Request Feature

Screenshot

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

# Clone the repository
git clone https://github.com/alfredang/faceswap.git
cd faceswap

# Install dependencies
pip install -r requirements.txt

Running

python app.py

Open 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. 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 for questions and ideas.


Powered by Tertiary Infotech Academy Pte Ltd

Acknowledgements

  • TinyFace β€” Lightweight face swap library
  • Gradio β€” Web UI framework
  • GFPGAN β€” Face enhancement

If you found this useful, please give it a ⭐