# Use a slim Python base image FROM python:3.9-slim # Install system build deps (adjust if you know you don't need them) RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ gcc \ libgomp1 \ git && \ rm -rf /var/lib/apt/lists/* # Prevent Python from writing .pyc files and enable unbuffered logging ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 WORKDIR /app # Copy only requirements first to leverage Docker cache COPY requirements.txt /app/requirements.txt # Install Python packages globally (as root) RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r /app/requirements.txt # Create a non-root user and switch to it RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" # Copy application code as the non-root user COPY --chown=user:root . /app # Expose the port expected by Hugging Face Spaces (7860) EXPOSE 7860 # Run uvicorn pointing at your FastAPI app. # Note: your FastAPI app instance is `app` in `backend.py`, so we use `backend:app`. CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]