WW
Browse files
README.md
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
(It includes the required YAML metadata at the very top and fixes your tags/list formatting.)
|
| 3 |
-
|
| 4 |
title: 🎬 BackgroundFX Pro - SAM2 + MatAnyone
|
| 5 |
emoji: 🎥
|
| 6 |
colorFrom: indigo
|
|
@@ -9,154 +7,88 @@ sdk: docker
|
|
| 9 |
app_port: 7860
|
| 10 |
license: mit
|
| 11 |
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
background-removal
|
| 16 |
-
|
| 17 |
-
segmentation
|
| 18 |
-
|
| 19 |
-
matting
|
| 20 |
-
|
| 21 |
-
SAM2
|
| 22 |
-
|
| 23 |
-
MatAnyone
|
| 24 |
-
|
| 25 |
-
🎬 BackgroundFX Pro — Professional Video Background Replacement
|
| 26 |
|
| 27 |
BackgroundFX Pro is a GPU-accelerated app for Hugging Face Spaces (Docker) that replaces video backgrounds using:
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
HF cache: ./.hf
|
| 44 |
-
|
| 45 |
-
Torch cache: ./.torch
|
| 46 |
-
|
| 47 |
-
App data & logs: ./data (see data/run.log)
|
| 48 |
-
|
| 49 |
-
🚀 Try It
|
| 50 |
-
|
| 51 |
-
Open the Space in your browser (GPU required):
|
| 52 |
https://huggingface.co/spaces/MogensR/VideoBackgroundReplacer2
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
Upload a video (.mp4, .avi, .mov, .mkv).
|
| 57 |
-
|
| 58 |
-
Choose a Background Type: Upload Image, AI Generate, Gradient, Solid, or Unsplash.
|
| 59 |
-
|
| 60 |
-
If not uploading, enter a prompt and click Generate Background.
|
| 61 |
-
|
| 62 |
-
Click Process Video.
|
| 63 |
-
|
| 64 |
-
Preview and download the result.
|
| 65 |
-
|
| 66 |
-
Tip: Start with 720p/1080p on T4; 4K can exceed memory.
|
| 67 |
-
|
| 68 |
-
🗂️ Project Structure (key files)
|
| 69 |
-
|
| 70 |
-
Dockerfile
|
| 71 |
-
|
| 72 |
-
requirements.txt
|
| 73 |
-
|
| 74 |
-
ui.py
|
| 75 |
-
|
| 76 |
-
ui_core_interface.py
|
| 77 |
-
|
| 78 |
-
ui_core_functionality.py
|
| 79 |
-
|
| 80 |
-
two_stage_pipeline.py
|
| 81 |
-
|
| 82 |
-
models/sam2_loader.py
|
| 83 |
-
|
| 84 |
-
models/matanyone_loader.py
|
| 85 |
-
|
| 86 |
-
utils/init.py
|
| 87 |
-
|
| 88 |
-
data/ (created at runtime for logs and outputs)
|
| 89 |
-
|
| 90 |
-
tmp/ (created at runtime for jobs and temp files)
|
| 91 |
-
|
| 92 |
-
⚙️ Runtime Notes
|
| 93 |
-
|
| 94 |
-
The app binds to the port from PORT or GRADIO_SERVER_PORT (defaults to 7860).
|
| 95 |
-
|
| 96 |
-
A heartbeat writes every ~2s to logs with memory and disk stats.
|
| 97 |
-
|
| 98 |
-
If the process dies without a final “PROCESS EXITING” line, it was likely an OOM or hard kill.
|
| 99 |
-
|
| 100 |
-
🧪 Local Development (Docker)
|
| 101 |
-
|
| 102 |
-
Requires an NVIDIA GPU with CUDA drivers installed.
|
| 103 |
-
|
| 104 |
-
Steps:
|
| 105 |
-
|
| 106 |
-
Clone the Space repo.
|
| 107 |
-
|
| 108 |
-
Build the image (base: Ubuntu 22.04, CUDA 12.1.1; installs Torch 2.5.1+cu121).
|
| 109 |
-
|
| 110 |
-
Run the container and map port 7860.
|
| 111 |
-
|
| 112 |
-
🔧 Space Settings
|
| 113 |
-
|
| 114 |
-
SDK: docker
|
| 115 |
-
|
| 116 |
-
App port: 7860
|
| 117 |
-
|
| 118 |
-
Hardware: T4 GPU (or better)
|
| 119 |
-
|
| 120 |
-
📦 Key Versions
|
| 121 |
-
|
| 122 |
-
Gradio: 4.41.0
|
| 123 |
-
|
| 124 |
-
PyTorch: 2.5.1 (cu121)
|
| 125 |
-
|
| 126 |
-
torchvision: 0.20.1
|
| 127 |
-
|
| 128 |
-
SAM2: installed from source at build time in third_party/sam2
|
| 129 |
-
|
| 130 |
-
MatAnyone: installed from GitHub
|
| 131 |
-
|
| 132 |
-
🧯 Troubleshooting
|
| 133 |
|
| 134 |
-
|
| 135 |
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
|
| 139 |
|
| 140 |
-
|
| 141 |
|
| 142 |
-
|
| 143 |
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
-
|
| 147 |
|
| 148 |
-
|
| 149 |
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
|
| 152 |
-
|
| 153 |
|
| 154 |
-
|
| 155 |
|
| 156 |
-
|
| 157 |
|
| 158 |
-
|
|
|
|
|
|
|
| 159 |
|
| 160 |
-
|
|
|
|
| 161 |
|
| 162 |
-
|
|
|
|
|
|
| 1 |
+
---
|
|
|
|
|
|
|
| 2 |
title: 🎬 BackgroundFX Pro - SAM2 + MatAnyone
|
| 3 |
emoji: 🎥
|
| 4 |
colorFrom: indigo
|
|
|
|
| 7 |
app_port: 7860
|
| 8 |
license: mit
|
| 9 |
tags:
|
| 10 |
+
- video
|
| 11 |
+
- background-removal
|
| 12 |
+
- segmentation
|
| 13 |
+
- matting
|
| 14 |
+
- SAM2
|
| 15 |
+
- MatAnyone
|
| 16 |
+
---
|
| 17 |
|
| 18 |
+
# 🎬 BackgroundFX Pro — Professional Video Background Replacement
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
BackgroundFX Pro is a GPU-accelerated app for Hugging Face Spaces (Docker) that replaces video backgrounds using:
|
| 21 |
+
- **SAM2** — high-quality object segmentation
|
| 22 |
+
- **MatAnyone** — temporal video matting for stable alpha over time
|
| 23 |
|
| 24 |
+
Built on: **CUDA 12.1.1**, **PyTorch 2.5.1 (cu121)**, **torchvision 0.20.1**, **Gradio 4.41.0**.
|
| 25 |
|
| 26 |
+
---
|
| 27 |
|
| 28 |
+
## ✨ Features
|
| 29 |
|
| 30 |
+
- Replace backgrounds with: **solid color**, **AI-generated** image (procedural), **custom uploaded image**, or **Unsplash** search
|
| 31 |
+
- Optimized for **T4 GPUs** on Hugging Face
|
| 32 |
+
- Caching & logs stored in the repo volume:
|
| 33 |
+
- HF cache → `./.hf`
|
| 34 |
+
- Torch cache → `./.torch`
|
| 35 |
+
- App data & logs → `./data` (see `data/run.log`)
|
| 36 |
|
| 37 |
+
---
|
| 38 |
|
| 39 |
+
## 🚀 Try It
|
| 40 |
|
| 41 |
+
Open the Space in your browser (GPU required):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
https://huggingface.co/spaces/MogensR/VideoBackgroundReplacer2
|
| 43 |
|
| 44 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
## 🖱️ How to Use
|
| 47 |
|
| 48 |
+
1. **Upload a video** (`.mp4`, `.avi`, `.mov`, `.mkv`).
|
| 49 |
+
2. Choose a **Background Type**: Upload Image, AI Generate, Gradient, Solid, or Unsplash.
|
| 50 |
+
3. If not uploading, enter a prompt and click **Generate Background**.
|
| 51 |
+
4. Click **Process Video**.
|
| 52 |
+
5. Preview and **Download Result**.
|
| 53 |
|
| 54 |
+
> Tip: Start with 720p/1080p on T4; 4K can exceed memory.
|
| 55 |
|
| 56 |
+
---
|
| 57 |
|
| 58 |
+
## 🗂️ Project Structure (key files)
|
| 59 |
|
| 60 |
+
- `Dockerfile`
|
| 61 |
+
- `requirements.txt`
|
| 62 |
+
- `ui.py`
|
| 63 |
+
- `ui_core_interface.py`
|
| 64 |
+
- `ui_core_functionality.py`
|
| 65 |
+
- `two_stage_pipeline.py`
|
| 66 |
+
- `models/sam2_loader.py`
|
| 67 |
+
- `models/matanyone_loader.py`
|
| 68 |
+
- `utils/__init__.py`
|
| 69 |
+
- `data/` (created at runtime for logs/outputs)
|
| 70 |
+
- `tmp/` (created at runtime for jobs/temp files)
|
| 71 |
|
| 72 |
+
---
|
| 73 |
|
| 74 |
+
## ⚙️ Runtime Notes
|
| 75 |
|
| 76 |
+
- Binds to `PORT` / `GRADIO_SERVER_PORT` (defaults to **7860**).
|
| 77 |
+
- Heartbeat logs every ~2s with memory & disk stats.
|
| 78 |
+
- If there’s no final “PROCESS EXITING” line, it was likely an **OOM** or hard kill.
|
| 79 |
|
| 80 |
+
---
|
| 81 |
|
| 82 |
+
## 🧪 Local Development (Docker)
|
| 83 |
|
| 84 |
+
Requires an NVIDIA GPU with CUDA drivers.
|
| 85 |
|
| 86 |
+
```bash
|
| 87 |
+
git clone https://huggingface.co/spaces/MogensR/VideoBackgroundReplacer2
|
| 88 |
+
cd VideoBackgroundReplacer2
|
| 89 |
|
| 90 |
+
# Build (Ubuntu 22.04, CUDA 12.1.1; installs Torch 2.5.1+cu121)
|
| 91 |
+
docker build -t backgroundfx-pro .
|
| 92 |
|
| 93 |
+
# Run
|
| 94 |
+
docker run --gpus all -p 7860:7860 backgroundfx-pro
|