BeatNet-dual / Dockerfile
ellagranger's picture
Change to subprocess
b6f3797
Raw
History Blame Contribute Delete
2.31 kB
# Hugging Face Spaces dual-interpreter template for BeatNet.
#
# - Python 3.10 frontend: Gradio / pyharp app, listening on $PORT.
# - Python 3.9 backend: BeatNet + madmom worker, isolated in its own venv.
# - IPC: JSON-over-Unix-domain-socket; audio is passed by file path.
FROM python:3.10-slim-bullseye
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=UTF-8 \
PIP_NO_BUILD_ISOLATION=1 \
FRONTEND_VENV=/opt/frontend-py310 \
BACKEND_VENV=/opt/backend-py39 \
BACKEND_PYTHON=/opt/backend-py39/bin/python \
BACKEND_SCRIPT=/app/backend_worker.py \
PORT=7860
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
git \
libasound2-dev \
portaudio19-dev \
python3.9 \
python3.9-dev \
python3.9-distutils \
python3.9-venv \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Backend uses Debian Bullseye's Python 3.9 interpreter for BeatNet/madmom.
# madmom is installed unpatched because the Space no longer runs it under 3.10+.
COPY requirements-backend-py39.txt /tmp/requirements-backend-py39.txt
RUN /usr/bin/python3.9 -m venv "$BACKEND_VENV" \
&& "$BACKEND_VENV/bin/pip" install --no-cache-dir -U pip wheel "Cython<3" \
&& "$BACKEND_VENV/bin/pip" install --no-cache-dir setuptools==80.9.0 \
&& "$BACKEND_VENV/bin/pip" install --no-cache-dir -r /tmp/requirements-backend-py39.txt \
&& "$BACKEND_VENV/bin/pip" install --no-cache-dir --no-build-isolation --no-deps madmom \
&& "$BACKEND_VENV/bin/pip" install --no-cache-dir --no-build-isolation --no-deps BeatNet \
&& "$BACKEND_VENV/bin/python" -c "import numpy; import madmom.audio.comb_filters; from BeatNet.BeatNet import BeatNet; print('backend import check ok', numpy.__version__)"
# Frontend uses the base image's Python 3.10 interpreter for Gradio/pyharp.
COPY requirements-frontend-py310.txt /tmp/requirements-frontend-py310.txt
RUN /usr/local/bin/python3.10 -m venv "$FRONTEND_VENV" \
&& "$FRONTEND_VENV/bin/pip" install --no-cache-dir -U pip wheel \
&& "$FRONTEND_VENV/bin/pip" install --no-cache-dir -r /tmp/requirements-frontend-py310.txt
COPY backend_worker.py frontend_app.py start.sh ./
RUN chmod +x /app/start.sh
EXPOSE 7860
CMD ["/app/start.sh"]