FROM python:3.11-slim # System dependencies RUN apt-get update && apt-get install -y \ ffmpeg \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ curl \ git \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Download SAM vit_b checkpoint at build time (375MB) RUN mkdir -p models && \ curl -L -o models/sam_vit_b.pth \ "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth" # HF Spaces requires port 7860 EXPOSE 7860 # Non-root user (HF Spaces requirement) RUN useradd -m -u 1000 user RUN chown -R user:user /app USER user CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]