File size: 3,281 Bytes
f0f84fb
4044503
f0f84fb
 
4044503
f0f84fb
4044503
 
f0f84fb
 
 
0c46c35
 
 
 
f0f84fb
 
 
bae0f63
 
f0f84fb
 
bae0f63
0c46c35
4044503
15f9d61
 
 
4044503
0c46c35
 
 
4044503
0c46c35
 
4044503
f0f84fb
 
 
 
 
 
0c46c35
 
4044503
0c46c35
4044503
 
8d1fac5
f0f84fb
 
 
4044503
bae0f63
0c46c35
4044503
 
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
# ─────────────────────────────────────────────────────────────────────────────
# PsyPredict β€” Backend Dockerfile for Hugging Face Spaces
#
# Architecture:
#   - LLM inference via Groq API (no Ollama needed)
#   - FastAPI app served by Uvicorn on port 7860 (HF Spaces standard port)
#   - ML assets (Keras face model + CSV) downloaded at BUILD time via gdown
#   - DistilBERT + Crisis classifier downloaded at BUILD time from HF Hub
#   - HF_HUB_OFFLINE=1 at runtime so the container starts offline-capable
# ─────────────────────────────────────────────────────────────────────────────

FROM python:3.10-slim

WORKDIR /app

# ── 1. System dependencies ────────────────────────────────────────────────────
# libgl1 + libglib2.0-0: OpenCV headless needs these
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 \
    libglib2.0-0 \
    curl \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# ── 2. PyTorch CPU-only (separate layer β€” ~800MB, caches very well) ───────────
RUN pip install --no-cache-dir \
    torch --index-url https://download.pytorch.org/whl/cpu

# ── 3. Install remaining Python dependencies ──────────────────────────────────
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# ── 4. Copy application source code ──────────────────────────────────────────
COPY . .

# ── 5. Download ML assets at BUILD time ──────────────────────────────────────
# Downloads:
#   - app/ml_assets/emotion_model_trained.h5  (Keras CNN face model, ~4MB, Google Drive)
#   - app/ml_assets/MEDICATION.csv            (remedy database, Google Drive)
#   - app/ml_assets/distilbert_model/         (DistilBERT emotion classifier, ~260MB, HF Hub)
#   - app/ml_assets/crisis_model/             (MiniLM zero-shot classifier, ~130MB, HF Hub)
ENV HF_HUB_OFFLINE=0
RUN python download_models.py

# ── 6. Runtime environment ────────────────────────────────────────────────────
ENV PYTHONPATH=/app
ENV OLLAMA_TIMEOUT_S=30
ENV OLLAMA_RETRIES=3
ENV HF_HUB_OFFLINE=1
ENV LOG_LEVEL=INFO
ENV RATE_LIMIT=30/minute

# ── 7. Expose HF Spaces standard port ────────────────────────────────────────
EXPOSE 7860

# ── 8. Launch FastAPI directly (no Ollama needed) ────────────────────────────
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--log-level", "info"]