FROM python:3.10 # Set up a non-root user for Hugging Face Spaces RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH WORKDIR $HOME/app # Limit build concurrency to prevent OOM errors during llama-cpp-python installation ENV MAKEFLAGS="-j1" ENV CMAKE_BUILD_PARALLEL_LEVEL="1" # Install dependencies using precompiled wheels to avoid memory issues (OOM) during build COPY --chown=user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu # Copy application files COPY --chown=user . . # Expose the correct port EXPOSE 7860 # Command to run the FastAPI app via Uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]