Spaces:
Sleeping
Sleeping
Commit ·
166d3d8
1
Parent(s): 9beb748
Add Dockerfile for Hugging Face Spaces deploy (16GB RAM)
Browse filesRender's 512MB free tier OOM-kills the worker — the torch + YOLO pipeline
peaks at 584MB before inference (and more with OCR). HF Spaces free tier has
16GB RAM, so the full pipeline (OCR included) fits. Docker SDK, serves on 7860,
runs as uid 1000 with writable model-cache paths.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- .dockerignore +17 -0
- Dockerfile +35 -0
.dockerignore
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Keep the image lean — only backend/ is needed at runtime.
|
| 2 |
+
frontend/
|
| 3 |
+
notebooks/
|
| 4 |
+
docs/
|
| 5 |
+
data/
|
| 6 |
+
*.db
|
| 7 |
+
.venv/
|
| 8 |
+
venv/
|
| 9 |
+
__pycache__/
|
| 10 |
+
**/__pycache__/
|
| 11 |
+
*.pyc
|
| 12 |
+
.git/
|
| 13 |
+
.github/
|
| 14 |
+
node_modules/
|
| 15 |
+
.env
|
| 16 |
+
.env.*
|
| 17 |
+
!.env.example
|
Dockerfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NETRA backend — Hugging Face Spaces (Docker SDK).
|
| 2 |
+
# HF free tier gives 16GB RAM / 2 vCPU, so the full torch + YOLO + TrOCR
|
| 3 |
+
# pipeline fits comfortably (unlike a 512MB host). HF serves on port 7860.
|
| 4 |
+
FROM python:3.11-slim
|
| 5 |
+
|
| 6 |
+
# OpenCV runtime libs (opencv-python-headless still needs libGL / glib).
|
| 7 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 8 |
+
libgl1 libglib2.0-0 \
|
| 9 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
+
|
| 11 |
+
# HF Spaces run containers as uid 1000. Create a matching user and point all
|
| 12 |
+
# model/caches at writable paths it owns.
|
| 13 |
+
RUN useradd -m -u 1000 user
|
| 14 |
+
ENV HOME=/home/user \
|
| 15 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 16 |
+
HF_HOME=/home/user/.cache/huggingface \
|
| 17 |
+
YOLO_CONFIG_DIR=/home/user/.config/Ultralytics \
|
| 18 |
+
PYTHONUNBUFFERED=1
|
| 19 |
+
|
| 20 |
+
# The app writes data/ under BASE_DIR (=/app), so /app must be user-owned.
|
| 21 |
+
RUN mkdir -p /app && chown -R user:user /app
|
| 22 |
+
USER user
|
| 23 |
+
WORKDIR /app
|
| 24 |
+
|
| 25 |
+
# Install deps first for layer caching (CPU torch via the index in requirements).
|
| 26 |
+
COPY --chown=user:user backend/requirements.txt ./backend/requirements.txt
|
| 27 |
+
RUN pip install --no-cache-dir --user -r backend/requirements.txt
|
| 28 |
+
|
| 29 |
+
# App code (ultimate_edge_preprocessor.py already lives inside backend/).
|
| 30 |
+
COPY --chown=user:user backend/ ./backend/
|
| 31 |
+
|
| 32 |
+
# Run from backend/ so `app.main` and `ultimate_edge_preprocessor` import cleanly.
|
| 33 |
+
WORKDIR /app/backend
|
| 34 |
+
EXPOSE 7860
|
| 35 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|