# Use official Python base (slim to keep image small) FROM python:3.12-slim # Install system dependencies RUN apt-get update && apt-get install -y \ git \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender1 \ && rm -rf /var/lib/apt/lists/* # Create and switch to a non-root user RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" # Set working directory WORKDIR /app # Copy requirements first (better cache) COPY --chown=user ./requirements.txt requirements.txt # Upgrade pip and install deps RUN python -m pip install --no-cache-dir --upgrade pip \ && pip install --no-cache-dir -r requirements.txt RUN python -c "import clip; clip.load('ViT-B/32', device = 'cpu', jit=False)" # Copy app code COPY --chown=user . /app # Expose the default Spaces port EXPOSE 7860 # Run FastAPI server (Spaces sets $PORT, default to 7860) CMD ["bash", "-lc", "uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860}"]