| # Stage 1: Build React Frontend | |
| FROM node:20-alpine as builder | |
| WORKDIR /app | |
| COPY frontend/ ./frontend/ | |
| WORKDIR /app/frontend | |
| RUN npm install | |
| # Create the output directory structure expected by vite.config.ts | |
| RUN mkdir -p ../static/react | |
| RUN npm run build | |
| # Stage 2: Python Backend | |
| FROM python:3.10-slim | |
| # Install system dependencies for OpenCV and others | |
| RUN apt-get update && apt-get install -y \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| WORKDIR /app | |
| # Copy requirements and install dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy backend code | |
| COPY . . | |
| # Copy built frontend from builder stage | |
| # Note: Vite build output was configured to ../static/react, so it's at /app/static/react in builder | |
| COPY --from=builder /app/static/react ./static/react | |
| # Expose the port | |
| # Expose the port (Hugging Face Spaces uses 7860) | |
| EXPOSE 7860 | |
| # Command to run the application | |
| CMD ["python", "app.py"] | |