File size: 2,229 Bytes
31523a9
ccddf78
31523a9
 
 
 
 
 
 
45652f7
bae0f63
 
 
 
 
 
 
 
286428e
bae0f63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286428e
bae0f63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
69
70
71
---
title: PsyPredict [Backend]
emoji: 🧠
colorFrom: indigo
colorTo: purple
sdk: docker
pinned: false
---

# PsyPredict - Backend

**FastAPI** backend for PsyPredict β€” production-grade multimodal clinical AI system.

## What Runs Here

| Service | Technology |
|---------|-----------|
| API Framework | FastAPI + Uvicorn |
| LLM Inference | Ollama / Llama3 (local) |
| Text Emotion | DistilBERT (`bhadresh-savani/distilbert-base-uncased-emotion`) |
| Crisis Detection | Zero-shot NLI (MiniLM) |
| Face Emotion | Keras CNN (custom trained, `emotion_model_trained.h5`) |
| Remedies | CSV lookup (`MEDICATION.csv`) |

## Endpoints

| Method | Path | Description |
|--------|------|-------------|
| `POST` | `/api/chat` | Main therapist β€” returns `PsychReport` |
| `POST` | `/api/predict/emotion` | Facial emotion detection |
| `GET`  | `/api/get_advice` | Remedy/condition lookup |
| `POST` | `/api/analyze/text` | Text emotion + crisis score |
| `GET`  | `/api/health` | System health check |

## Running Locally

```bash
# 1. Install Ollama + LLaMA 3 (one-time)
winget install Ollama.Ollama
ollama pull llama3

# 2. Install dependencies
pip install -r requirements.txt

# 3. Start server
uvicorn app.main:app --host 0.0.0.0 --port 7860 --reload
```

Swagger docs: http://localhost:7860/docs

## Key Files

```
app/
β”œβ”€β”€ main.py                   # FastAPI app factory
β”œβ”€β”€ config.py                 # Pydantic Settings
β”œβ”€β”€ schemas.py                # All request/response models (PsychReport etc.)
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ ollama_engine.py      # LLaMA 3 async client
β”‚   β”œβ”€β”€ text_emotion_engine.py# DistilBERT classifier
β”‚   β”œβ”€β”€ crisis_engine.py      # Zero-shot NLI crisis detection
β”‚   β”œβ”€β”€ fusion_engine.py      # Multimodal weighted fusion
β”‚   β”œβ”€β”€ emotion_engine.py     # Keras CNN face emotion (preserved)
β”‚   └── remedy_engine.py      # CSV remedy lookup (preserved)
└── api/endpoints/
    β”œβ”€β”€ therapist.py          # POST /api/chat
    β”œβ”€β”€ facial.py             # POST /api/predict/emotion
    β”œβ”€β”€ remedies.py           # GET  /api/get_advice
    └── analysis.py           # POST /api/analyze/text + GET /api/health
```