Spaces:
Sleeping
Sleeping
File size: 3,092 Bytes
1294b5d 1a6d560 1294b5d 1a6d560 1294b5d 1a6d560 1294b5d 1a6d560 1294b5d 1a6d560 1294b5d 1a6d560 1294b5d 1a6d560 1294b5d 1a6d560 1294b5d 1a6d560 1294b5d | 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 59 60 61 62 63 64 | # ============================================================
# PolicyPilot β Hugging Face Spaces Docker Image
# Base: python:3.10-slim (Debian Bullseye)
# Port: 7860 (mandatory for HF Spaces)
# ============================================================
# Python 3.10 matches the local dev environment (locks away
# any silent 3.11 incompatibilities in Docling / PyTorch deps)
FROM python:3.10-slim
# ββ System packages βββββββββββββββββββββββββββββββββββββββββ
# Docling needs:
# - libgl1 + libglib2.0-0 : OpenCV (used by docling's vision pipeline)
# - libgomp1 : OpenMP runtime (PyTorch parallel ops)
# - poppler-utils : pdfinfo / pdftotext fallback
# - tesseract-ocr : OCR fallback when Docling model is unavailable
# - curl : health-check / debugging utility
# build-essential is NOT needed β we only install pre-built wheels
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
libgomp1 \
poppler-utils \
tesseract-ocr \
curl \
&& rm -rf /var/lib/apt/lists/*
# ββ Non-root user (required by Hugging Face Spaces) βββββββββ
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
# Silence HuggingFace symlink warnings on read-only FS
HF_HUB_DISABLE_SYMLINKS_WARNING=1 \
# Keep Python output unbuffered so logs appear in real time
PYTHONUNBUFFERED=1
# ββ Working directory ββββββββββββββββββββββββββββββββββββββββ
WORKDIR $HOME/app
# ββ Install dependencies (layered for cache efficiency) βββββ
# Copy ONLY the requirement files first β Docker will cache
# this layer and skip re-installing packages on every code push.
COPY --chown=user backend/requirements.txt ./requirements.txt
COPY --chown=user backend/requirements-docling.txt ./requirements-docling.txt
# Core dependencies first (fast), then Docling (slow, ~2 GB)
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt \
&& pip install --no-cache-dir -r requirements-docling.txt
# ββ Copy application source ββββββββββββββββββββββββββββββββββ
# Done AFTER pip install so code changes don't bust the cache
COPY --chown=user backend/ ./
# ββ Port βββββββββββββββββββββββββββββββββββββββββββββββββββββ
EXPOSE 7860
# ββ Boot βββββββββββββββββββββββββββββββββββββββββββββββββββββ
# --workers 1 : single worker avoids in-memory state sharding
# (active_ruleset is stored in Python module state)
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
|