Spaces:
Sleeping
Sleeping
Indrajit Ari
fix: unified deployment fix with flat routing, Suspense boundaries, and forced static export
87a48cb | # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Hugging Face Spaces β Docker SDK | |
| # | |
| # Architecture (simplified β NO nginx, NO Next.js server process): | |
| # 1. Build Next.js as a static export β ./frontend/out/ | |
| # 2. FastAPI serves the static files + handles /api/* and /ws/* | |
| # 3. Single process: uvicorn on port 7860 | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # ββ Stage 1: Build Next.js static export ββββββββββββββββββββββββββββββββββββ | |
| FROM node:20-slim AS frontend-builder | |
| WORKDIR /build/frontend | |
| COPY frontend/package*.json ./ | |
| # use npm install (more resilient) instead of ci for this setup | |
| RUN npm install | |
| COPY frontend/ ./ | |
| # We forced output:export in next.config.js, but keeping these for clarity | |
| ENV NEXT_PUBLIC_API_URL="" | |
| ENV NODE_ENV=production | |
| RUN npm run build | |
| # ββ Stage 2: Runtime (Python only, no nginx, no Node) βββββββββββββββββββββββ | |
| FROM python:3.10-slim | |
| # System deps: ffmpeg + OpenCV | |
| RUN apt-get update && apt-get install -y \ | |
| ffmpeg libgl1 libglib2.0-0 \ | |
| && apt-get clean && rm -rf /var/lib/apt/lists/* | |
| WORKDIR /app | |
| # ββ Python: CPU-only torch βββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| RUN pip install --no-cache-dir \ | |
| torch==2.1.2 torchvision==0.16.2 \ | |
| --index-url https://download.pytorch.org/whl/cpu | |
| # ββ Python: app dependencies βββββββββββββββββββββββββββββββββββββββββββββββββ | |
| RUN pip install --no-cache-dir \ | |
| "fastapi>=0.110.0" \ | |
| "uvicorn[standard]>=0.29.0" \ | |
| "python-multipart>=0.0.9" \ | |
| "aiofiles>=23.0.0" \ | |
| "opencv-python-headless>=4.9.0" \ | |
| "Pillow>=10.0.0" \ | |
| "numpy>=1.24.0,<2.0" \ | |
| "imageio>=2.33.0" \ | |
| "imageio-ffmpeg>=0.4.9" | |
| # ββ Copy backend code ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| COPY backend/ ./backend/ | |
| # ββ Copy Next.js static export βββββββββββββββββββββββββββββββββββββββββββββββ | |
| COPY --from=frontend-builder /build/frontend/out ./frontend/out | |
| # ββ Storage dirs βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| RUN mkdir -p /tmp/video_seg/uploads /tmp/video_seg/outputs | |
| # HF Spaces requires port 7860 | |
| EXPOSE 7860 | |
| # Single process: FastAPI serves both the API and the static frontend | |
| CMD ["uvicorn", "backend.app_hf:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"] | |