File size: 1,975 Bytes
ad83752
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f9a457
ad83752
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
# --------------------------------------------------------------------------- #
# Dockerfile for Hugging Face Spaces (Docker SDK)
# Crop vs No-Crop Segmentation - SegFormer-B2 - CPU optimized
# --------------------------------------------------------------------------- #
FROM python:3.10-slim

# --- Environment ----------------------------------------------------------- #
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    # Hugging Face cache in a writable location (model config + best.pt land here)
    HF_HOME=/home/user/.cache/huggingface

# --- System dependencies --------------------------------------------------- #
# opencv-python-headless needs libglib2.0-0 at runtime.
RUN apt-get update && apt-get install -y --no-install-recommends \
        libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# --- Non-root user (Hugging Face Spaces best practice) --------------------- #
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR /home/user/app

# --- Python dependencies --------------------------------------------------- #
COPY --chown=user requirements.txt .

# Install the CPU-only build of torch/torchvision first to keep the image
# small (no CUDA libraries). The subsequent -r install then finds them already
# satisfied and skips re-downloading.
RUN pip install --upgrade pip && \
    pip install --no-cache-dir \
        torch torchvision \
        --index-url https://download.pytorch.org/whl/cpu && \
    pip install --no-cache-dir -r requirements.txt

# --- Application code ------------------------------------------------------ #
COPY --chown=user . .

# Streamlit listens on 8501 (matched by app_port in README front matter).
EXPOSE 8501

CMD ["streamlit", "run", "app.py", \
     "--server.port=8501", \
     "--server.address=0.0.0.0", \
     "--server.enableCORS=false", \
     "--server.enableXsrfProtection=false"]