FROM python:3.9-slim # 1. Install system dependencies for OpenCV RUN apt-get update && apt-get install -y \ libgl1 \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* # 2. Set up a non-root user for Hugging Face Spaces RUN useradd -m -u 1000 user WORKDIR /app RUN chown user:user /app USER user ENV PATH="/home/user/.local/bin:$PATH" # 3. Install Python dependencies COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir --user -r requirements.txt # 4. PRE-DOWNLOAD THE MODEL (This prevents the "stuck" build/startup) RUN python -c "from ultralytics import YOLO; YOLO('yolov8n-pose.pt')" # 5. Copy the app code COPY --chown=user app.py . EXPOSE 7860 CMD ["python", "app.py"]