File size: 4,843 Bytes
3973c7a
 
 
 
 
 
 
 
 
 
19d6abb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
---
title: Multi-Agent AI Health System
emoji: πŸ₯
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
---

# PRESAGE: Multi-Agent AI Health Prediction System

A sophisticated medical AI system that uses multiple specialized agents to analyze patient health data and generate personalized 90-day prevention plans.

## πŸš€ Quick Start

### Option 1: Automated Startup (Recommended)

**Windows (Batch):**
```bash
start-presage.bat
```

**Windows (PowerShell):**
```powershell
.\start-presage.ps1
```

### Option 2: Manual Startup

**Terminal 1 - Start API Backend:**
```bash
uvicorn api.main:app --reload --host 127.0.0.1 --port 8000
```

**Terminal 2 - Start React Frontend:**
```bash
cd client
npm install
npm run dev
```

The system will be available at:
- **React UI**: http://localhost:3000
- **API Backend**: http://127.0.0.1:8000
- **API Docs**: http://127.0.0.1:8000/docs

## πŸ“ Project Structure

```
presage/
β”œβ”€β”€ core/                           # Core modules
β”‚   β”œβ”€β”€ llm.py                     # Groq LLM integration
β”‚   β”œβ”€β”€ patient.py                 # Patient data models
β”‚   └── vector_store.py            # ChromaDB vector store
β”‚
β”œβ”€β”€ agents/                         # Specialized agents
β”‚   β”œβ”€β”€ data_agent.py              # Data validation & flagging
β”‚   β”œβ”€β”€ risk_agent.py              # ML-based risk assessment
β”‚   β”œβ”€β”€ literature_agent.py        # PubMed literature search
β”‚   β”œβ”€β”€ intervention_agent.py      # 90-day plan generation
β”‚   └── orchestrator.py            # Pipeline coordinator
β”‚
β”œβ”€β”€ api/                            # FastAPI backend
β”‚   └── main.py                    # REST API endpoints
β”‚
β”œβ”€β”€ client/                         # React (Next.js) frontend
β”‚   └── ...                        # Next.js project structure
β”‚
β”œβ”€β”€ data/                           # Data storage
β”‚   └── risk_models/               # Pre-trained ML models
β”‚
β”œβ”€β”€ .env                            # Environment variables (API keys)
β”œβ”€β”€ requirements.txt                # Python dependencies
└── README.md                       # This file
```

## πŸ”§ Configuration

### Environment Variables

Create or update `.env` file in the root directory:

```
GROQ_API_KEY=your_api_key_here
```

Get your API key from: https://console.groq.com

## 🚨 Troubleshooting

### Timeout Error: "Read timed out (read timeout=45/120)"

**Cause:** API server isn't running or is processing too slowly

**Solution:**
1. Make sure API server is running: `uvicorn api.main:app --reload`
2. Check API health: `curl http://127.0.0.1:8000/health`
3. Check terminal logs for errors
4. Increase timeout in the API client if needed

### Connection Error: "Cannot connect to API server"

**Solution:**
- Ensure FastAPI is running on port 8000
- Check if port 8000 is already in use: `netstat -ano | findstr :8000`
- Try a different port: `uvicorn api.main:app --port 8001`

### Import Errors

**Solution:**
```bash
pip install -r requirements.txt
```

### Groq API Key Error

**Solution:**
1. Verify `.env` file exists in root directory
2. Check that `GROQ_API_KEY=...` is correct
3. Generate a new key at https://console.groq.com

## πŸ“Š Pipeline Overview

The PRESAGE system operates through a coordinated multi-agent pipeline:

1. **Data Agent** β†’ Validates patient metrics and flags abnormalities
2. **Risk Agent** β†’ Predicts disease risk percentages using ML models
3. **Literature Agent** β†’ Searches PubMed for evidence-based interventions
4. **Intervention Agent** β†’ Synthesizes findings into a 90-day plan
5. **Orchestrator** β†’ Coordinates parallel execution and aggregates results

## πŸ” Security

- API keys are stored in `.env` (never commit to Git)
- `.gitignore` prevents accidental exposure
- No sensitive data is logged
- CORS enabled for frontend-backend communication

## πŸ“¦ Dependencies

- **groq**: LLM API client
- **fastapi**: Backend framework
- **Next.js/React**: Frontend framework
- **Tailwind CSS**: UI styling
- **scikit-learn**: ML models
- **chromadb**: Vector database
- **pydantic**: Data validation
- **requests**: HTTP client

## πŸ§ͺ Testing

Run the orchestrator test:
```bash
python test_orchestrator.py
```

## πŸ“ API Documentation

Interactive API docs available at:
```
http://127.0.0.1:8000/docs
```

## 🀝 Contributing

To add new agents or features:
1. Add agent to `agents/` folder
2. Implement `run_presage_pipeline()` updates
3. Update API schema if needed
4. Test with `test_orchestrator.py`

## πŸ“„ License

Proprietary Medical AI System

## πŸ”— Resources

- [Groq Console](https://console.groq.com)
- [FastAPI Docs](https://fastapi.tiangolo.com)
- [Next.js Docs](https://nextjs.org/docs)
- [ChromaDB Docs](https://docs.trychroma.com)