# Use a lightweight build environment with cmake and make installed FROM python:3.11-slim AS builder RUN apt-get update && apt-get install -y \ build-essential \ cmake \ git \ curl \ && rm -rf /var/lib/apt/lists/* # Clone and build llama.cpp server WORKDIR /app RUN git clone https://github.com/ggerganov/llama.cpp.git \ && cd llama.cpp \ && cmake -B build -DBUILD_SHARED_LIBS=OFF \ && cmake --build build --config Release --target llama-server # Use a clean, small final image FROM python:3.11-slim RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* WORKDIR /app # Copy the built llama-server binary from the builder stage COPY --from=builder /app/llama.cpp/build/bin/llama-server /app/llama-server # Download the MiniCPM5-1B-GGUF model (using Q4_K_M for optimal speed/memory balance on CPU) RUN curl -L -o minicpm-1b.gguf "https://huggingface.co/openbmb/MiniCPM5-1B-GGUF/resolve/main/MiniCPM5-1B-Q4_K_M.gguf" # Expose port 7860 (Hugging Face Spaces requires your app to listen on port 7860) EXPOSE 7860 # Add entrypoint script COPY entrypoint.sh /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh ENTRYPOINT ["/app/entrypoint.sh"]