Spaces:
Running
title: DeepFace Studio
emoji: π
colorFrom: green
colorTo: yellow
sdk: docker
app_port: 7860
pinned: false
license: mit
DeepFace Studio
Live demo: https://aditya-raj19-faceswap.hf.space
AI-powered face swap web application with seamless hair-to-neck blending, skin tone matching, and Firebase authentication.
Features
- Live camera capture or image upload for source face
- Upload target face image
- Deep face swap using InsightFace inswapper model
- Hair-to-neck seamless blending (Laplacian + Poisson)
- Skin tone matching (CIE LAB colour transfer)
- Quality metrics after every swap
- Firebase Google Sign-in with 10-day session
- GPU + CPU support (auto-detected)
Local Setup
Requirements
- Python 3.10+
- Node.js 20+
Installation
# Install Python dependencies
pip install -r requirements.txt
# Download the face swap model (~528 MB)
python scripts/download_models.py
# Build the React frontend
cd frontend
npm install
npm run build
cd ..
# Start the app
python web_app.py
Hair Transfer (HairFastGAN) β optional
The "Swap hair too" toggle transfers the source's hairstyle (InsightFace only
swaps the face). Two backends, auto-selected by core/hair_transfer.py:
- Local GPU (best) β vendored HairFastGAN on your NVIDIA GPU. Needs Visual
Studio Build Tools (C++), CUDA, and git-lfs. Set it up once:
First swap is slow (one-time op compile + CLIP/vgg download); then ~18s each.python scripts/setup_hairfast.py # clones repo + ~7GB weights, patches ops pip install git+https://github.com/openai/CLIP.git face_alignment lpips kornia - Hosted Space (HF / no local GPU) β falls back to the HairFastGAN Gradio
Space automatically. Set
HF_TOKEN(lifts the public ZeroGPU quota) and optionallyHAIRFAST_SPACE=<you>/HairFastGANfor your own GPU Space. Force this path withHAIRFAST_LOCAL=0.
external/ (the vendored repo + weights) is gitignored; scripts/setup_hairfast.py
recreates it on any machine.
Firebase Setup
- Go to https://console.firebase.google.com
- Create a new project
- Add a Web App
- Enable Google Sign-In under Authentication
- Copy the config into
frontend/src/firebase.js - Rebuild the frontend:
cd frontend && npm run build
Deployment (HuggingFace Spaces)
The app deploys automatically via GitHub Actions on every push to main.
The inswapper model is downloaded automatically at container startup.
Tech Stack
- Frontend: React 18 + Vite + TailwindCSS + Framer Motion
- Backend: Python + Flask
- AI Models: InsightFace (inswapper_128), MediaPipe, OpenCV
- Auth: Firebase Google Sign-In
Note
This tool is for educational purposes only. Use responsibly and only with images you own or have explicit consent to use.
Pipeline
The swap runs a deliberately short, high-quality path β no heavy post-blending that softens the face or smears the hairline:
- InsightFace
inswapper_128swaps the face (paste_backalready blends the boundary; source skin tone is carried by the model). - GFPGAN face restoration recreates the facial detail lost in the model's 128Γ128 internal resize β this is what removes the blur. Runs before the preview is encoded, so the on-screen result is sharp, not just the download.
- RealESRGAN Γ4 upscales the result to ~4K for the downloadable PNG (Lanczos fallback if the SR weights aren't present).
All three models auto-detect and run on GPU (CUDA) when available.
Full Feature List
π Core Face Swap
- Deep face swap β InsightFace
inswapper_128ONNX model, Haar-cascadeseamlessClonefallback (core/swapper.py) - Multi-face targets β swaps every detected face
- Glasses/spectacle preservation β restores the target's eyewear region after the swap
- GFPGAN face restoration β fixes the 128Γ128 swap blur (core/super_res.py)
π Detection & Analysis
- Face detection β InsightFace
buffalo_lwith Haar fallback (core/detector.py) - 468-point landmarks β MediaPipe Face Mesh (core/landmarks.py)
- Hair/skin/neck segmentation β BiSeNet or heuristic (core/segmentor.py)
- Skin-tone analysis β Fitzpatrick category + undertone from 5 face regions (core/skin_tone.py)
π Quality Metrics (shown after every swap)
- Alignment, Blend quality, ΞE colour difference, Naturalness (core/quality_checker.py)
π§° Additional Modules (available for the full/batch pipelines)
- Seamless hairβfaceβneck blending (core/neck_integrator.py)
- Laplacian pyramid + Poisson seamless cloning (core/blender.py)
- Colour harmonization + boundary-lighting correction (core/color_corrector.py)
- Face alignment β Procrustes transform (core/aligner.py)
- Full pipeline with progress callbacks (pipeline/full_pipeline.py) and batch β one source β many targets (pipeline/batch_pipeline.py)
π₯οΈ Frontend (React 18 + Vite + Tailwind + Framer Motion)
- Landing + App pages with animated UI (Aurora, BlurText, SplitText, TiltedCard, Spotlight, CountUp, Magnet)
- Live camera capture or image upload for the source face
- Firebase Google Sign-In with 10-day session (frontend/src/hooks/useAuth.js)
βοΈ Backend & Infra
- Flask REST API β
/api/detect,/api/swap,/api/download(web_app.py) - 4K PNG download of results
- Docker deployment (port 7860) +
startup.shauto-downloads models - CI/CD β GitHub Actions:
ci.yml(backend pytest + frontend build),deploy.yml(auto-push to HuggingFace Spaces onmain) - GPU + CPU auto-detection
Live demo: https://aditya-raj19-faceswap.hf.space
Β© Aditya Raj 2026