SpacesExamples/llama-cpp-python-cuda-gradio
23
1ARG CUDA_IMAGE="12.1.1-devel-ubuntu22.04"2FROM nvidia/cuda:${CUDA_IMAGE}3 4# We need to set the host to 0.0.0.0 to allow outside access5ENV HOST 0.0.0.06 7RUN apt-get update && apt-get upgrade -y \8 && apt-get install -y git build-essential \9 python3 python3-pip gcc wget \10 ocl-icd-opencl-dev opencl-headers clinfo \11 libclblast-dev libopenblas-dev \12 && mkdir -p /etc/OpenCL/vendors && echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd13 14COPY . .15 16# setting build related env vars17ENV CUDA_DOCKER_ARCH=all18ENV LLAMA_CUBLAS=119 20# Install depencencies21RUN python3 -m pip install --upgrade pip pytest cmake \22 scikit-build setuptools fastapi uvicorn sse-starlette \23 pydantic-settings starlette-context gradio huggingface_hub hf_transfer24 25# Install llama-cpp-python (build with cuda)26RUN CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python27 28RUN useradd -m -u 1000 user29# Switch to the "user" user30USER user31# Set home to the user's home directory32ENV HOME=/home/user \33 PATH=/home/user/.local/bin:$PATH \34 PYTHONPATH=$HOME/app \35 PYTHONUNBUFFERED=1 \36 GRADIO_ALLOW_FLAGGING=never \37 GRADIO_NUM_PORTS=1 \38 GRADIO_SERVER_NAME=0.0.0.0 \39 GRADIO_THEME=huggingface \40 SYSTEM=spaces41 42WORKDIR $HOME/app43 44# Copy the current directory contents into the container at $HOME/app setting the owner to the user45COPY --chown=user . $HOME/app46 47CMD ["python3", "app.py"]