File size: 2,439 Bytes
fe19082
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5de1ad5
 
 
 
fe19082
 
22b320d
 
 
 
 
fe19082
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# PiedPiper — Hugging Face Space (Docker SDK).
#
# Build target: free CPU Basic Space (16 GB RAM / 2 vCPU). The CLAP checkpoint
# is pre-pulled at build time so the first request after a cold wake isn't ~30 s.
# The 160-track reference corpus is baked in so /neighbors works from the first
# request — no separate volume mount needed.
#
# This Dockerfile expects a flat build context populated by `deploy/sync_to_hf.sh`:
#   <staging>/Dockerfile
#   <staging>/README.md           (HF Space metadata + docs)
#   <staging>/app.py              (uvicorn entrypoint, re-exports backend.api:app)
#   <staging>/requirements.txt
#   <staging>/backend/...         (the backend Python package)
#   <staging>/corpus/...          (mean + segment embeddings + eval.json)
#   <staging>/eval_audio/...      (named-example previews)
#
# Image footprint is ~5–6 GB once weights are baked in; HF allows this on free tier.

FROM python:3.11-slim

# Audio decode + DSP shared libs librosa+soundfile need.
RUN apt-get update && apt-get install -y --no-install-recommends \
    libsndfile1 ffmpeg \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# CPU torch from the official wheel index — avoids pulling CUDA wheels.
RUN pip install --no-cache-dir torch>=2.4 --index-url https://download.pytorch.org/whl/cpu

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY backend /app/backend
COPY app.py /app/app.py

# The backend's _default_corpus_dir resolves to /app/quality-scorer/public/corpus
# at runtime — copy the files there rather than setting CORPUS_DIR so the default
# path keeps working.
COPY corpus /app/quality-scorer/public/corpus
COPY eval_audio /app/quality-scorer/public/eval_audio

# ADR-0002: pre-pull MuQ-MuLan weights at build time so the first /neighbors
# after a cold wake doesn't have to download ~2.8 GB. The pre-pull also caches
# the XLM-RoBERTa text encoder MuQ-MuLan depends on.
RUN python -c "from muq import MuQMuLan; MuQMuLan.from_pretrained('OpenMuQ/MuQ-MuLan-large')"

ENV PORT=7860 HF_HOME=/app/.hf_cache
# The corpus copy target above is /app/quality-scorer/public/corpus. The
# Python default would resolve to /quality-scorer/public/corpus inside the
# flattened container layout (parents[2] of /app/backend/api.py is /, not /app),
# so override explicitly.
ENV CORPUS_DIR=/app/quality-scorer/public/corpus
EXPOSE 7860

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]