File size: 2,715 Bytes
f381be8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1552b5a
f381be8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ─────────────────────────────────────────────────────────────
# Stage 1: Build React frontend
# ─────────────────────────────────────────────────────────────
FROM node:20-slim AS frontend-build

WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm ci --no-audit --no-fund
COPY frontend/ ./
RUN npm run build

# ─────────────────────────────────────────────────────────────
# Stage 2: Python runtime
# ─────────────────────────────────────────────────────────────
FROM python:3.11-slim AS runtime

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    LOG_LEVEL=INFO

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc g++ && \
    rm -rf /var/lib/apt/lists/*

# Install Python dependencies
# Install torch CPU-only and tensorflow-cpu FIRST so requirements.txt
# finds them already satisfied (avoids downloading 3+ GB of CUDA deps)
COPY requirements.txt .
RUN pip install --upgrade pip && \
    pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu && \
    pip install tensorflow-cpu && \
    pip install -r requirements.txt

# Ensure writable artifact directories exist
RUN mkdir -p artifacts/v1/models/classical artifacts/v1/models/deep \
             artifacts/v1/scalers \
             artifacts/v2/models/classical artifacts/v2/models/deep \
             artifacts/v2/scalers artifacts/v2/results artifacts/v2/reports \
             artifacts/logs

# Copy project source (artifacts/ is NOT in git β€” downloaded at runtime)
COPY src/ src/
COPY api/ api/
COPY scripts/ scripts/
COPY cleaned_dataset/ cleaned_dataset/

# Copy built frontend
COPY --from=frontend-build /app/frontend/dist frontend/dist

# Expose port (Hugging Face Spaces expects 7860)
EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')"

# Entrypoint: download models from HF Hub if absent, then start the server
CMD ["sh", "-c", "python scripts/download_models.py && uvicorn api.main:app --host 0.0.0.0 --port 7860 --workers 1"]