# Stage 1: Build the React Frontend FROM node:22-alpine AS frontend-builder WORKDIR /app/frontend COPY frontend/package*.json ./ RUN npm install COPY frontend/ ./ RUN npm run build # Stage 2: Setup Python Backend FROM python:3.10-slim # Create a non-root user with UID 1000 for Hugging Face Spaces RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH WORKDIR $HOME/app # Copy requirements and install dependencies COPY --chown=user:user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy backend files COPY --chown=user:user . . # Copy built frontend from Stage 1 into the static directory COPY --chown=user:user --from=frontend-builder /app/frontend/dist ./frontend/dist # Expose port 7860 EXPOSE 7860 # Run Uvicorn server on port 7860 CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]