fix: define REPO_NAME in hf_upload.sh (ensure_blade_space referenced it)
Browse files- CLAUDE.md +1 -1
- app.py +23 -1
- formscout/config.py +5 -0
CLAUDE.md
CHANGED
|
@@ -170,7 +170,7 @@ Track the running sum in `MODEL_BUDGET.md`. The two Qwen3-VL-8B models share a b
|
|
| 170 |
|
| 171 |
The UI uses **Gradio `gr.Blocks`** with custom CSS/theme (`formscout/ui/theme.py`). Custom Svelte components for score dial, asymmetry bars, rubric drawer are planned for Phase 4. Use `gradio-svelte-expert` agent for Svelte component work.
|
| 172 |
|
| 173 |
-
- ZeroGPU:
|
| 174 |
- Verify Gradio APIs against current docs before use β pin exact versions in `requirements.txt`.
|
| 175 |
|
| 176 |
## Build phases
|
|
|
|
| 170 |
|
| 171 |
The UI uses **Gradio `gr.Blocks`** with custom CSS/theme (`formscout/ui/theme.py`). Custom Svelte components for score dial, asymmetry bars, rubric drawer are planned for Phase 4. Use `gradio-svelte-expert` agent for Svelte component work.
|
| 172 |
|
| 173 |
+
- ZeroGPU: `app.py`'s `process_video` (the Start Analysis handler) is decorated with `@spaces.GPU` (via the `gpu_task` shim, no-op off-Space) so one GPU window wraps the whole pipeline β pose, optional 3D, and the judge. **ZeroGPU aborts startup with "No @spaces.GPU function detected" unless a decorated function exists at import time**, so the decorator must stay at module level on a top-level function, not buried behind a lazy import. Window length is `config.ZEROGPU_DURATION` (default 120s, `FORMSCOUT_ZEROGPU_DURATION`).
|
| 174 |
- Verify Gradio APIs against current docs before use β pin exact versions in `requirements.txt`.
|
| 175 |
|
| 176 |
## Build phases
|
app.py
CHANGED
|
@@ -20,6 +20,23 @@ from formscout import config
|
|
| 20 |
from formscout import session as session_mod
|
| 21 |
from formscout.startup import ensure_checkpoints
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
ensure_checkpoints()
|
| 24 |
|
| 25 |
|
|
@@ -50,9 +67,14 @@ SCORE_DESCRIPTIONS = {
|
|
| 50 |
|
| 51 |
# βββ Processing ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 52 |
|
|
|
|
| 53 |
def process_video(video_path: str, test_name: str, side: str, model_key: str,
|
| 54 |
layers: list[str], session_state):
|
| 55 |
-
"""Analyse one clip and accumulate it into the screening session.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
if not video_path:
|
| 57 |
return (
|
| 58 |
session_state, _render_empty_state(), "Upload a video to begin analysis.",
|
|
|
|
| 20 |
from formscout import session as session_mod
|
| 21 |
from formscout.startup import ensure_checkpoints
|
| 22 |
|
| 23 |
+
# βββ ZeroGPU ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
+
# On an HF Spaces ZeroGPU runtime the heavy analysis MUST run inside an
|
| 25 |
+
# @spaces.GPU function, and that function must already exist at import time:
|
| 26 |
+
# ZeroGPU scans for one during startup and aborts the Space with
|
| 27 |
+
# "No @spaces.GPU function detected during startup" if none is registered.
|
| 28 |
+
# We decorate process_video (the Start Analysis handler) so a single GPU window
|
| 29 |
+
# covers the whole pipeline β pose, optional 3D, and the Qwen3-VL judge. Off a
|
| 30 |
+
# ZeroGPU Space the `spaces` package is absent (or its decorator is effect-free),
|
| 31 |
+
# so local runs and CPU Spaces are unaffected.
|
| 32 |
+
try:
|
| 33 |
+
import spaces
|
| 34 |
+
|
| 35 |
+
gpu_task = spaces.GPU(duration=config.ZEROGPU_DURATION)
|
| 36 |
+
except Exception: # local dev / non-ZeroGPU β decorate as a no-op
|
| 37 |
+
def gpu_task(fn):
|
| 38 |
+
return fn
|
| 39 |
+
|
| 40 |
ensure_checkpoints()
|
| 41 |
|
| 42 |
|
|
|
|
| 67 |
|
| 68 |
# βββ Processing ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 69 |
|
| 70 |
+
@gpu_task
|
| 71 |
def process_video(video_path: str, test_name: str, side: str, model_key: str,
|
| 72 |
layers: list[str], session_state):
|
| 73 |
+
"""Analyse one clip and accumulate it into the screening session.
|
| 74 |
+
|
| 75 |
+
Decorated with @spaces.GPU on ZeroGPU: the whole pipeline (pose, optional 3D,
|
| 76 |
+
Qwen3-VL judge) runs inside one GPU window. The decorator is a no-op off-Space.
|
| 77 |
+
"""
|
| 78 |
if not video_path:
|
| 79 |
return (
|
| 80 |
session_state, _render_empty_state(), "Upload a video to begin analysis.",
|
formscout/config.py
CHANGED
|
@@ -152,6 +152,11 @@ JUDGE_BACKEND = os.environ.get("FORMSCOUT_JUDGE_BACKEND", "auto")
|
|
| 152 |
JUDGE_HF_MODEL = os.environ.get("FORMSCOUT_JUDGE_HF_MODEL", "Qwen/Qwen3-VL-8B-Instruct")
|
| 153 |
ON_HF_SPACE = bool(os.environ.get("SPACE_ID"))
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
def has_gpu() -> bool:
|
| 157 |
"""True on a ZeroGPU Space (env flag) or when CUDA is actually present.
|
|
|
|
| 152 |
JUDGE_HF_MODEL = os.environ.get("FORMSCOUT_JUDGE_HF_MODEL", "Qwen/Qwen3-VL-8B-Instruct")
|
| 153 |
ON_HF_SPACE = bool(os.environ.get("SPACE_ID"))
|
| 154 |
|
| 155 |
+
# Seconds the ZeroGPU window stays allocated per analysis. One window wraps the
|
| 156 |
+
# whole pipeline (pose, optional 3D, Qwen3-VL judge), so size it for the slowest
|
| 157 |
+
# clip; raise via env for long videos. Only effective on a ZeroGPU Space.
|
| 158 |
+
ZEROGPU_DURATION = int(os.environ.get("FORMSCOUT_ZEROGPU_DURATION", "120"))
|
| 159 |
+
|
| 160 |
|
| 161 |
def has_gpu() -> bool:
|
| 162 |
"""True on a ZeroGPU Space (env flag) or when CUDA is actually present.
|