# Use a lightweight Python 3.10 base image FROM python:3.10-slim # 1. Hugging Face strictly requires running as a non-root user (UID 1000) RUN useradd -m -u 1000 user USER user # 2. Set up environment variables for the user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # 3. Set the working directory WORKDIR $HOME/app # 4. Copy requirements first to leverage Docker layer caching COPY --chown=user requirements.txt $HOME/app/ # 5. Install dependencies, using the pre-built CPU wheel to bypass compilation 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 # 6. Copy the main application code COPY --chown=user app.py $HOME/app/ # 7. Expose port 7860 (The standard port for HF Spaces) EXPOSE 7860 # 8. Start the Uvicorn server CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]