EYEDOL commited on
Commit
5869d53
Β·
verified Β·
1 Parent(s): 71f2d36

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +59 -0
Dockerfile ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Dockerfile for HuggingFace Spaces (Docker SDK)
3
+ #
4
+ # Hardware target: CPU Space (free tier) or GPU Space (T4-small recommended).
5
+ # Port 7860 is the HF Spaces standard.
6
+ #
7
+ # Build order:
8
+ # 1. System deps (libsndfile for soundfile, git for pip installs)
9
+ # 2. Python packages (cached layer)
10
+ # 3. App code (invalidates only on source changes)
11
+ # 4. Switch to non-root user (HF Spaces requirement)
12
+ # ─────────────────────────────────────────────────────────────────────────────
13
+
14
+ FROM python:3.11-slim
15
+
16
+ WORKDIR /app
17
+
18
+ # ── System dependencies ───────────────────────────────────────────────────── #
19
+ RUN apt-get update && apt-get install -y --no-install-recommends \
20
+ libsndfile1 \
21
+ libgomp1 \
22
+ git \
23
+ && rm -rf /var/lib/apt/lists/*
24
+
25
+ # ── Python dependencies (cached unless requirements.txt changes) ──────────── #
26
+ COPY requirements.txt .
27
+
28
+ # Install CPU-only torch first (saves ~1 GB over default CUDA wheel).
29
+ # Comment these two lines out and use the plain pip install if you have a GPU Space.
30
+ RUN pip install --no-cache-dir \
31
+ torch==2.5.1+cpu torchaudio==2.5.1+cpu \
32
+ --index-url https://download.pytorch.org/whl/cpu
33
+
34
+ RUN pip install --no-cache-dir -r requirements.txt
35
+
36
+ # ── Application code ─────────────────────────────────────────────────────── #
37
+ COPY . .
38
+
39
+ # ── Non-root user for HF Spaces compatibility ─────────────────────────────── #
40
+ RUN useradd -m -u 1000 appuser \
41
+ && chown -R appuser:appuser /app
42
+ USER 1000
43
+
44
+ # ── Model cache lives in the user home so HF Spaces can persist it ────────── #
45
+ ENV HF_HOME=/home/appuser/.cache/huggingface
46
+ ENV PORT=7860
47
+
48
+ EXPOSE 7860
49
+
50
+ # ── Healthcheck ───────────────────────────────────────────────────────────── #
51
+ HEALTHCHECK --interval=60s --timeout=10s --start-period=300s \
52
+ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')"
53
+
54
+ CMD ["python", "-m", "uvicorn", "app:app", \
55
+ "--host", "0.0.0.0", \
56
+ "--port", "7860", \
57
+ "--log-level", "info", \
58
+ "--ws-ping-interval", "30", \
59
+ "--ws-ping-timeout", "60"]