# ── GLM-OCR — Dockerfile (Hugging Face Spaces) ──────────────────────────── # # HF Spaces builds this automatically when you push to your Space repo. # No local Docker needed — HF handles the build and hosting. # ────────────────────────────────────────────────────────────────────────── # Use plain Python slim — no CUDA needed on the free CPU tier, # and it avoids the old PyTorch 2.2 in the pytorch/pytorch base image # (GLM-OCR's transformers requires PyTorch >= 2.4). FROM python:3.11-slim # ── System deps ──────────────────────────────────────────────────────────── RUN apt-get update && apt-get install -y --no-install-recommends \ libgl1 \ libglib2.0-0 \ curl \ && rm -rf /var/lib/apt/lists/* # ── Workdir ──────────────────────────────────────────────────────────────── WORKDIR /app # ── Install CPU PyTorch first (must come before requirements.txt so pip # doesn't pull the CUDA build from PyPI and stays on >=2.4) ───────────── RUN pip install --no-cache-dir \ "torch>=2.4.0" \ "torchvision>=0.19.0" \ --index-url https://download.pytorch.org/whl/cpu # ── Install remaining dependencies ───────────────────────────────────────── # pip will see torch/torchvision already satisfy their constraints and skip them COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt # ── Copy source (flat structure) ─────────────────────────────────────────── COPY main.py ocr_engine.py ./ COPY frontend/ ./frontend/ # ── Expose & run (HF Spaces requires port 7860) ──────────────────────────── EXPOSE 7860 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]