FROM python:3.10-slim # Install git for huggingface_hub to download models RUN apt-get update && apt-get install -y --no-install-recommends \ git \ && rm -rf /var/lib/apt/lists/* # Create a non-root user (UID 1000) as required by Hugging Face Spaces RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ # Hugging Face cache inside the container HF_HOME=/home/user/.cache/huggingface WORKDIR $HOME/app # Install Python dependencies COPY --chown=user requirements.txt . # Use --extra-index-url for pre-compiled llama-cpp-python wheels RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt \ --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu # Copy application source COPY --chown=user app.py . # Expose the port Hugging Face Spaces expects EXPOSE 7860 # Start the FastAPI server CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]