Spaces:
Running
Running
| # ============================================================================= | |
| # HyperView - Hugging Face Spaces Dockerfile | |
| # ============================================================================= | |
| # Multi-stage build for deploying HyperView to HuggingFace Spaces. | |
| # | |
| # Features: | |
| # - CLIP embeddings (Euclidean) via embed-anything | |
| # - HyCoCLIP embeddings (Hyperbolic) via hyper-models ONNX | |
| # - Pre-computed demo dataset (300 CIFAR-10 samples) | |
| # - Torch-free runtime for minimal image size | |
| # | |
| # Deploy: https://huggingface.co/spaces/Hyper3Labs/HyperView | |
| # ============================================================================= | |
| # ----------------------------------------------------------------------------- | |
| # Stage 1: Build Frontend (Next.js static export) | |
| # ----------------------------------------------------------------------------- | |
| FROM node:20-slim AS frontend-builder | |
| WORKDIR /app/frontend | |
| # Install dependencies first (better caching) | |
| COPY frontend/package.json frontend/package-lock.json ./ | |
| RUN npm ci --prefer-offline | |
| # Build hyper-scatter (installed from source tarball, dist-lib not prebuilt) | |
| RUN cd node_modules/hyper-scatter \ | |
| && npm install \ | |
| && npm run build:lib | |
| # Copy frontend source and build | |
| COPY frontend/ ./ | |
| RUN npm run build | |
| # Verify output exists | |
| RUN ls -la out/ && echo "Frontend build complete" | |
| # ----------------------------------------------------------------------------- | |
| # Stage 2: Python Runtime | |
| # ----------------------------------------------------------------------------- | |
| FROM python:3.11-slim AS runtime | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| curl \ | |
| git \ | |
| libssl-dev \ | |
| pkg-config \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # HuggingFace Spaces requirement: create user with UID 1000 | |
| RUN useradd -m -u 1000 user | |
| # Switch to user | |
| USER user | |
| # Set environment variables | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH \ | |
| HF_HOME=/home/user/.cache/huggingface \ | |
| PYTHONUNBUFFERED=1 \ | |
| PIP_NO_CACHE_DIR=1 | |
| WORKDIR $HOME/app | |
| # Upgrade pip | |
| RUN pip install --upgrade pip | |
| # Copy Python package files | |
| COPY --chown=user pyproject.toml README.md LICENSE ./ | |
| COPY --chown=user src/ ./src/ | |
| COPY --chown=user scripts/ ./scripts/ | |
| # Install Python package (without ML extras - we use ONNX) | |
| RUN pip install -e . | |
| # Copy built frontend to static directory | |
| COPY --from=frontend-builder --chown=user /app/frontend/out ./src/hyperview/server/static/ | |
| # Verify frontend is in place | |
| RUN ls -la src/hyperview/server/static/ && echo "Frontend copied successfully" | |
| # ----------------------------------------------------------------------------- | |
| # Stage 3: Pre-compute Demo Dataset | |
| # ----------------------------------------------------------------------------- | |
| # Create output directories | |
| RUN mkdir -p $HOME/app/demo_data/datasets $HOME/app/demo_data/media | |
| # Set environment for precomputation | |
| ENV HYPERVIEW_DATASETS_DIR=/home/user/app/demo_data/datasets \ | |
| HYPERVIEW_MEDIA_DIR=/home/user/app/demo_data/media \ | |
| DEMO_SAMPLES=300 | |
| # Pre-download HuggingFace models and compute embeddings | |
| # This runs during build to ensure fast startup | |
| RUN python scripts/precompute_hf_demo.py | |
| # Verify dataset was created | |
| RUN ls -la demo_data/ && echo "Demo dataset pre-computed successfully" | |
| # ----------------------------------------------------------------------------- | |
| # Final Configuration | |
| # ----------------------------------------------------------------------------- | |
| # Copy entrypoint | |
| COPY --chown=user app_hf.py ./ | |
| # Set runtime environment | |
| ENV HOST=0.0.0.0 \ | |
| PORT=7860 \ | |
| DEMO_DATASET=cifar10_hf_demo \ | |
| HYPERVIEW_DATASETS_DIR=/home/user/app/demo_data/datasets \ | |
| HYPERVIEW_MEDIA_DIR=/home/user/app/demo_data/media | |
| # Expose port (HuggingFace Spaces default) | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ | |
| CMD curl -f http://localhost:7860/__hyperview__/health || exit 1 | |
| # Start server | |
| CMD ["python", "app_hf.py"] | |