# Use official Python runtime as base image FROM python:3.9-slim # Create a non-root user as required by Hugging Face Spaces RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set working directory WORKDIR /home/user/app # Copy requirements file first (for caching) COPY --chown=user requirements.txt requirements.txt # Install dependencies RUN pip install --no-cache-dir --upgrade -r requirements.txt # Copy the application code COPY --chown=user . /home/user/app # Run the FastAPI app on port 7860 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]