# ─────────────────────────────────────────────────────────── # Dockerfile for Hugging Face Spaces (Docker SDK) — full ML stack. # 16GB RAM on the free tier comfortably runs the CryptoBERT ensemble. # HF Spaces serve on port 7860. # ─────────────────────────────────────────────────────────── FROM python:3.11-slim # System deps (build tools for some wheels) RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential curl && rm -rf /var/lib/apt/lists/* # Non-root user (HF Spaces convention) + writable home RUN useradd -m -u 1000 user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ HF_HOME=/home/user/.cache/huggingface \ DB_PATH=/home/user/app/narrative_analysis.db \ PYTHONUNBUFFERED=1 WORKDIR /home/user/app # Install Python deps (core + full ML) as the user COPY --chown=user requirements.txt requirements-ml.txt ./ RUN pip install --no-cache-dir --user -r requirements.txt -r requirements-ml.txt # Pre-download models at build time so the first request is fast RUN python -c "from huggingface_hub import snapshot_download; snapshot_download('ElKulako/cryptobert')" || true RUN python -m spacy download en_core_web_sm || true # App code COPY --chown=user . . # Ensure the whole home (app dir, caches) is writable by the runtime user RUN chown -R user:user /home/user USER user EXPOSE 7860 CMD ["python", "-m", "uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]