Spaces:
Sleeping
Sleeping
Initial Soundstage ZeroGPU Space
Browse files- README.md +13 -7
- SPACE_DEPLOY.md +118 -0
- __pycache__/app.cpython-314.pyc +0 -0
- __pycache__/pipeline.cpython-314.pyc +0 -0
- __pycache__/setup_weights.cpython-314.pyc +0 -0
- app.py +279 -0
- packages.txt +2 -0
- pipeline.py +366 -0
- requirements.txt +37 -0
- setup_weights.py +167 -0
- theme.css +155 -0
README.md
CHANGED
|
@@ -1,13 +1,19 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version:
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Soundstage Preview
|
| 3 |
+
emoji: 🎬
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.49.1
|
| 8 |
+
python_version: "3.10"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
+
startup_duration_timeout: 1h
|
| 12 |
+
suggested_hardware: zero-a10g
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# Soundstage
|
| 16 |
+
|
| 17 |
+
Private soundtrack preview — upload a short video and generate speech, sound effects, and music locked to the picture.
|
| 18 |
+
|
| 19 |
+
Access requires a guest token (set as Space secret `ACCESS_TOKEN`).
|
SPACE_DEPLOY.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deploy Soundstage on Hugging Face (ZeroGPU)
|
| 2 |
+
|
| 3 |
+
Public Gradio Space with a guest-token gate and free **ZeroGPU (A10G)** inference.
|
| 4 |
+
|
| 5 |
+
**Do not use Docker SDK** for this path — ZeroGPU only works with Gradio Spaces.
|
| 6 |
+
|
| 7 |
+
## 0. Account rules (important)
|
| 8 |
+
|
| 9 |
+
Hugging Face changed hosting: **Gradio/Docker on `cpu-basic` needs PRO**.
|
| 10 |
+
Free personal accounts in good standing (verified email, account ≥ ~30 days) can still host **up to 2 ZeroGPU Gradio Spaces** for free.
|
| 11 |
+
|
| 12 |
+
| Path | Works on free? |
|
| 13 |
+
|------|----------------|
|
| 14 |
+
| Create Gradio Space via CLI (`upload` auto-creates on cpu-basic) | **No** → `402 Payment Required` |
|
| 15 |
+
| Create Gradio Space in the **web UI** with hardware **ZeroGPU** | **Yes** (≤2 Spaces) |
|
| 16 |
+
| PRO / Team org | Gradio + Docker + more ZeroGPU slots |
|
| 17 |
+
|
| 18 |
+
Do **not** use `huggingface-cli upload …` to *create* the Space. Create it in the browser first (ZeroGPU), then push files.
|
| 19 |
+
|
| 20 |
+
## 1. Create the Space (web UI)
|
| 21 |
+
|
| 22 |
+
1. Open [huggingface.co/new-space](https://huggingface.co/new-space)
|
| 23 |
+
2. Owner: your **personal** user (ZeroGPU free tier is for personal accounts; orgs need Team/Enterprise)
|
| 24 |
+
3. Name: e.g. `Soundstage`
|
| 25 |
+
4. SDK: **Gradio**
|
| 26 |
+
5. Hardware: **ZeroGPU** (A10G / `zero-a10g`) — pick this at create time if shown
|
| 27 |
+
6. Visibility: **Public** (access is gated by `ACCESS_TOKEN` in the UI)
|
| 28 |
+
7. Create Space
|
| 29 |
+
|
| 30 |
+
## 2. Confirm hardware is ZeroGPU
|
| 31 |
+
|
| 32 |
+
1. Space → **Settings** → **Hardware**
|
| 33 |
+
2. Must be **ZeroGPU** / **Nvidia A10G · ZeroGPU** (`zero-a10g`), not CPU Basic
|
| 34 |
+
3. Save
|
| 35 |
+
|
| 36 |
+
Without ZeroGPU, Foley-Omni will not fit. If the UI only offers CPU Basic and asks for PRO, your account is not eligible for the free ZeroGPU host quota (too new / email unverified / already at 2 Spaces) — then you need [PRO](https://huggingface.co/pro) or reuse/replace an existing ZeroGPU Space (e.g. duplicate `Artimis/FOG` under a personal account that already has ZeroGPU).
|
| 37 |
+
|
| 38 |
+
## 3. Add secrets
|
| 39 |
+
|
| 40 |
+
Space → **Settings** → **Variables and secrets** → **New secret**:
|
| 41 |
+
|
| 42 |
+
| Secret | Purpose |
|
| 43 |
+
|--------|---------|
|
| 44 |
+
| `ACCESS_TOKEN` | Guest token shown on the gate screen |
|
| 45 |
+
| `ADMIN_TOKEN` | Admin token (optional clear-queue note; must differ from guest) |
|
| 46 |
+
|
| 47 |
+
Optional:
|
| 48 |
+
|
| 49 |
+
| Name | Purpose |
|
| 50 |
+
|------|---------|
|
| 51 |
+
| `HF_TOKEN` | Only if Hub downloads need auth |
|
| 52 |
+
| `SAMPLE_STEPS` | Default steps (Space default `15`) |
|
| 53 |
+
| `FOLEY_GPU_SECONDS` | `@spaces.GPU` duration budget (default `180`) |
|
| 54 |
+
| `MAX_VIDEO_SECONDS` | Max clip length (default `10`) |
|
| 55 |
+
|
| 56 |
+
## 4. Push this package as the Space root
|
| 57 |
+
|
| 58 |
+
The Space repo root must contain `app.py`, `README.md` (with YAML), `requirements.txt`, etc.
|
| 59 |
+
|
| 60 |
+
### Option A — clone Space and copy files
|
| 61 |
+
|
| 62 |
+
```bash
|
| 63 |
+
git clone https://huggingface.co/spaces/<user>/Soundstage
|
| 64 |
+
cd Soundstage
|
| 65 |
+
# Copy contents of Foley-Omni-API/hf_space/ into this repo root
|
| 66 |
+
cp -r /path/to/Foley-Omni-API/hf_space/* .
|
| 67 |
+
git add -A
|
| 68 |
+
git commit -m "Initial Soundstage ZeroGPU Space"
|
| 69 |
+
git push
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
### Option B — git subtree (from Foley-Omni-API root)
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
git subtree push --prefix=hf_space https://huggingface.co/spaces/<user>/Soundstage main
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
(Requires HF git credentials / token with write access to the Space.)
|
| 79 |
+
|
| 80 |
+
### Option C — Hugging Face CLI (Space must already exist)
|
| 81 |
+
|
| 82 |
+
```powershell
|
| 83 |
+
# Windows — Space must already exist with ZeroGPU (see §1)
|
| 84 |
+
& "$env:LOCALAPPDATA\Programs\Python\Python311\Scripts\huggingface-cli.exe" upload <user>/Soundstage ./hf_space . --repo-type=space
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
If you see **`402 Payment Required`**, the CLI tried to *create* a Gradio Space on cpu-basic. Create the Space in the web UI with ZeroGPU first, then re-run upload.
|
| 88 |
+
|
| 89 |
+
## 5. First build
|
| 90 |
+
|
| 91 |
+
1. Open the Space page — build installs `requirements.txt` + `packages.txt` (ffmpeg, git)
|
| 92 |
+
2. Cold start downloads weights from `CocoBro/Foley-Omni` (can take a long time)
|
| 93 |
+
3. README sets `startup_duration_timeout: 1h` so the first boot can finish
|
| 94 |
+
4. When the app is up: `https://<user>-<space>.hf.space/`
|
| 95 |
+
|
| 96 |
+
Standalone Space (only `hf_space/` files): startup clones Foley-Omni into `vendor/` then downloads checkpoints.
|
| 97 |
+
Monorepo push of the whole Foley-Omni-API tree also works — `setup_weights.py` detects parent `inference_v2st.py`.
|
| 98 |
+
|
| 99 |
+
## 6. Use it
|
| 100 |
+
|
| 101 |
+
1. Open the Space URL
|
| 102 |
+
2. Paste the guest `ACCESS_TOKEN` → **Enter studio**
|
| 103 |
+
3. Upload a ≤10s video, fill Words / Audio caption / Music, **Generate soundtrack**
|
| 104 |
+
4. Wait for ZeroGPU allocation + generation (first call is slowest)
|
| 105 |
+
|
| 106 |
+
## Troubleshooting
|
| 107 |
+
|
| 108 |
+
| Symptom | Check |
|
| 109 |
+
|---------|--------|
|
| 110 |
+
| Gate says secrets not set | Add `ACCESS_TOKEN` (and ideally `ADMIN_TOKEN`) under Secrets |
|
| 111 |
+
| OOM / CUDA errors | Hardware must be **ZeroGPU A10G**; keep `cpu_offload` on (default) |
|
| 112 |
+
| Stuck on “Preparing model” | First weight download / engine load — watch Space logs |
|
| 113 |
+
| Build fails on torch | Stick to the pinned versions in `requirements.txt` |
|
| 114 |
+
| Foley name in UI | Guest UI is Soundstage-only; Hub model id may still appear in logs |
|
| 115 |
+
|
| 116 |
+
## Paid alternative
|
| 117 |
+
|
| 118 |
+
Exact FastAPI + static HTML from the main repo needs a **Docker** Space with a **dedicated** paid GPU (ZeroGPU is Gradio-only). See root [`DEPLOY.md`](../DEPLOY.md) for self-hosted Docker.
|
__pycache__/app.cpython-314.pyc
ADDED
|
Binary file (11.4 kB). View file
|
|
|
__pycache__/pipeline.cpython-314.pyc
ADDED
|
Binary file (21 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Soundstage — public Gradio Space with guest-token gate + ZeroGPU inference.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import secrets
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import gradio as gr
|
| 12 |
+
|
| 13 |
+
# Import spaces before torch (ZeroGPU requirement) when available
|
| 14 |
+
try:
|
| 15 |
+
import spaces # noqa: F401
|
| 16 |
+
except ImportError:
|
| 17 |
+
spaces = None # type: ignore
|
| 18 |
+
|
| 19 |
+
from pipeline import SAMPLE_STEPS_DEFAULT, generate, warmup
|
| 20 |
+
|
| 21 |
+
HERE = Path(__file__).resolve().parent
|
| 22 |
+
THEME_CSS = (HERE / "theme.css").read_text(encoding="utf-8")
|
| 23 |
+
|
| 24 |
+
ACCESS_TOKEN = (os.getenv("ACCESS_TOKEN") or "").strip()
|
| 25 |
+
ADMIN_TOKEN = (os.getenv("ADMIN_TOKEN") or "").strip()
|
| 26 |
+
MAX_VIDEO_SECONDS = float(os.getenv("MAX_VIDEO_SECONDS", "10"))
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _check_token(token: str) -> tuple[bool, bool]:
|
| 30 |
+
"""Return (ok, is_admin)."""
|
| 31 |
+
t = (token or "").strip()
|
| 32 |
+
if not t:
|
| 33 |
+
return False, False
|
| 34 |
+
if ACCESS_TOKEN and secrets.compare_digest(t, ACCESS_TOKEN):
|
| 35 |
+
return True, False
|
| 36 |
+
if ADMIN_TOKEN and secrets.compare_digest(t, ADMIN_TOKEN):
|
| 37 |
+
return True, True
|
| 38 |
+
# Either secret missing: refuse rather than open the Space
|
| 39 |
+
if not ACCESS_TOKEN and not ADMIN_TOKEN:
|
| 40 |
+
return False, False
|
| 41 |
+
return False, False
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def enter_studio(token: str):
|
| 45 |
+
ok, is_admin = _check_token(token)
|
| 46 |
+
if not ok:
|
| 47 |
+
if not ACCESS_TOKEN and not ADMIN_TOKEN:
|
| 48 |
+
msg = "Space secrets ACCESS_TOKEN / ADMIN_TOKEN are not set."
|
| 49 |
+
else:
|
| 50 |
+
msg = "Invalid access token."
|
| 51 |
+
return (
|
| 52 |
+
gr.update(visible=True), # gate
|
| 53 |
+
gr.update(visible=False), # studio
|
| 54 |
+
msg,
|
| 55 |
+
False, # authed
|
| 56 |
+
False, # admin
|
| 57 |
+
gr.update(visible=False), # admin panel
|
| 58 |
+
"Private preview",
|
| 59 |
+
)
|
| 60 |
+
role = "Admin" if is_admin else "Guest"
|
| 61 |
+
return (
|
| 62 |
+
gr.update(visible=False),
|
| 63 |
+
gr.update(visible=True),
|
| 64 |
+
"",
|
| 65 |
+
True,
|
| 66 |
+
is_admin,
|
| 67 |
+
gr.update(visible=is_admin),
|
| 68 |
+
f"Private preview · {role}",
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def sign_out():
|
| 73 |
+
return (
|
| 74 |
+
gr.update(visible=True),
|
| 75 |
+
gr.update(visible=False),
|
| 76 |
+
"",
|
| 77 |
+
False,
|
| 78 |
+
False,
|
| 79 |
+
gr.update(visible=False),
|
| 80 |
+
"Private preview",
|
| 81 |
+
None, # clear result video
|
| 82 |
+
"", # clear status
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def run_generate(
|
| 87 |
+
authed: bool,
|
| 88 |
+
video,
|
| 89 |
+
words: str,
|
| 90 |
+
sfx: str,
|
| 91 |
+
music: str,
|
| 92 |
+
seed: float,
|
| 93 |
+
steps: float,
|
| 94 |
+
progress=gr.Progress(track_tqdm=False),
|
| 95 |
+
):
|
| 96 |
+
if not authed:
|
| 97 |
+
raise gr.Error("Please enter a valid access token first.")
|
| 98 |
+
if video is None:
|
| 99 |
+
raise gr.Error("Please upload a video first.")
|
| 100 |
+
|
| 101 |
+
path = video if isinstance(video, str) else getattr(video, "name", None) or str(video)
|
| 102 |
+
try:
|
| 103 |
+
out = generate(
|
| 104 |
+
video_path=path,
|
| 105 |
+
words=words or "",
|
| 106 |
+
sfx=sfx or "",
|
| 107 |
+
music=music or "",
|
| 108 |
+
seed=int(seed),
|
| 109 |
+
sample_steps=int(steps),
|
| 110 |
+
progress=progress,
|
| 111 |
+
)
|
| 112 |
+
return out, "Done — soundtrack muxed into your clip."
|
| 113 |
+
except ValueError as e:
|
| 114 |
+
raise gr.Error(str(e)) from e
|
| 115 |
+
except Exception as e:
|
| 116 |
+
raise gr.Error(str(e)[-800:]) from e
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def clear_queue_admin(authed: bool, is_admin: bool):
|
| 120 |
+
if not authed or not is_admin:
|
| 121 |
+
raise gr.Error("Admin token required.")
|
| 122 |
+
# Gradio's built-in queue cannot cancel others' GPU work; this is a soft ack.
|
| 123 |
+
return "Queue note: new jobs wait behind the current GPU job. Running work cannot be aborted on ZeroGPU."
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
# Warm model on non-ZeroGPU / after fork-safe path; on ZeroGPU load is deferred to first generate.
|
| 127 |
+
if not os.environ.get("SPACES_ZERO_GPU"):
|
| 128 |
+
try:
|
| 129 |
+
warmup()
|
| 130 |
+
except Exception:
|
| 131 |
+
pass
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
with gr.Blocks(
|
| 135 |
+
title="Soundstage Preview",
|
| 136 |
+
css=THEME_CSS,
|
| 137 |
+
theme=gr.themes.Base(
|
| 138 |
+
primary_hue=gr.themes.Color(
|
| 139 |
+
c50="#e8f5f3",
|
| 140 |
+
c100="#c5e8e3",
|
| 141 |
+
c200="#9fd5cf",
|
| 142 |
+
c300="#6bb8b0",
|
| 143 |
+
c400="#3d9189",
|
| 144 |
+
c500="#0c6b66",
|
| 145 |
+
c600="#084f4b",
|
| 146 |
+
c700="#063d3a",
|
| 147 |
+
c800="#042e2c",
|
| 148 |
+
c900="#021f1e",
|
| 149 |
+
c950="#011413",
|
| 150 |
+
),
|
| 151 |
+
font=[gr.themes.GoogleFont("IBM Plex Sans"), "system-ui", "sans-serif"],
|
| 152 |
+
),
|
| 153 |
+
) as demo:
|
| 154 |
+
is_authed = gr.State(False)
|
| 155 |
+
is_admin_state = gr.State(False)
|
| 156 |
+
|
| 157 |
+
# ----- Gate -----
|
| 158 |
+
with gr.Column(visible=True, elem_classes=["ss-panel"]) as gate_col:
|
| 159 |
+
gr.HTML(
|
| 160 |
+
"""
|
| 161 |
+
<p class="ss-brand">Soundstage</p>
|
| 162 |
+
<h1 class="ss-headline">Hear the picture.</h1>
|
| 163 |
+
<p class="ss-lede">
|
| 164 |
+
Private preview — generate speech, sound effects, and music locked to your clip.
|
| 165 |
+
</p>
|
| 166 |
+
"""
|
| 167 |
+
)
|
| 168 |
+
token_in = gr.Textbox(
|
| 169 |
+
label="Access token",
|
| 170 |
+
type="password",
|
| 171 |
+
placeholder="Paste the token you were given",
|
| 172 |
+
autofocus=True,
|
| 173 |
+
)
|
| 174 |
+
gate_err = gr.Markdown("", elem_classes=["ss-error"])
|
| 175 |
+
enter_btn = gr.Button("Enter studio", variant="primary")
|
| 176 |
+
gr.HTML(
|
| 177 |
+
f'<p class="ss-fine">Token stays in this browser only. '
|
| 178 |
+
f"Clips ≤ {MAX_VIDEO_SECONDS:.0f} seconds.</p>"
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
# ----- Studio -----
|
| 182 |
+
with gr.Column(visible=False) as studio_col:
|
| 183 |
+
with gr.Row(elem_classes=["ss-topbar"]):
|
| 184 |
+
gr.HTML('<span class="ss-brand">Soundstage</span>')
|
| 185 |
+
caption = gr.Markdown("Private preview")
|
| 186 |
+
signout_btn = gr.Button("Sign out", variant="secondary", size="sm")
|
| 187 |
+
|
| 188 |
+
with gr.Column(elem_classes=["ss-panel"]):
|
| 189 |
+
gr.HTML(
|
| 190 |
+
"""
|
| 191 |
+
<h2 class="ss-section-title">Compose</h2>
|
| 192 |
+
<p class="ss-lede">Describe what should be heard. At least one field below is enough.</p>
|
| 193 |
+
"""
|
| 194 |
+
)
|
| 195 |
+
video_in = gr.Video(
|
| 196 |
+
label="Video",
|
| 197 |
+
sources=["upload"],
|
| 198 |
+
format="mp4",
|
| 199 |
+
height=280,
|
| 200 |
+
)
|
| 201 |
+
words = gr.Textbox(
|
| 202 |
+
label="Words (speech)",
|
| 203 |
+
lines=2,
|
| 204 |
+
placeholder="What should be spoken…",
|
| 205 |
+
)
|
| 206 |
+
sfx = gr.Textbox(
|
| 207 |
+
label="Audio caption (SFX · ambience · voice)",
|
| 208 |
+
lines=3,
|
| 209 |
+
placeholder="Footsteps on gravel, distant traffic, a calm female voice…",
|
| 210 |
+
)
|
| 211 |
+
music = gr.Textbox(
|
| 212 |
+
label="Music (optional)",
|
| 213 |
+
lines=2,
|
| 214 |
+
placeholder="Soft piano, medium tempo, warm and understated…",
|
| 215 |
+
)
|
| 216 |
+
with gr.Accordion("Advanced", open=False):
|
| 217 |
+
with gr.Row():
|
| 218 |
+
seed = gr.Number(label="Seed", value=103, precision=0)
|
| 219 |
+
steps = gr.Slider(
|
| 220 |
+
label="Sample steps",
|
| 221 |
+
minimum=5,
|
| 222 |
+
maximum=50,
|
| 223 |
+
step=1,
|
| 224 |
+
value=SAMPLE_STEPS_DEFAULT,
|
| 225 |
+
)
|
| 226 |
+
gen_btn = gr.Button("Generate soundtrack", variant="primary")
|
| 227 |
+
gr.HTML(
|
| 228 |
+
'<p class="ss-fine">Jobs run one at a time on the shared preview GPU.</p>'
|
| 229 |
+
)
|
| 230 |
+
status = gr.Markdown("")
|
| 231 |
+
result = gr.Video(label="Result", interactive=False)
|
| 232 |
+
|
| 233 |
+
with gr.Column(visible=False) as admin_col:
|
| 234 |
+
clear_btn = gr.Button("Clear queue note", variant="secondary")
|
| 235 |
+
admin_msg = gr.Markdown("")
|
| 236 |
+
|
| 237 |
+
gate_outputs = [
|
| 238 |
+
gate_col,
|
| 239 |
+
studio_col,
|
| 240 |
+
gate_err,
|
| 241 |
+
is_authed,
|
| 242 |
+
is_admin_state,
|
| 243 |
+
admin_col,
|
| 244 |
+
caption,
|
| 245 |
+
]
|
| 246 |
+
|
| 247 |
+
enter_btn.click(enter_studio, inputs=[token_in], outputs=gate_outputs)
|
| 248 |
+
token_in.submit(enter_studio, inputs=[token_in], outputs=gate_outputs)
|
| 249 |
+
|
| 250 |
+
signout_btn.click(
|
| 251 |
+
sign_out,
|
| 252 |
+
outputs=[
|
| 253 |
+
gate_col,
|
| 254 |
+
studio_col,
|
| 255 |
+
gate_err,
|
| 256 |
+
is_authed,
|
| 257 |
+
is_admin_state,
|
| 258 |
+
admin_col,
|
| 259 |
+
caption,
|
| 260 |
+
result,
|
| 261 |
+
status,
|
| 262 |
+
],
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
gen_btn.click(
|
| 266 |
+
run_generate,
|
| 267 |
+
inputs=[is_authed, video_in, words, sfx, music, seed, steps],
|
| 268 |
+
outputs=[result, status],
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
clear_btn.click(
|
| 272 |
+
clear_queue_admin,
|
| 273 |
+
inputs=[is_authed, is_admin_state],
|
| 274 |
+
outputs=[admin_msg],
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
if __name__ == "__main__":
|
| 279 |
+
demo.queue(max_size=8, default_concurrency_limit=1).launch()
|
packages.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
| 2 |
+
git
|
pipeline.py
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ZeroGPU-aware soundtrack generation for the Soundstage Space.
|
| 3 |
+
|
| 4 |
+
Follows the proven Artimis/FOG pattern: cpu_offload, no qint8 on ZeroGPU,
|
| 5 |
+
@spaces.GPU around the generate step, single-flight lock.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import contextlib
|
| 11 |
+
import gc
|
| 12 |
+
import glob
|
| 13 |
+
import json
|
| 14 |
+
import os
|
| 15 |
+
import shutil
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
import tempfile
|
| 19 |
+
import threading
|
| 20 |
+
import wave
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
|
| 23 |
+
from setup_weights import ensure_ready
|
| 24 |
+
|
| 25 |
+
REPO_DIR = ensure_ready()
|
| 26 |
+
|
| 27 |
+
MODE = os.getenv("FOLEY_MODE", "inprocess").strip().lower()
|
| 28 |
+
IS_ZEROGPU = bool(os.environ.get("SPACES_ZERO_GPU"))
|
| 29 |
+
ZEROGPU_DURATION = int(os.getenv("FOLEY_GPU_SECONDS", "180"))
|
| 30 |
+
MAX_VIDEO_SECONDS = float(os.getenv("MAX_VIDEO_SECONDS", "10"))
|
| 31 |
+
MIN_GEN_DURATION = 1.0
|
| 32 |
+
SAMPLE_STEPS_DEFAULT = int(os.getenv("SAMPLE_STEPS", "15"))
|
| 33 |
+
|
| 34 |
+
_GPU_LOCK = threading.Lock()
|
| 35 |
+
_ENGINE: dict = {"inf": None, "engine": None, "cfg": None, "failed": False}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _env_flag(name: str, default: bool) -> bool:
|
| 39 |
+
v = os.getenv(name)
|
| 40 |
+
if v is None:
|
| 41 |
+
return default
|
| 42 |
+
return v.strip().lower() in ("1", "true", "yes", "on")
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def build_prompt(words: str, sfx: str, music: str) -> str:
|
| 46 |
+
parts = []
|
| 47 |
+
w = (words or "").strip()
|
| 48 |
+
a = (sfx or "").strip()
|
| 49 |
+
m = (music or "").strip()
|
| 50 |
+
if w:
|
| 51 |
+
parts.append(f"[WORDS]{w}[END_WORDS]")
|
| 52 |
+
if a:
|
| 53 |
+
parts.append(f"[AUDIO_CAPTION]{a}[END_AUDIO_CAPTION]")
|
| 54 |
+
if m:
|
| 55 |
+
parts.append(f"[MUSIC]{m}[END_MUSIC]")
|
| 56 |
+
if not parts:
|
| 57 |
+
# Unconditioned-ish prompt (FOG used spaces in all blocks)
|
| 58 |
+
return "[WORDS] [END_WORDS][AUDIO_CAPTION] [END_AUDIO_CAPTION][MUSIC] [END_MUSIC]"
|
| 59 |
+
return "".join(parts)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def probe_video(path: str) -> dict:
|
| 63 |
+
r = subprocess.run(
|
| 64 |
+
["ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", path],
|
| 65 |
+
capture_output=True,
|
| 66 |
+
text=True,
|
| 67 |
+
)
|
| 68 |
+
info = json.loads(r.stdout or "{}")
|
| 69 |
+
fmt = info.get("format", {})
|
| 70 |
+
streams = info.get("streams", [])
|
| 71 |
+
vs = next((s for s in streams if s.get("codec_type") == "video"), None)
|
| 72 |
+
if vs is None:
|
| 73 |
+
raise RuntimeError("No video stream found in the uploaded file.")
|
| 74 |
+
has_audio = any(s.get("codec_type") == "audio" for s in streams)
|
| 75 |
+
duration = float(fmt.get("duration") or vs.get("duration") or 0)
|
| 76 |
+
return {"duration": duration, "has_audio": has_audio}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def _make_base_cfg(sample_steps: int | None = None, seed: int | None = None):
|
| 80 |
+
from omegaconf import OmegaConf
|
| 81 |
+
|
| 82 |
+
cfg_path = REPO_DIR / "inference_v2st.yaml"
|
| 83 |
+
cfg = OmegaConf.load(str(cfg_path))
|
| 84 |
+
cfg.sp_size = 1
|
| 85 |
+
cfg.audio_only = True
|
| 86 |
+
cfg.cpu_offload = _env_flag("FOLEY_CPU_OFFLOAD", True)
|
| 87 |
+
cfg.fp8 = False
|
| 88 |
+
cfg.qint8 = _env_flag("FOLEY_QINT8", False if IS_ZEROGPU else False)
|
| 89 |
+
cfg.sample_steps = int(sample_steps if sample_steps is not None else SAMPLE_STEPS_DEFAULT)
|
| 90 |
+
if seed is not None:
|
| 91 |
+
cfg.seed = int(seed)
|
| 92 |
+
cfg.duration = 10.0
|
| 93 |
+
cfg.video_path = None
|
| 94 |
+
cfg.json_file = None
|
| 95 |
+
cfg.ckpt_dir = str(REPO_DIR / "ckpts")
|
| 96 |
+
cfg.model_checkpoint = str(REPO_DIR / "ckpts" / "Foley-Omni" / "v2st.pth")
|
| 97 |
+
return cfg
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
@contextlib.contextmanager
|
| 101 |
+
def _zerogpu_safe_cuda():
|
| 102 |
+
"""Prevent main-process CUDA init on ZeroGPU (fork worker requirement)."""
|
| 103 |
+
if not IS_ZEROGPU:
|
| 104 |
+
yield
|
| 105 |
+
return
|
| 106 |
+
import torch
|
| 107 |
+
|
| 108 |
+
saved = {}
|
| 109 |
+
for name in ("ipc_collect", "synchronize", "reset_peak_memory_stats"):
|
| 110 |
+
if hasattr(torch.cuda, name):
|
| 111 |
+
saved[name] = getattr(torch.cuda, name)
|
| 112 |
+
setattr(torch.cuda, name, lambda *a, **k: None)
|
| 113 |
+
try:
|
| 114 |
+
yield
|
| 115 |
+
finally:
|
| 116 |
+
for name, fn in saved.items():
|
| 117 |
+
setattr(torch.cuda, name, fn)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def _load_engine(sample_steps: int | None = None, seed: int | None = None) -> None:
|
| 121 |
+
import torch
|
| 122 |
+
|
| 123 |
+
if str(REPO_DIR) not in sys.path:
|
| 124 |
+
sys.path.insert(0, str(REPO_DIR))
|
| 125 |
+
os.chdir(REPO_DIR)
|
| 126 |
+
|
| 127 |
+
with _zerogpu_safe_cuda():
|
| 128 |
+
import inference_v2st as inf
|
| 129 |
+
|
| 130 |
+
if not inf.MMAUDIO_AVAILABLE:
|
| 131 |
+
raise RuntimeError("mmaudio modules could not be imported.")
|
| 132 |
+
|
| 133 |
+
cfg = _make_base_cfg(sample_steps=sample_steps, seed=seed)
|
| 134 |
+
inf._init_logging(0)
|
| 135 |
+
if not IS_ZEROGPU:
|
| 136 |
+
try:
|
| 137 |
+
torch.cuda.set_device(0)
|
| 138 |
+
except Exception as e:
|
| 139 |
+
print(f"[engine] set_device skipped: {e}", flush=True)
|
| 140 |
+
inf.initialize_sequence_parallel_state(1)
|
| 141 |
+
|
| 142 |
+
print(
|
| 143 |
+
f"[engine] loading engine cpu_offload={cfg.cpu_offload} steps={cfg.sample_steps} ...",
|
| 144 |
+
flush=True,
|
| 145 |
+
)
|
| 146 |
+
engine = inf.FoleyOmniEngine(config=cfg, device=0, target_dtype=torch.bfloat16)
|
| 147 |
+
print("[engine] loaded", flush=True)
|
| 148 |
+
_ENGINE.update(inf=inf, engine=engine, cfg=cfg)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def warmup() -> None:
|
| 152 |
+
if MODE != "inprocess" or _ENGINE["engine"] is not None or _ENGINE["failed"]:
|
| 153 |
+
return
|
| 154 |
+
try:
|
| 155 |
+
_load_engine()
|
| 156 |
+
except Exception:
|
| 157 |
+
import traceback
|
| 158 |
+
|
| 159 |
+
traceback.print_exc()
|
| 160 |
+
_ENGINE["failed"] = True
|
| 161 |
+
print("[engine] in-process load failed", flush=True)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _gpu(duration: int):
|
| 165 |
+
if IS_ZEROGPU:
|
| 166 |
+
import spaces
|
| 167 |
+
|
| 168 |
+
return spaces.GPU(duration=duration)
|
| 169 |
+
return lambda f: f
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def _generate_one_impl(video_path: str, prompt: str, sample_steps: int, seed: int):
|
| 173 |
+
import torch
|
| 174 |
+
|
| 175 |
+
inf, engine, cfg = _ENGINE["inf"], _ENGINE["engine"], _ENGINE["cfg"]
|
| 176 |
+
if engine is None:
|
| 177 |
+
raise RuntimeError("Model engine is not available inside the GPU worker.")
|
| 178 |
+
|
| 179 |
+
# Refresh tunable fields for this request
|
| 180 |
+
cfg.sample_steps = int(sample_steps)
|
| 181 |
+
cfg.seed = int(seed)
|
| 182 |
+
|
| 183 |
+
accurate, _ = inf.get_video_duration_accurate(video_path)
|
| 184 |
+
duration = float(accurate) if accurate and accurate > 0 else float(cfg.get("duration", 10.0))
|
| 185 |
+
apply_clip, apply_sync = inf._resolve_negative_video_feature_cfg(cfg)
|
| 186 |
+
|
| 187 |
+
try:
|
| 188 |
+
return inf.generate_audio_for_video(
|
| 189 |
+
foley_omni_engine=engine,
|
| 190 |
+
video_path=video_path,
|
| 191 |
+
text_prompt=prompt,
|
| 192 |
+
seed=int(seed),
|
| 193 |
+
solver_name=str(cfg.get("solver_name", "unipc")),
|
| 194 |
+
sample_steps=int(sample_steps),
|
| 195 |
+
shift=float(cfg.get("shift", 5.0)),
|
| 196 |
+
audio_guidance_scale=float(cfg.get("audio_guidance_scale", 5.0)),
|
| 197 |
+
slg_layer=int(cfg.get("slg_layer", 11)),
|
| 198 |
+
audio_negative_prompt=str(cfg.get("audio_negative_prompt", "")),
|
| 199 |
+
duration=duration,
|
| 200 |
+
cfg_apply_to_clip_features=apply_clip,
|
| 201 |
+
cfg_apply_to_sync_features=apply_sync,
|
| 202 |
+
device=0,
|
| 203 |
+
dtype=torch.bfloat16,
|
| 204 |
+
)
|
| 205 |
+
except inf.SkipShortVideoError as e:
|
| 206 |
+
raise ValueError(str(e)) from e
|
| 207 |
+
finally:
|
| 208 |
+
gc.collect()
|
| 209 |
+
try:
|
| 210 |
+
torch.cuda.empty_cache()
|
| 211 |
+
except Exception:
|
| 212 |
+
pass
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
@_gpu(ZEROGPU_DURATION)
|
| 216 |
+
def _generate_one(video_path: str, prompt: str, sample_steps: int, seed: int):
|
| 217 |
+
"""Runs on the ZeroGPU worker — load engine here so CUDA init stays in-worker."""
|
| 218 |
+
import traceback
|
| 219 |
+
|
| 220 |
+
try:
|
| 221 |
+
if _ENGINE["engine"] is None:
|
| 222 |
+
_load_engine(sample_steps=sample_steps, seed=seed)
|
| 223 |
+
elif _ENGINE["cfg"] is not None:
|
| 224 |
+
_ENGINE["cfg"].sample_steps = int(sample_steps)
|
| 225 |
+
_ENGINE["cfg"].seed = int(seed)
|
| 226 |
+
if _ENGINE["engine"] is None:
|
| 227 |
+
raise RuntimeError("Model engine failed to load inside the GPU worker.")
|
| 228 |
+
return ("ok", _generate_one_impl(video_path, prompt, sample_steps, seed))
|
| 229 |
+
except Exception:
|
| 230 |
+
tb = traceback.format_exc()
|
| 231 |
+
print("[gpu-worker] ERROR:\n" + tb, flush=True)
|
| 232 |
+
return ("err", tb)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def _write_wav(path: str, audio, sample_rate: int) -> None:
|
| 236 |
+
import numpy as np
|
| 237 |
+
|
| 238 |
+
a = np.clip(np.asarray(audio, dtype=np.float32), -1.0, 1.0)
|
| 239 |
+
pcm = (a * 32767.0).astype("<i2")
|
| 240 |
+
with wave.open(path, "wb") as w:
|
| 241 |
+
w.setnchannels(1)
|
| 242 |
+
w.setsampwidth(2)
|
| 243 |
+
w.setframerate(int(sample_rate))
|
| 244 |
+
w.writeframes(pcm.tobytes())
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _mux(video_path: str, wav_path: str, out_mp4: str) -> None:
|
| 248 |
+
r = subprocess.run(
|
| 249 |
+
[
|
| 250 |
+
"ffmpeg",
|
| 251 |
+
"-y",
|
| 252 |
+
"-i",
|
| 253 |
+
video_path,
|
| 254 |
+
"-i",
|
| 255 |
+
wav_path,
|
| 256 |
+
"-map",
|
| 257 |
+
"0:v:0",
|
| 258 |
+
"-map",
|
| 259 |
+
"1:a:0",
|
| 260 |
+
"-c:v",
|
| 261 |
+
"copy",
|
| 262 |
+
"-c:a",
|
| 263 |
+
"aac",
|
| 264 |
+
"-shortest",
|
| 265 |
+
out_mp4,
|
| 266 |
+
],
|
| 267 |
+
capture_output=True,
|
| 268 |
+
text=True,
|
| 269 |
+
)
|
| 270 |
+
if r.returncode != 0:
|
| 271 |
+
raise RuntimeError(f"ffmpeg mux failed:\n{(r.stderr or '')[-800:]}")
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def _cleanup_old_results(max_age_s: int = 3600) -> None:
|
| 275 |
+
import time
|
| 276 |
+
|
| 277 |
+
for f in glob.glob(os.path.join(tempfile.gettempdir(), "soundstage_result_*.mp4")):
|
| 278 |
+
try:
|
| 279 |
+
if time.time() - os.path.getmtime(f) > max_age_s:
|
| 280 |
+
os.remove(f)
|
| 281 |
+
except OSError:
|
| 282 |
+
pass
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def generate(
|
| 286 |
+
video_path: str,
|
| 287 |
+
words: str = "",
|
| 288 |
+
sfx: str = "",
|
| 289 |
+
music: str = "",
|
| 290 |
+
seed: int = 103,
|
| 291 |
+
sample_steps: int = 15,
|
| 292 |
+
progress=None,
|
| 293 |
+
) -> str:
|
| 294 |
+
if not video_path:
|
| 295 |
+
raise ValueError("Please upload a video first.")
|
| 296 |
+
|
| 297 |
+
info = probe_video(video_path)
|
| 298 |
+
if info["duration"] <= 0:
|
| 299 |
+
raise ValueError("Could not read video duration.")
|
| 300 |
+
if info["duration"] > MAX_VIDEO_SECONDS + 0.05:
|
| 301 |
+
raise ValueError(
|
| 302 |
+
f"This preview accepts videos up to {MAX_VIDEO_SECONDS:.0f}s "
|
| 303 |
+
f"(yours: {info['duration']:.1f}s)."
|
| 304 |
+
)
|
| 305 |
+
if info["duration"] < MIN_GEN_DURATION:
|
| 306 |
+
raise ValueError(f"Video is too short (need at least ~{MIN_GEN_DURATION:.0f}s).")
|
| 307 |
+
|
| 308 |
+
prompt = build_prompt(words, sfx, music)
|
| 309 |
+
_cleanup_old_results()
|
| 310 |
+
work = tempfile.mkdtemp(prefix="soundstage_")
|
| 311 |
+
try:
|
| 312 |
+
local_video = os.path.join(work, "input.mp4")
|
| 313 |
+
shutil.copy(video_path, local_video)
|
| 314 |
+
if info["has_audio"]:
|
| 315 |
+
muted = os.path.join(work, "input_muted.mp4")
|
| 316 |
+
r = subprocess.run(
|
| 317 |
+
["ffmpeg", "-y", "-i", local_video, "-c:v", "copy", "-an", muted],
|
| 318 |
+
capture_output=True,
|
| 319 |
+
text=True,
|
| 320 |
+
)
|
| 321 |
+
if r.returncode == 0:
|
| 322 |
+
local_video = muted
|
| 323 |
+
|
| 324 |
+
if progress:
|
| 325 |
+
progress(0.05, desc="Preparing model…")
|
| 326 |
+
|
| 327 |
+
with _GPU_LOCK:
|
| 328 |
+
# Non-ZeroGPU: preload in this process. ZeroGPU: load inside @_gpu worker.
|
| 329 |
+
if not IS_ZEROGPU:
|
| 330 |
+
if _ENGINE["engine"] is None and not _ENGINE["failed"]:
|
| 331 |
+
_load_engine(sample_steps=sample_steps, seed=seed)
|
| 332 |
+
elif _ENGINE["cfg"] is not None:
|
| 333 |
+
_ENGINE["cfg"].sample_steps = int(sample_steps)
|
| 334 |
+
_ENGINE["cfg"].seed = int(seed)
|
| 335 |
+
if _ENGINE["engine"] is None:
|
| 336 |
+
raise RuntimeError(
|
| 337 |
+
"Model failed to load. Check Space logs. "
|
| 338 |
+
"ZeroGPU Spaces need hardware set to ZeroGPU / A10G."
|
| 339 |
+
)
|
| 340 |
+
|
| 341 |
+
if progress:
|
| 342 |
+
progress(0.15, desc="Generating soundtrack (GPU)…")
|
| 343 |
+
|
| 344 |
+
status, payload = _generate_one(local_video, prompt, int(sample_steps), int(seed))
|
| 345 |
+
if status == "err":
|
| 346 |
+
raise RuntimeError("GPU step failed:\n" + str(payload)[-1200:])
|
| 347 |
+
audio = payload
|
| 348 |
+
|
| 349 |
+
sample_rate = 16000
|
| 350 |
+
if _ENGINE.get("cfg") is not None:
|
| 351 |
+
sample_rate = int(_ENGINE["cfg"].get("sample_rate", 16000))
|
| 352 |
+
wav_path = os.path.join(work, "out.wav")
|
| 353 |
+
_write_wav(wav_path, audio, sample_rate)
|
| 354 |
+
|
| 355 |
+
if progress:
|
| 356 |
+
progress(0.9, desc="Muxing video…")
|
| 357 |
+
|
| 358 |
+
fd, final_path = tempfile.mkstemp(suffix=".mp4", prefix="soundstage_result_")
|
| 359 |
+
os.close(fd)
|
| 360 |
+
_mux(local_video, wav_path, final_path)
|
| 361 |
+
|
| 362 |
+
if progress:
|
| 363 |
+
progress(1.0, desc="Done")
|
| 364 |
+
return final_path
|
| 365 |
+
finally:
|
| 366 |
+
shutil.rmtree(work, ignore_errors=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ZeroGPU-friendly torch stack (align with HF ZeroGPU PyTorch support)
|
| 2 |
+
torch==2.8.0
|
| 3 |
+
torchvision==0.23.0
|
| 4 |
+
torchaudio==2.8.0
|
| 5 |
+
|
| 6 |
+
gradio==5.49.1
|
| 7 |
+
spaces>=0.30.0
|
| 8 |
+
|
| 9 |
+
numpy==1.26.4
|
| 10 |
+
omegaconf==2.3.0
|
| 11 |
+
tqdm==4.67.3
|
| 12 |
+
pandas==2.3.3
|
| 13 |
+
|
| 14 |
+
av==17.0.0
|
| 15 |
+
moviepy==1.0.3
|
| 16 |
+
imageio==2.37.3
|
| 17 |
+
imageio-ffmpeg==0.6.0
|
| 18 |
+
Pillow==11.3.0
|
| 19 |
+
soundfile==0.13.1
|
| 20 |
+
scipy==1.15.3
|
| 21 |
+
librosa==0.11.0
|
| 22 |
+
pydub==0.25.1
|
| 23 |
+
|
| 24 |
+
diffusers==0.37.1
|
| 25 |
+
optimum-quanto==0.2.7
|
| 26 |
+
transformers==4.51.3
|
| 27 |
+
tokenizers==0.21.4
|
| 28 |
+
sentencepiece==0.2.1
|
| 29 |
+
safetensors==0.7.0
|
| 30 |
+
huggingface_hub>=0.30.0,<1.0
|
| 31 |
+
open-clip-torch==3.3.0
|
| 32 |
+
einops==0.8.2
|
| 33 |
+
ftfy==6.3.1
|
| 34 |
+
regex>=2024.0.0
|
| 35 |
+
colorlog==6.10.1
|
| 36 |
+
psutil==7.2.2
|
| 37 |
+
torch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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Prepare inference code + checkpoints for the Soundstage Space.
|
| 3 |
+
|
| 4 |
+
Modes:
|
| 5 |
+
1) Monorepo: if parent folder already has inference_v2st.py (this project), use it.
|
| 6 |
+
2) Standalone Space: clone Foley-Omni from GitHub, then download Hub weights.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
import subprocess
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
HERE = Path(__file__).resolve().parent
|
| 16 |
+
PARENT = HERE.parent
|
| 17 |
+
|
| 18 |
+
REPO_URL = os.getenv("FOLEY_REPO_URL", "https://github.com/SAIL-PRLab/Foley-Omni.git").strip()
|
| 19 |
+
REPO_COMMIT = os.getenv("FOLEY_COMMIT", "").strip()
|
| 20 |
+
WEIGHTS_REPO = os.getenv("FOLEY_WEIGHTS_REPO", "CocoBro/Foley-Omni").strip()
|
| 21 |
+
|
| 22 |
+
# When Space repo is only hf_space/*, code lives under vendor/
|
| 23 |
+
VENDOR_DIR = HERE / "vendor" / "Foley-Omni"
|
| 24 |
+
|
| 25 |
+
CKPT_FILES = [
|
| 26 |
+
"ckpts/Foley-Omni/v2st.pth",
|
| 27 |
+
"ckpts/Wan2.2-TI2V-5B/models_t5_umt5-xxl-enc-bf16.pth",
|
| 28 |
+
"ckpts/Wan2.2-TI2V-5B/google/umt5-xxl/special_tokens_map.json",
|
| 29 |
+
"ckpts/Wan2.2-TI2V-5B/google/umt5-xxl/spiece.model",
|
| 30 |
+
"ckpts/Wan2.2-TI2V-5B/google/umt5-xxl/tokenizer.json",
|
| 31 |
+
"ckpts/Wan2.2-TI2V-5B/google/umt5-xxl/tokenizer_config.json",
|
| 32 |
+
"ckpts/mmaudio/ext_weights/v1-16.pth",
|
| 33 |
+
"ckpts/mmaudio/ext_weights/best_netG.pt",
|
| 34 |
+
"ckpts/mmaudio/ext_weights/synchformer_state_dict.pth",
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
REPO_DIR: Path | None = None
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def resolve_repo_dir() -> Path:
|
| 41 |
+
global REPO_DIR
|
| 42 |
+
if REPO_DIR is not None:
|
| 43 |
+
return REPO_DIR
|
| 44 |
+
|
| 45 |
+
if (PARENT / "inference_v2st.py").is_file() and (PARENT / "foley_omni").is_dir():
|
| 46 |
+
REPO_DIR = PARENT
|
| 47 |
+
print(f"[setup] using monorepo at {REPO_DIR}")
|
| 48 |
+
return REPO_DIR
|
| 49 |
+
|
| 50 |
+
REPO_DIR = VENDOR_DIR
|
| 51 |
+
print(f"[setup] using vendor dir {REPO_DIR}")
|
| 52 |
+
return REPO_DIR
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _apply_patch(file_path: Path, old: str, new: str, label: str) -> None:
|
| 56 |
+
content = file_path.read_text(encoding="utf-8")
|
| 57 |
+
if new in content:
|
| 58 |
+
print(f"[patch] {label}: already patched")
|
| 59 |
+
return
|
| 60 |
+
if old not in content:
|
| 61 |
+
print(f"[patch] {label}: pattern not found — skipping (upstream may differ)")
|
| 62 |
+
return
|
| 63 |
+
file_path.write_text(content.replace(old, new), encoding="utf-8")
|
| 64 |
+
print(f"[patch] {label}: patched")
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def apply_zerogpu_patches(repo: Path) -> None:
|
| 68 |
+
"""Best-effort RAM / attention patches used by the working FOG Space."""
|
| 69 |
+
m = repo / "foley_omni"
|
| 70 |
+
if not m.is_dir():
|
| 71 |
+
return
|
| 72 |
+
|
| 73 |
+
_apply_patch(
|
| 74 |
+
m / "modules" / "t5.py",
|
| 75 |
+
old=""" # init model
|
| 76 |
+
model = umt5_xxl(
|
| 77 |
+
encoder_only=True,
|
| 78 |
+
return_tokenizer=False,
|
| 79 |
+
dtype=dtype,
|
| 80 |
+
device=device if not cpu_offload else "cpu").eval().requires_grad_(False)
|
| 81 |
+
logging.info(f'loading {checkpoint_path}')
|
| 82 |
+
model.load_state_dict(torch.load(checkpoint_path, map_location='cpu'))
|
| 83 |
+
self.model = model""",
|
| 84 |
+
new=""" # init model on the meta device (allocates no real memory yet)
|
| 85 |
+
model = umt5_xxl(
|
| 86 |
+
encoder_only=True,
|
| 87 |
+
return_tokenizer=False,
|
| 88 |
+
dtype=dtype,
|
| 89 |
+
device="meta").eval().requires_grad_(False)
|
| 90 |
+
logging.info(f'loading {checkpoint_path}')
|
| 91 |
+
try:
|
| 92 |
+
state_dict = torch.load(checkpoint_path, map_location='cpu', mmap=True, weights_only=True)
|
| 93 |
+
except Exception:
|
| 94 |
+
state_dict = torch.load(checkpoint_path, map_location='cpu')
|
| 95 |
+
model.load_state_dict(state_dict, assign=True)
|
| 96 |
+
del state_dict
|
| 97 |
+
target_device = device if not cpu_offload else "cpu"
|
| 98 |
+
model = model.to(target_device)
|
| 99 |
+
self.model = model""",
|
| 100 |
+
label="t5.py",
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
_apply_patch(
|
| 104 |
+
m / "fusion_engine.py",
|
| 105 |
+
old=""" logging.info(f"Loading model checkpoint from {checkpoint_path}")
|
| 106 |
+
checkpoint = torch.load(checkpoint_path, map_location="cpu")
|
| 107 |
+
if isinstance(checkpoint, dict) and "model" in checkpoint:""",
|
| 108 |
+
new=""" logging.info(f"Loading model checkpoint from {checkpoint_path}")
|
| 109 |
+
try:
|
| 110 |
+
checkpoint = torch.load(checkpoint_path, map_location="cpu", mmap=True, weights_only=True)
|
| 111 |
+
except Exception:
|
| 112 |
+
checkpoint = torch.load(checkpoint_path, map_location="cpu")
|
| 113 |
+
if isinstance(checkpoint, dict) and "model" in checkpoint:""",
|
| 114 |
+
label="fusion_engine.py",
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
imp_old = "from .attention import flash_attention"
|
| 118 |
+
imp_new = "from .attention import attention as flash_attention"
|
| 119 |
+
for rel in ("modules/model.py", "modules/clip.py", "modules/__init__.py"):
|
| 120 |
+
p = m / rel
|
| 121 |
+
if p.is_file():
|
| 122 |
+
_apply_patch(p, imp_old, imp_new, f"{rel} attention import")
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def clone_repo_if_needed(repo: Path) -> None:
|
| 126 |
+
if (repo / "inference_v2st.py").is_file():
|
| 127 |
+
print("[setup] inference code already present")
|
| 128 |
+
return
|
| 129 |
+
repo.parent.mkdir(parents=True, exist_ok=True)
|
| 130 |
+
if REPO_COMMIT:
|
| 131 |
+
subprocess.run(["git", "clone", REPO_URL, str(repo)], check=True)
|
| 132 |
+
subprocess.run(["git", "-C", str(repo), "checkout", REPO_COMMIT], check=True)
|
| 133 |
+
else:
|
| 134 |
+
subprocess.run(["git", "clone", "--depth", "1", REPO_URL, str(repo)], check=True)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def download_checkpoints(repo: Path) -> None:
|
| 138 |
+
missing = [f for f in CKPT_FILES if not (repo / f).is_file()]
|
| 139 |
+
if not missing:
|
| 140 |
+
print("[setup] checkpoints already present")
|
| 141 |
+
return
|
| 142 |
+
from huggingface_hub import snapshot_download
|
| 143 |
+
|
| 144 |
+
print(f"[setup] downloading {len(missing)} files from {WEIGHTS_REPO} ...")
|
| 145 |
+
token = os.getenv("HF_TOKEN") or os.getenv("HUGGING_FACE_HUB_TOKEN")
|
| 146 |
+
snapshot_download(
|
| 147 |
+
WEIGHTS_REPO,
|
| 148 |
+
local_dir=str(repo),
|
| 149 |
+
allow_patterns=CKPT_FILES,
|
| 150 |
+
token=token,
|
| 151 |
+
)
|
| 152 |
+
still = [f for f in CKPT_FILES if not (repo / f).is_file()]
|
| 153 |
+
if still:
|
| 154 |
+
raise RuntimeError(f"Checkpoint download incomplete: {still}")
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def ensure_ready() -> Path:
|
| 158 |
+
repo = resolve_repo_dir()
|
| 159 |
+
clone_repo_if_needed(repo)
|
| 160 |
+
apply_zerogpu_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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import url("https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Syne:wght@600;700;800&family=IBM+Plex+Sans:wght@400;500;600&display=swap");
|
| 2 |
+
|
| 3 |
+
:root {
|
| 4 |
+
--ink: #141c1a;
|
| 5 |
+
--ink-soft: #3a4743;
|
| 6 |
+
--muted: #6b7873;
|
| 7 |
+
--paper: #f3efe6;
|
| 8 |
+
--accent: #0c6b66;
|
| 9 |
+
--accent-deep: #084f4b;
|
| 10 |
+
--line: rgba(20, 28, 26, 0.14);
|
| 11 |
+
--panel: rgba(255, 252, 246, 0.82);
|
| 12 |
+
--danger: #a33b32;
|
| 13 |
+
--radius: 14px;
|
| 14 |
+
--font-brand: "Syne", sans-serif;
|
| 15 |
+
--font-display: "Instrument Serif", Georgia, serif;
|
| 16 |
+
--font-ui: "IBM Plex Sans", system-ui, sans-serif;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
html, body, .gradio-container {
|
| 20 |
+
font-family: var(--font-ui) !important;
|
| 21 |
+
color: var(--ink) !important;
|
| 22 |
+
background:
|
| 23 |
+
radial-gradient(900px 420px at 90% -10%, rgba(159, 213, 207, 0.45), transparent 60%),
|
| 24 |
+
radial-gradient(700px 380px at -5% 100%, rgba(232, 201, 154, 0.35), transparent 55%),
|
| 25 |
+
linear-gradient(145deg, #f7f3ea 0%, #ebe4d4 45%, #dce8e4 100%) !important;
|
| 26 |
+
min-height: 100vh;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
.gradio-container {
|
| 30 |
+
max-width: 920px !important;
|
| 31 |
+
margin: 0 auto !important;
|
| 32 |
+
padding: 1.5rem 1rem 3rem !important;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
footer, .svelte-1edrejj {
|
| 36 |
+
display: none !important;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/* Brand */
|
| 40 |
+
.ss-brand {
|
| 41 |
+
font-family: var(--font-brand) !important;
|
| 42 |
+
font-weight: 800 !important;
|
| 43 |
+
font-size: clamp(2.4rem, 7vw, 4rem) !important;
|
| 44 |
+
letter-spacing: -0.04em !important;
|
| 45 |
+
line-height: 0.95 !important;
|
| 46 |
+
margin: 0 0 0.75rem !important;
|
| 47 |
+
color: var(--ink) !important;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.ss-headline {
|
| 51 |
+
font-family: var(--font-display) !important;
|
| 52 |
+
font-size: clamp(1.8rem, 5vw, 2.8rem) !important;
|
| 53 |
+
font-weight: 400 !important;
|
| 54 |
+
letter-spacing: -0.02em !important;
|
| 55 |
+
margin: 0 0 0.5rem !important;
|
| 56 |
+
color: var(--ink) !important;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.ss-lede, .ss-fine {
|
| 60 |
+
color: var(--ink-soft) !important;
|
| 61 |
+
max-width: 36rem;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
.ss-fine {
|
| 65 |
+
font-size: 0.85rem !important;
|
| 66 |
+
color: var(--muted) !important;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.ss-panel {
|
| 70 |
+
background: var(--panel) !important;
|
| 71 |
+
border: 1px solid var(--line) !important;
|
| 72 |
+
border-radius: var(--radius) !important;
|
| 73 |
+
padding: 1.15rem !important;
|
| 74 |
+
box-shadow: 0 18px 50px rgba(20, 28, 26, 0.08) !important;
|
| 75 |
+
backdrop-filter: blur(12px);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.ss-section-title {
|
| 79 |
+
font-family: var(--font-display) !important;
|
| 80 |
+
font-size: 1.75rem !important;
|
| 81 |
+
margin: 0 0 0.35rem !important;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/* Controls */
|
| 85 |
+
button.primary, .ss-panel button.primary {
|
| 86 |
+
background: var(--accent) !important;
|
| 87 |
+
border: none !important;
|
| 88 |
+
color: #f7fffe !important;
|
| 89 |
+
font-weight: 600 !important;
|
| 90 |
+
border-radius: 9px !important;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
button.primary:hover {
|
| 94 |
+
background: var(--accent-deep) !important;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
button.secondary, button.stop {
|
| 98 |
+
border-radius: 9px !important;
|
| 99 |
+
border: 1px solid var(--line) !important;
|
| 100 |
+
background: rgba(255, 253, 248, 0.9) !important;
|
| 101 |
+
color: var(--ink) !important;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
input, textarea, .wrap, .block {
|
| 105 |
+
border-radius: 10px !important;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
label span, .label-wrap span {
|
| 109 |
+
font-size: 0.78rem !important;
|
| 110 |
+
font-weight: 600 !important;
|
| 111 |
+
letter-spacing: 0.04em !important;
|
| 112 |
+
text-transform: uppercase !important;
|
| 113 |
+
color: var(--ink-soft) !important;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
.ss-error {
|
| 117 |
+
color: var(--danger) !important;
|
| 118 |
+
font-size: 0.92rem !important;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.ss-topbar {
|
| 122 |
+
display: flex;
|
| 123 |
+
justify-content: space-between;
|
| 124 |
+
align-items: center;
|
| 125 |
+
gap: 1rem;
|
| 126 |
+
margin-bottom: 1.25rem;
|
| 127 |
+
padding-bottom: 0.85rem;
|
| 128 |
+
border-bottom: 1px solid var(--line);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.ss-topbar .ss-brand {
|
| 132 |
+
font-size: 1.2rem !important;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.ss-badge {
|
| 136 |
+
display: inline-block;
|
| 137 |
+
padding: 0.28rem 0.55rem;
|
| 138 |
+
border: 1px solid var(--line);
|
| 139 |
+
border-radius: 6px;
|
| 140 |
+
font-size: 0.7rem;
|
| 141 |
+
font-weight: 700;
|
| 142 |
+
letter-spacing: 0.08em;
|
| 143 |
+
text-transform: uppercase;
|
| 144 |
+
color: var(--accent-deep);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
@media (max-width: 640px) {
|
| 148 |
+
.gradio-container {
|
| 149 |
+
padding: 1rem 0.75rem 2rem !important;
|
| 150 |
+
}
|
| 151 |
+
.ss-topbar {
|
| 152 |
+
flex-direction: column;
|
| 153 |
+
align-items: flex-start;
|
| 154 |
+
}
|
| 155 |
+
}
|