Spaces:
Sleeping
title: BeatNet Dual
emoji: 🌖
colorFrom: red
colorTo: blue
sdk: docker
pinned: false
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
BeatNet dual-Python Hugging Face Space template
This directory is a copy-ready solution for a Hugging Face Docker Space that needs two Python interpreters in one container:
- Frontend: Python 3.10 virtual environment for Gradio / pyharp.
- Backend: Python 3.9 virtual environment for BeatNet and madmom.
- Transport: on-demand Python 3.9 subprocess calls, with uploaded audio passed as a file path. This avoids importing BeatNet/madmom in the frontend interpreter without keeping a backend process alive.
The public teamup-tech/BeatNet Space currently uses a single
python:3.10-slim Docker image and starts app.py directly. Replace that setup
with these files, or adapt the same pattern in-place.
File map
| File | Purpose |
|---|---|
Dockerfile |
Builds separate Python 3.9 and 3.10 virtual environments. |
requirements-backend-py39.txt |
BeatNet/madmom dependencies only. |
requirements-frontend-py310.txt |
Gradio/pyharp dependencies only. |
backend_worker.py |
One-shot BeatNet subprocess runner under Python 3.9. |
frontend_app.py |
Gradio app running under Python 3.10. |
start.sh |
Starts the frontend. |
Why a subprocess instead of importing both stacks?
madmom and BeatNet can be sensitive to Python, NumPy, Cython, and build
isolation versions. Running BeatNet/madmom in a backend-only Python 3.9
environment avoids the madmom compatibility patching needed by newer Python
versions, while the public web layer runs independently on Python 3.10. The
frontend invokes the backend script only when processing audio:
/opt/backend-py39/bin/python /app/backend_worker.py /tmp/gradio/upload.wav
The backend prints stable JSON to stdout:
{"ok": true, "beats": [{"time": 0.42, "beat": 1.0}]}
Hugging Face Space usage
- Copy every file in this directory to the root of the BeatNet Space.
- Do not copy or run
patch_madmom.py; the backend stays on Python 3.9 so madmom can be installed without the Python 3.10+ patch. - Add any project-specific frontend packages to
requirements-frontend-py310.txtand backend packages torequirements-backend-py39.txt. - Push to the Space. Hugging Face will build the Docker image and route traffic
to
PORT=7860.
Alternative: persistent worker transport
If startup latency becomes a problem, keep the same two virtual environments and
run backend_worker.py as a long-lived process behind a Unix socket or file
queue. The subprocess approach uses less idle memory, while a persistent worker
can reuse the loaded BeatNet model across requests.