File size: 3,086 Bytes
11e477d
81c0e3c
 
11e477d
81c0e3c
11e477d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18c7533
 
 
 
 
11e477d
 
 
 
 
 
 
 
 
 
81c0e3c
 
 
11e477d
 
 
 
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
# 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"]