FROM python:3.11-slim # System deps for OpenCV (YOLO), image processing RUN apt-get update && apt-get install -y --no-install-recommends \ libgl1 \ libglib2.0-0 \ libsm6 \ libxrender1 \ libxext6 \ git \ && rm -rf /var/lib/apt/lists/* # Create non-root user (Spaces requirement) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH WORKDIR $HOME/app # Install Python deps COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu && \ pip install --no-cache-dir -r requirements.txt # Copy project files COPY --chown=user . . # Ensure writable dirs exist RUN mkdir -p archive_images archive_db # Spaces expects port 7860 EXPOSE 7860 CMD ["python", "app.py"]