Spaces:
Build error
Build error
# Use a Python 3.10 base image with Debian Bookworm | |
FROM python:3.10-bookworm | |
# Set environment variables to avoid Python buffering and ensure non-interactive installs | |
ENV PYTHONUNBUFFERED=1 \ | |
DEBIAN_FRONTEND=noninteractive | |
# Install system dependencies, including OpenBLAS, Git, and build tools | |
RUN apt-get update && apt-get install -y \ | |
git \ | |
build-essential \ | |
cmake \ | |
libopenblas-dev \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Create a non-root user with configurable UID/GID | |
ARG USER_ID=1000 | |
ARG GROUP_ID=1000 | |
RUN groupadd -g ${GROUP_ID} appuser && \ | |
useradd -m -u ${USER_ID} -g ${GROUP_ID} -s /bin/bash appuser | |
# Set up Hugging Face cache directory and /app with proper permissions | |
RUN mkdir -p /home/appuser/.cache/huggingface /app && \ | |
chown -R appuser:appuser /home/appuser/.cache /app | |
# Set working directory | |
WORKDIR /app | |
# Clone llama-cpp-python repository with submodules as appuser | |
USER appuser | |
RUN git clone --recursive https://github.com/abetlen/llama-cpp-python.git /app/llama-cpp-python | |
# Set working directory to llama-cpp-python | |
WORKDIR /app/llama-cpp-python | |
# Update llama.cpp submodule to the latest version as appuser | |
RUN git submodule update --remote vendor/llama.cpp | |
# Set environment variables for building with OpenBLAS | |
ENV FORCE_CMAKE=1 | |
ENV CMAKE_ARGS="-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DLLAMA_CURL=OFF" | |
# Install llama-cpp-python from source as appuser | |
RUN pip install . --user --upgrade --force-reinstall --no-cache-dir | |
# Switch to root to copy application code (to ensure permissions) | |
USER root | |
COPY --chown=appuser:appuser app.py /app/ | |
# Install additional Python dependencies for your app as appuser | |
USER appuser | |
RUN pip install --user gradio huggingface_hub | |
# Set working directory for the application | |
WORKDIR /app | |
# Expose port for Gradio | |
EXPOSE 7860 | |
# Run the application as appuser | |
CMD ["python", "app.py"] |