Spaces:
Paused
Paused
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,12 +1,91 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
| 8 |
-
license:
|
| 9 |
-
short_description: Swap
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Face Swap Image To Video
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
+
license: other
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Face Swap: Image β Video
|
| 13 |
+
|
| 14 |
+
Upload a face photo and a target video; the app swaps the face from your
|
| 15 |
+
photo onto every face it detects in the video, frame by frame, and
|
| 16 |
+
re-attaches the original audio.
|
| 17 |
+
|
| 18 |
+
It uses:
|
| 19 |
+
- **insightface** (`buffalo_l`) for face detection/analysis
|
| 20 |
+
- **inswapper_128.onnx** for the actual face swap
|
| 21 |
+
- **onnxruntime-gpu** to run on a GPU
|
| 22 |
+
- **ffmpeg** to remux the original audio back onto the output
|
| 23 |
+
|
| 24 |
+
This Space builds from a custom `Dockerfile` (lean `python:3.10-slim` base)
|
| 25 |
+
rather than the Gradio SDK's auto-build, which avoids compiling Python from
|
| 26 |
+
source and pulling in a huge C toolchain β the auto-build path was timing
|
| 27 |
+
out during `apt-get` on this dependency stack. Build should now take a few
|
| 28 |
+
minutes instead of 40+.
|
| 29 |
+
|
| 30 |
+
## Setup on Hugging Face
|
| 31 |
+
|
| 32 |
+
1. Create a new Space β SDK: **Docker** (not Gradio).
|
| 33 |
+
2. Upload all files in this folder (`Dockerfile`, `app.py`,
|
| 34 |
+
`requirements.txt`, `README.md`) to the Space repo root.
|
| 35 |
+
3. In **Settings β Hardware**, select a **rented GPU** tier (e.g. T4 small,
|
| 36 |
+
T4 medium, or A10G) β CPU Basic will work but will be very slow for
|
| 37 |
+
video.
|
| 38 |
+
4. Build/restart the Space. On first launch it downloads:
|
| 39 |
+
- the `buffalo_l` face analysis model (auto, via `insightface`)
|
| 40 |
+
- `inswapper_128.onnx` (auto, via a Hugging Face Hub mirror β see below)
|
| 41 |
+
|
| 42 |
+
### If the download is slow
|
| 43 |
+
|
| 44 |
+
- The app already enables `hf_transfer` (parallel chunked downloads), which
|
| 45 |
+
is usually a big speedup over a plain single-stream download.
|
| 46 |
+
- **Turn on Persistent Storage** in Settings β this is the biggest win: without
|
| 47 |
+
it, the ~530 MB model gets re-downloaded every time the Space restarts or
|
| 48 |
+
wakes from sleep. With it, you only pay for the slow download once.
|
| 49 |
+
- Check the Space logs β the app prints which mirror it's trying
|
| 50 |
+
(`[model-download] trying ...`). If it's stuck on one mirror, that mirror
|
| 51 |
+
may be throttled; you can reorder/edit `INSWAPPER_MIRRORS` in `app.py` to
|
| 52 |
+
try a different one first, or download the file yourself and upload it
|
| 53 |
+
directly to the Space root as `inswapper_128.onnx` (skips the download
|
| 54 |
+
entirely).
|
| 55 |
+
|
| 56 |
+
### If the automatic model download fails
|
| 57 |
+
|
| 58 |
+
`inswapper_128.onnx` (~530 MB) isn't included in this zip because it's a
|
| 59 |
+
large binary model file, and its original hosting has moved around over
|
| 60 |
+
time. `app.py` tries a few known public mirrors on the Hub automatically.
|
| 61 |
+
If all of them fail (mirrors do occasionally disappear), just download the
|
| 62 |
+
file yourself from wherever you can find a trusted copy and drop it into
|
| 63 |
+
the Space's root folder as `inswapper_128.onnx` β the app checks for a
|
| 64 |
+
local copy first before trying to download anything.
|
| 65 |
+
|
| 66 |
+
## Files
|
| 67 |
+
|
| 68 |
+
| File | Purpose |
|
| 69 |
+
|--------------------|---------------------------------------------------|
|
| 70 |
+
| `Dockerfile` | Lean build: python:3.10-slim + ffmpeg + pip deps |
|
| 71 |
+
| `app.py` | Gradio UI + face-swap pipeline |
|
| 72 |
+
| `requirements.txt` | Python packages |
|
| 73 |
+
| `README.md` | This file / Space metadata header |
|
| 74 |
+
|
| 75 |
+
## Responsible use
|
| 76 |
+
|
| 77 |
+
Only upload media you have the rights and consent to modify. Don't use
|
| 78 |
+
this to impersonate real people without their permission, create
|
| 79 |
+
non-consensual explicit content, or spread misinformation. You are
|
| 80 |
+
responsible for how you use the output.
|
| 81 |
+
|
| 82 |
+
## Local testing
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
pip install -r requirements.txt
|
| 86 |
+
python app.py
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
(You'll need `ffmpeg` installed locally too, and a CUDA-capable GPU +
|
| 90 |
+
matching drivers for `onnxruntime-gpu` to actually use the GPU β otherwise
|
| 91 |
+
it'll fall back to CPU.)
|