# ── Stage 1: Builder (downloads model) ── FROM ghcr.io/ggml-org/llama.cpp:full AS builder WORKDIR /app RUN apt-get update && apt-get install -y --no-install-recommends \ python3 python3-pip python3-venv \ && rm -rf /var/lib/apt/lists/* RUN python3 -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" RUN pip install --no-cache-dir -U pip huggingface_hub RUN python3 -c 'from huggingface_hub import hf_hub_download; \ hf_hub_download(repo_id="Abiray/MiniCPM5-1B-GGUF", \ filename="minicpm5-1b-Q4_K_M.gguf", \ local_dir="/app")' # ── Stage 2: Runtime ── FROM ghcr.io/ggml-org/llama.cpp:full # Create user FIRST (HF Spaces runs as UID 1000) RUN useradd -m -u 1000 user WORKDIR /app ENV HOME=/home/user \ PATH=/home/user/.local/bin:/opt/venv/bin:$PATH \ PYTHONUNBUFFERED=1 # Minimal runtime deps RUN apt-get update && apt-get install -y --no-install-recommends \ python3 python3-pip python3-venv \ ffmpeg \ libgomp1 \ && rm -rf /var/lib/apt/lists/* # Copy venv from builder COPY --from=builder /opt/venv /opt/venv # Install runtime packages RUN pip install --no-cache-dir flask edge-tts llama-cpp-python \ && rm -rf /root/.cache/pip # Copy model COPY --from=builder /app/minicpm5-1b-Q4_K_M.gguf /app/minicpm5-1b-Q4_K_M.gguf # ── CRITICAL: Copy app + assets with correct ownership ── # The model/ and animation/ folders must be in your repo root COPY --chown=user:user app.py /app/app.py COPY --chown=user:user model /app/model COPY --chown=user:user animation /app/animation # Ensure user owns everything RUN chown -R user:user /app USER user EXPOSE 7860 ENTRYPOINT [] CMD ["python3", "/app/app.py"]