# ── Base image ──────────────────────────────────────────────────────────────── # Use Python 3.10 slim; HF free CPU spaces have ~16 GB RAM FROM python:3.10-slim # ── System deps ─────────────────────────────────────────────────────────────── RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ libgl1 \ && rm -rf /var/lib/apt/lists/* # ── Working dir ─────────────────────────────────────────────────────────────── WORKDIR /app # ── Python deps (cached layer) ──────────────────────────────────────────────── COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # ── Pre-download the model during build (avoids cold-start timeout) ─────────── # HF Spaces has no outbound rate limit during Docker build. RUN python - <<'EOF' from transformers import TrOCRProcessor, VisionEncoderDecoderModel TrOCRProcessor.from_pretrained("microsoft/trocr-large-handwritten") VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-large-handwritten") print("Model cached successfully.") EOF # ── Copy source ─────────────────────────────────────────────────────────────── COPY app.py . # ── HF Spaces requires the app to listen on port 7860 ──────────────────────── EXPOSE 7860 # ── Run ─────────────────────────────────────────────────────────────────────── CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]