Spaces:
Running
Running
| # ────────────────────────────────────────────────── | |
| # OptiQ — Full-stack Docker image for Hugging Face Spaces | |
| # Multi-stage: Node (frontend build) → Python (backend) | |
| # ────────────────────────────────────────────────── | |
| # ── Stage 1: Build the React frontend ──────────── | |
| FROM node:20-alpine AS frontend | |
| WORKDIR /app/frontend | |
| COPY frontend/package*.json ./ | |
| RUN if [ -f package-lock.json ]; then npm ci --no-audit --no-fund; else npm install --no-audit --no-fund; fi | |
| COPY frontend/ . | |
| RUN npm run build | |
| # ── Stage 2: Python backend + built frontend ───── | |
| FROM python:3.12-slim | |
| WORKDIR /app | |
| # System dependencies needed by some Python packages (pandapower, scipy, etc.) | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends gcc g++ && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Install PyTorch CPU first (not in requirements.txt — installed via conda locally) | |
| RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu | |
| # Install remaining Python dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy application source | |
| COPY api/ api/ | |
| COPY src/ src/ | |
| COPY config.py . | |
| # Copy pre-trained model checkpoint if it exists (models/ may only contain .gitkeep) | |
| COPY models/ models/ | |
| # Copy built frontend from Stage 1 | |
| COPY --from=frontend /app/frontend/dist frontend/dist/ | |
| # Create writable directory for SQLite database | |
| RUN mkdir -p /app/data | |
| # HF Spaces requires port 7860 | |
| ENV PORT=7860 | |
| EXPOSE 7860 | |
| # Run the application | |
| CMD ["python", "-m", "uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"] | |