File size: 2,271 Bytes
4fa696a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# ── Base ───────────────────────────────────────────────────────────────────────
# slim image keeps the layer small; HF free tier is CPU-only
FROM python:3.11-slim

# ── System deps ────────────────────────────────────────────────────────────────
# libgl1 + libglib2.0-0 are required by OpenCV (pulled in by ultralytics)
RUN apt-get update && apt-get install -y --no-install-recommends \
        libgl1 \
        libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# ── HF Spaces user (uid 1000) ──────────────────────────────────────────────────
# Spaces runs as a non-root user; pre-create it so chown works
RUN useradd -m -u 1000 user
USER user

ENV HOME=/home/user \
    PATH="/home/user/.local/bin:$PATH" \
    PYTHONUNBUFFERED=1 \
    # tell HF hub to cache inside the writable home dir
    HF_HOME=/home/user/.cache/huggingface \
    # disable YOLO's attempt to write analytics / config to /root
    YOLO_CONFIG_DIR=/home/user/.config/ultralytics

WORKDIR /home/user/app

# ── Python deps ────────────────────────────────────────────────────────────────
# Copy requirements first so Docker can cache this layer
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
 && pip install --no-cache-dir -r requirements.txt

# ── App code ───────────────────────────────────────────────────────────────────
COPY --chown=user . .

# ── Runtime ────────────────────────────────────────────────────────────────────
EXPOSE 7860

CMD ["python", "app.py"]