Spaces:
Running
Running
vaibuzz
feat: production-ready deployment β Dockerfile, schema fixes, PCT_DIFF logic, abs() resolver
1294b5d | # ============================================================ | |
| # 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"] | |