FROM python:3.12-slim # System libraries required by OpenCV and PyTorch RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libgl1 \ libsm6 \ libxrender1 \ libxext6 \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Install Python dependencies before copying the rest of the code # so this layer is cached as long as requirements.txt doesn't change. COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy application code and assets COPY . . # HF Spaces runs containers as uid 1000 (non-root) RUN useradd -m -u 1000 appuser \ && chown -R appuser /app USER appuser EXPOSE 7860 CMD ["python", "app.py"]