Spaces:
Running
Running
| # ----------------------------- | |
| # 1️⃣ Build Frontend | |
| # ----------------------------- | |
| FROM node:18-bullseye AS frontend-builder | |
| WORKDIR /app/frontend | |
| COPY frontend/package*.json ./ | |
| RUN npm install | |
| COPY frontend/ . | |
| RUN npm run build | |
| # ----------------------------- | |
| # 2️⃣ Build Backend | |
| # ----------------------------- | |
| FROM python:3.10-slim-bullseye | |
| WORKDIR /app | |
| # Install essential system libraries for OpenCV, YOLO, and Ultralytics | |
| RUN apt-get update && apt-get install -y \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libgomp1 \ | |
| && apt-get clean && rm -rf /var/lib/apt/lists/* | |
| # Copy backend source code | |
| COPY backend/ . | |
| # Copy built frontend into the right folder for FastAPI | |
| # ✅ this must match your app.mount() path in app.py | |
| COPY --from=frontend-builder /app/frontend/dist ./frontend/dist | |
| # Install Python dependencies | |
| RUN pip install --upgrade pip | |
| RUN pip install -r requirements.txt || pip install -r backend/requirements.txt || true | |
| # Install runtime dependencies explicitly | |
| RUN pip install --no-cache-dir fastapi uvicorn python-multipart ultralytics opencv-python-headless pillow numpy scikit-learn tensorflow keras | |
| # Hugging Face Spaces sets PORT (default 7860). Listen on $PORT for compatibility. | |
| EXPOSE 7860 | |
| # Run FastAPI app (respect PORT env var if set by the platform) | |
| CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860}"] | |