Spaces:
Sleeping
Sleeping
Fix: upgrade to Python 3.11-slim + CPU PyTorch >=2.4
Browse files- Dockerfile +13 -6
Dockerfile
CHANGED
|
@@ -4,7 +4,10 @@
|
|
| 4 |
# No local Docker needed β HF handles the build and hosting.
|
| 5 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
# ββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"]
|