Spaces:
Sleeping
Sleeping
File size: 3,291 Bytes
f020d6c 62b7f0a f020d6c 62b7f0a f020d6c 87a48cb f020d6c 87a48cb f020d6c 87a48cb f020d6c 62b7f0a f020d6c 62b7f0a f020d6c 62b7f0a f020d6c 62b7f0a f020d6c 62b7f0a f020d6c 62b7f0a f020d6c 62b7f0a f020d6c 62b7f0a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 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"]
|