# Stage 1: Build Frontend FROM node:20 AS frontend-build WORKDIR /app/frontend COPY frontend/package*.json ./ # Use --legacy-peer-deps to avoid strict version conflicts RUN npm install --legacy-peer-deps COPY frontend/ ./ # Run build with verbose output to see errors RUN npm run build # Stage 2: Final Image FROM python:3.10-slim WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ libgl1 \ libglib2.0-0 \ tesseract-ocr \ libsm6 \ libxext6 \ libxrender-dev \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy backend code and modules COPY src/ ./src/ COPY models/ ./models/ COPY api.py . COPY endToEnd2.py . # Copy built frontend from stage 1 COPY --from=frontend-build /app/frontend/dist ./frontend/dist # Set environment variables ENV PORT=7860 ENV MPLBACKEND=Agg ENV HOME=/tmp # Create necessary directories and set permissions # Important for HF Spaces: generated_models and samples must be writable RUN mkdir -p samples generated_models outputs && \ chmod -R 777 samples generated_models outputs && \ chmod -R 777 /app USER 1000 EXPOSE 7860 # Run the app CMD ["python", "api.py"]