File size: 2,384 Bytes
76adb1b
 
 
5fbcecf
76adb1b
 
 
 
 
5d05066
69a751d
76adb1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4da6bd3
14d8a56
76adb1b
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
58
59
# SheetSage2 needs Python 3.10/3.11 and FFmpeg 6.1 with shared libs.
# Ubuntu 24.04 ships FFmpeg 6.1.x; Python 3.11 comes from deadsnakes.
FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    HOME=/home/user \
    HF_HOME=/home/user/.cache/huggingface \
    PATH=/opt/venv/bin:$PATH

RUN apt-get update && apt-get install -y --no-install-recommends \
      software-properties-common ca-certificates curl git gnupg unzip \
 && add-apt-repository -y ppa:deadsnakes/ppa \
 && apt-get update && apt-get install -y --no-install-recommends \
      python3.11 python3.11-venv python3.11-dev build-essential \
      ffmpeg libsndfile1 fluidsynth fonts-dejavu-core \
 && rm -rf /var/lib/apt/lists/*

# Deno: yt-dlp needs an external JavaScript runtime for YouTube.
# Installed to /usr/local/bin so yt-dlp finds it on PATH.
RUN curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local sh \
 && deno --version

# HF Spaces runs the container as uid 1000. Ubuntu 24.04 already has an
# "ubuntu" user with that uid, so remove it first.
RUN userdel -r ubuntu 2>/dev/null || true \
 && useradd -m -u 1000 -s /bin/bash user \
 && python3.11 -m venv /opt/venv

WORKDIR /home/user/app

# CPU-only torch (swap the index to .../whl/cu126 if you use a GPU Space).
# yt-dlp[default] includes yt-dlp-ejs, which works together with Deno.
RUN pip install --no-cache-dir --upgrade pip \
 && pip install --no-cache-dir torch==2.8.0 torchaudio==2.8.0 \
      --index-url https://download.pytorch.org/whl/cpu \
 && pip install --no-cache-dir huggingface-hub==0.36.0 "gradio>=5,<6" "yt-dlp[default]"

# Download the model repo + MERT parent at build time.
# Needs a Space secret named HF_TOKEN (Settings -> Variables and secrets).
COPY download_models.py .
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=false \
    HF_TOKEN="$(cat /run/secrets/HF_TOKEN 2>/dev/null || true)" \
    python download_models.py

# Repo's own requirements (torch is already satisfied above).
RUN pip install --no-cache-dir -r /home/user/SheetSage2/requirements.txt

# Sheet-music / piano-audio rendering tools. Runs as root with HOME=/home/user
# so anything it caches lands where the runtime user can read it.
RUN cd /home/user/SheetSage2 && python setup_render.py --with-deps

COPY app.py .

RUN chown -R user:user /home/user /opt/venv
USER user

EXPOSE 7860
CMD ["python", "app.py"]