# Stage 1: Build React Frontend FROM node:20 as build-frontend WORKDIR /app/web_client COPY web_client/package.json web_client/package-lock.json ./ RUN npm ci COPY web_client/ ./ RUN npm run build # Stage 2: Python Backend & Runtime FROM python:3.11-slim # Install system dependencies for compiling llama.cpp and upif extensions RUN apt-get update && apt-get install -y \ build-essential \ cmake \ git \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Create a writable directory for model downloads (HF Spaces runs as user 1000) RUN mkdir -p /app/models && chmod 777 /app/models # Copy Python requirements first for caching COPY requirements.txt . # Install dependencies (pip + Python deps) RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # ⬇️ FIX: install llama-cpp-python correctly (compiles from source) RUN CMAKE_ARGS="-DLLAMA_CUBLAS=off" pip install --no-cache-dir llama-cpp-python==0.2.90 # Copy the rest of the application COPY . . # Install your backend package (pyproject.toml) RUN pip install . # Copy built frontend assets COPY --from=build-frontend /app/web_client/dist /app/web_client/dist # Hugging Face defaults ENV PORT=7860 EXPOSE 7860 CMD ["python", "server.py"]