EuropaLex / Dockerfile
Takosaga's picture
fix: remove build-time model download to fix HF Spaces build timeout
81c0e3c
Raw
History Blame Contribute Delete
3.09 kB
# EuropaLex β€” Docker / Hugging Face Spaces Deployment
# Single-stage build: CPU-only deps + Gradio launch.
# Models (~26 GB) are downloaded at runtime via app.py (_auto_download_models).
#
# Build (local, with token for gated models):
# docker build --secret id=hf_token,env=HUGGING_FACE_HUB_TOKEN -t europalex .
#
# Run (local test):
# docker run -p 7860:7860 europalex
FROM python:3.12-slim
# ─── System dependencies ───────────────────────────────────────────────
# git for huggingface-cli, build-essential for llama-cpp-python compilation
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# ─── Build secret: Hugging Face token ──────────────────────────────────
# Mounted at /run/secrets/hf_token during docker build.
# Used to authenticate huggingface-cli download of gated models.
RUN --mount=type=secret,id=hf_token \
if [ -f /run/secrets/hf_token ]; then \
echo "Authenticated as $(huggingface-cli whoami --token $(cat /run/secrets/hf_token) 2>/dev/null || echo 'unknown')"; \
else \
echo "WARNING: No HUGGING_FACE_HUB_TOKEN secret provided. Model download will fail for gated models."; \
fi
# ─── CPU-only PyTorch ──────────────────────────────────────────────────
# Install from the official CPU wheel index to avoid ~2 GB of CUDA deps.
RUN pip install --no-cache-dir \
--extra-index-url https://download.pytorch.org/whl/cpu \
torch>=2.1.0
# ─── llama-cpp-python (CPU-only build) ─────────────────────────────────
# LLAMA_CUDA=0 forces CPU-only compile, skipping GPU backend entirely.
# Without this, llama-cpp-python compiles from source for 15-30+ min with
# no output, appearing frozen on HF Spaces.
RUN LLAMA_CUDA=0 pip install --no-cache-dir \
llama-cpp-python>=0.3.28
# ─── Other Python dependencies ─────────────────────────────────────────
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# ─── Copy project source ───────────────────────────────────────────────
COPY . /app
WORKDIR /app
# ─── Models downloaded at runtime by app.py (_auto_download_models) ────
# Downloading ~26 GB of model weights at build time exceeds HF Spaces' timeout.
# The auto-download runs on first app start, keeping the build fast.
# ─── Launch ────────────────────────────────────────────────────────────
EXPOSE 7860
CMD ["python", "app.py"]