Sam20202 commited on
Commit
e705a4f
Β·
1 Parent(s): b6a4ae1

Fix: upgrade to Python 3.11-slim + CPU PyTorch >=2.4

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -6
Dockerfile CHANGED
@@ -4,7 +4,10 @@
4
  # No local Docker needed β€” HF handles the build and hosting.
5
  # ──────────────────────────────────────────────────────────────────────────
6
 
7
- FROM pytorch/pytorch:2.2.0-cuda12.1-cudnn8-runtime
 
 
 
8
 
9
  # ── System deps ────────────────────────────────────────────────────────────
10
  RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -16,7 +19,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
16
  # ── Workdir ────────────────────────────────────────────────────────────────
17
  WORKDIR /app
18
 
19
- # ── Python deps ────────────────────────────────────────────────────────────
 
 
 
 
 
 
 
 
20
  COPY requirements.txt ./
21
  RUN pip install --no-cache-dir -r requirements.txt
22
 
@@ -24,10 +35,6 @@ RUN pip install --no-cache-dir -r requirements.txt
24
  COPY main.py ocr_engine.py ./
25
  COPY frontend/ ./frontend/
26
 
27
- # ── Model weights download at first startup (not baked into image) ─────────
28
- # HF Spaces caches ~/.cache/huggingface across restarts on paid tiers.
29
- # On the free tier the model (~1-2 GB) re-downloads on each cold start.
30
-
31
  # ── Expose & run (HF Spaces requires port 7860) ────────────────────────────
32
  EXPOSE 7860
33
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
4
  # No local Docker needed β€” HF handles the build and hosting.
5
  # ──────────────────────────────────────────────────────────────────────────
6
 
7
+ # Use plain Python slim β€” no CUDA needed on the free CPU tier,
8
+ # and it avoids the old PyTorch 2.2 in the pytorch/pytorch base image
9
+ # (GLM-OCR's transformers requires PyTorch >= 2.4).
10
+ FROM python:3.11-slim
11
 
12
  # ── System deps ────────────────────────────────────────────────────────────
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
19
  # ── Workdir ────────────────────────────────────────────────────────────────
20
  WORKDIR /app
21
 
22
+ # ── Install CPU PyTorch first (must come before requirements.txt so pip
23
+ # doesn't pull the CUDA build from PyPI and stays on >=2.4) ─────────────
24
+ RUN pip install --no-cache-dir \
25
+ "torch>=2.4.0" \
26
+ "torchvision>=0.19.0" \
27
+ --index-url https://download.pytorch.org/whl/cpu
28
+
29
+ # ── Install remaining dependencies ─────────────────────────────────────────
30
+ # pip will see torch/torchvision already satisfy their constraints and skip them
31
  COPY requirements.txt ./
32
  RUN pip install --no-cache-dir -r requirements.txt
33
 
 
35
  COPY main.py ocr_engine.py ./
36
  COPY frontend/ ./frontend/
37
 
 
 
 
 
38
  # ── Expose & run (HF Spaces requires port 7860) ────────────────────────────
39
  EXPOSE 7860
40
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]