# Stage 1: Build React Frontend FROM node:18-alpine AS frontend-builder WORKDIR /app COPY frontend/package.json ./ COPY frontend/package-lock.json ./ RUN npm install --legacy-peer-deps COPY frontend/ ./ RUN npm run build # Stage 2: Setup Python Backend FROM python:3.10-slim # Setup user 1000 for Hugging Face Spaces compatibility RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH WORKDIR $HOME/app # Switch back to root to install system dependencies USER root RUN apt-get update && apt-get install -y tesseract-ocr && rm -rf /var/lib/apt/lists/* # Install python dependencies as user USER user COPY --chown=user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir fastapi uvicorn python-multipart # Copy backend code COPY --chown=user . . # Copy built frontend from Stage 1 COPY --from=frontend-builder --chown=user /app/dist $HOME/app/frontend/dist # Expose port 7860 for Hugging Face Spaces EXPOSE 7860 # Run the API CMD ["python", "-m", "uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860"]