MA commited on
Commit
a65104d
Β·
1 Parent(s): 6184230

fix: dockerfile librairies again

Browse files
Files changed (1) hide show
  1. Dockerfile +63 -24
Dockerfile CHANGED
@@ -1,36 +1,75 @@
1
- FROM python:3.10-slim
 
 
 
 
2
 
3
- WORKDIR /app
4
 
5
- # ── System dependencies ───────────────────────────────────────────────────────
 
 
 
6
  RUN apt-get update && apt-get install -y --no-install-recommends \
7
- git \
8
- ffmpeg \
9
- build-essential \
10
- pkg-config \
11
- libavformat-dev \
12
- libavcodec-dev \
13
- libswscale-dev \
 
 
 
 
14
  && rm -rf /var/lib/apt/lists/*
15
 
16
- # ── Python: torch first (CPU build, works on Render's free/standard tier) ─────
17
- # Swap the index URL for a CUDA build if you ever add a GPU service on Render.
 
 
 
 
 
18
  RUN pip install --no-cache-dir \
19
- torch torchaudio --index-url https://download.pytorch.org/whl/cpu
 
 
20
 
21
- # ── Python: audiocraft + flask ────────────────────────────────────────────────
22
- RUN pip install --upgrade pip \
23
- && pip install --no-cache-dir audiocraft flask
 
 
 
 
 
 
24
 
25
- # ── App code ──────────────────────────────────────────────────────────────────
 
 
 
 
 
 
 
 
 
26
  COPY app.py index.html ./
27
 
28
- # ── Model cache directory (matches the Render persistent disk mount path) ─────
29
- # The disk is mounted at /data; HF will read/write models there so they
30
- # survive container restarts and don't need to re-download every deploy.
31
- ENV HF_HOME=/data/huggingface
 
 
 
 
 
 
 
32
 
33
- # Render injects $PORT at runtime; default to 10000 to match Render's standard
34
- EXPOSE 10000
35
 
36
- CMD ["python", "app.py"]
 
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # SAMPLE GENERATOR β€” Dockerfile
3
+ # Flask + Meta MusicGen (audiocraft)
4
+ # Compatible with: HuggingFace Spaces (Docker SDK), Render, local Docker
5
+ # ────────────────────────────────────────────── ───────────────────────────────
6
 
7
+ FROM python:3.11-slim
8
 
9
+ # ── System deps ───────────────────────────────────────────────────────────────
10
+ # ffmpeg β†’ audio encoding/decoding used by torchaudio & audiocraft
11
+ # libsndfile1 β†’ soundfile I/O backend
12
+ # git β†’ audiocraft may pull sub-packages from git at install time
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
+ ffmpeg \
15
+ libavformat-dev \
16
+ libavcodec-dev \
17
+ libavdevice-dev \
18
+ libavutil-dev \
19
+ libavfilter-dev \
20
+ libswscale-dev \
21
+ libswresample-dev \
22
+ libsndfile1 \
23
+ git \
24
+ pkg-config \
25
  && rm -rf /var/lib/apt/lists/*
26
 
27
+ # ── Create a non-root user (required by HuggingFace Spaces) ──────────────────
28
+ RUN useradd -m -u 1000 appuser
29
+
30
+ WORKDIR /app
31
+
32
+ # ── Install PyTorch (CPU-only) first, before audiocraft pulls its own copy ───
33
+ # Using the official CPU wheel index keeps the image ~2 GB smaller than CUDA.
34
  RUN pip install --no-cache-dir \
35
+ torch==2.1.0 \
36
+ torchaudio==2.1.0 \
37
+ --index-url https://download.pytorch.org/whl/cpu
38
 
39
+ # ── Stub out xformers ─────────────────────────────────────────────────────────
40
+ # xformers has no CPU-only pre-built wheel and fails to compile from source
41
+ # (it needs CUDA). audiocraft lists it as a dependency but MusicGen inference
42
+ # works fine without it on CPU. We install a minimal stub so pip's resolver
43
+ # sees the requirement as satisfied and skips the source build entirely.
44
+ RUN mkdir -p /tmp/xformers-stub && \
45
+ echo "from setuptools import setup; setup(name='xformers', version='0.0.28.post1')" \
46
+ > /tmp/xformers-stub/setup.py && \
47
+ pip install --no-cache-dir /tmp/xformers-stub
48
 
49
+ # ── Install remaining Python deps ─────────────────────────────────────────────
50
+ # --extra-index-url ensures pip can still find CPU wheels for any torch-related
51
+ # packages pulled in transitively by audiocraft, preventing it from silently
52
+ # upgrading torch to a CUDA build from the default PyPI index.
53
+ COPY requirements.txt .
54
+ RUN pip install --no-cache-dir \
55
+ --extra-index-url https://download.pytorch.org/whl/cpu \
56
+ -r requirements.txt
57
+
58
+ # ── Copy application source ───────────────────────────────────────────────────
59
  COPY app.py index.html ./
60
 
61
+ # ── Runtime environment ───────────────────────────────────────────────────────
62
+ # HF_HOME: store downloaded model weights in a predictable location.
63
+ # On Render, mount a persistent disk at /data to avoid re-downloading on restart.
64
+ ENV HF_HOME=/data/huggingface \
65
+ PORT=7860
66
+
67
+ # Ensure the cache dir is writable by the non-root user even when /data is
68
+ # not mounted (e.g. plain `docker run` without a volume).
69
+ RUN mkdir -p /data/huggingface && chown -R appuser:appuser /data /app
70
+
71
+ USER appuser
72
 
73
+ EXPOSE 7860
 
74
 
75
+ CMD ["python", "app.py"]