Takosaga commited on
Commit
11e477d
Β·
1 Parent(s): c958b0b

feat: add Dockerfile for HF Spaces deployment (CPU-only)

Browse files
Files changed (1) hide show
  1. Dockerfile +59 -0
Dockerfile ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # EuropaLex β€” Docker / Hugging Face Spaces Deployment
2
+ # Single-stage build: CPU-only deps + model download + Gradio launch
3
+ #
4
+ # Build:
5
+ # docker build --secret id=hf_token,env=HUGGING_FACE_HUB_TOKEN -t europalex .
6
+ #
7
+ # Run (local test):
8
+ # docker run -p 7860:7860 europalex
9
+
10
+ FROM python:3.12-slim
11
+
12
+ # ─── System dependencies ───────────────────────────────────────────────
13
+ # git for huggingface-cli, build-essential for llama-cpp-python compilation
14
+ RUN apt-get update && apt-get install -y --no-install-recommends \
15
+ git \
16
+ build-essential \
17
+ && rm -rf /var/lib/apt/lists/*
18
+
19
+ # ─── Build secret: Hugging Face token ──────────────────────────────────
20
+ # Mounted at /run/secrets/hf_token during docker build.
21
+ # Used to authenticate huggingface-cli download of gated models.
22
+ RUN --mount=type=secret,id=hf_token \
23
+ if [ -f /run/secrets/hf_token ]; then \
24
+ echo "Authenticated as $(huggingface-cli whoami --token $(cat /run/secrets/hf_token) 2>/dev/null || echo 'unknown')"; \
25
+ else \
26
+ echo "WARNING: No HUGGING_FACE_HUB_TOKEN secret provided. Model download will fail for gated models."; \
27
+ fi
28
+
29
+ # ─── CPU-only PyTorch ──────────────────────────────────────────────────
30
+ # Install from the official CPU wheel index to avoid ~2 GB of CUDA deps.
31
+ RUN pip install --no-cache-dir \
32
+ --extra-index-url https://download.pytorch.org/whl/cpu \
33
+ torch>=2.1.0
34
+
35
+ # ─── llama-cpp-python (CPU backend, no CUDA flags) ─────────────────────
36
+ # Build with default CPU backend β€” no CUDA/MKL flags needed on slim base.
37
+ RUN pip install --no-cache-dir \
38
+ llama-cpp-python>=0.3.28
39
+
40
+ # ─── Other Python dependencies ─────────────────────────────────────────
41
+ COPY requirements.txt .
42
+ RUN pip install --no-cache-dir -r requirements.txt
43
+
44
+ # ─── Copy project source ───────────────────────────────────────────────
45
+ COPY . /app
46
+ WORKDIR /app
47
+
48
+ # ─── Download models at build time ─────────────────────────────────────
49
+ # Uses the HF token secret for authenticated downloads.
50
+ # Models are baked into the image (~26 GB total).
51
+ RUN --mount=type=secret,id=hf_token \
52
+ if [ -f /run/secrets/hf_token ]; then \
53
+ export HUGGING_FACE_HUB_TOKEN=$(cat /run/secrets/hf_token); \
54
+ fi && \
55
+ python -m models.download_models
56
+
57
+ # ─── Launch ────────────────────────────────────────────────────────────
58
+ EXPOSE 7860
59
+ CMD ["python", "app.py"]