File size: 6,675 Bytes
dadd038
 
68686f8
dadd038
 
9727d1f
 
dadd038
 
68686f8
 
 
 
 
151ec26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
faf0422
151ec26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
faf0422
 
151ec26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
faf0422
151ec26
 
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
---
title: Sanjeevani AI API
emoji: πŸ₯
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false
---

# Sanjeevani AI API

AI-powered healthcare backend API for the Sanjeevani platform.

# SanjeevaniAI β€” Industry-Grade Healthcare AI Platform

[![FastAPI](https://img.shields.io/badge/FastAPI-0.115+-009688?style=flat&logo=fastapi&logoColor=white)](https://fastapi.tiangolo.com)
[![PyTorch](https://img.shields.io/badge/PyTorch-2.2+-EE4C2C?style=flat&logo=pytorch&logoColor=white)](https://pytorch.org)
[![HuggingFace](https://img.shields.io/badge/Model-RoBERTa--large--BC5CDR-FFD21E?style=flat&logo=huggingface&logoColor=black)](https://huggingface.co/tner/roberta-large-bc5cdr)
[![Next.js](https://img.shields.io/badge/Next.js-14.2+-000000?style=flat&logo=next.js&logoColor=white)](https://nextjs.org)
[![TailwindCSS](https://img.shields.io/badge/TailwindCSS-3.4+-38B2AC?style=flat&logo=tailwind-css&logoColor=white)](https://tailwindcss.com)
[![Docker](https://img.shields.io/badge/Docker-Ready-2496ED?style=flat&logo=docker&logoColor=white)](https://www.docker.com)
[![Tests](https://img.shields.io/badge/Tests-16%2F16%20Passing-brightgreen?style=flat&logo=pytest&logoColor=white)](backend/tests)

> **Clinical Notice & Positioning**: SanjeevaniAI provides **AI-assisted healthcare information and clinical decision-support insights**. It is **not an autonomous diagnostic system** and is not a substitute for direct clinical examination, laboratory diagnosis, or emergency medical care.

---

## πŸ₯ Architecture Overview

```
SanjeevaniAI Platform
β”œβ”€β”€ Frontend (Next.js 14 + Tailwind CSS + Lucide Icons)
β”‚   β”œβ”€β”€ /                -> Landing page with medical disclaimer & capabilities
β”‚   β”œβ”€β”€ /dashboard       -> Clinical intelligence overview & metrics
β”‚   β”œβ”€β”€ /ner             -> Real-time local RoBERTa BC5CDR NER visualizer
β”‚   β”œβ”€β”€ /reports         -> Document upload, SHA-256 integrity & analysis
β”‚   β”œβ”€β”€ /reports/[id]    -> Structured clinical findings & raw text
β”‚   β”œβ”€β”€ /assistant       -> Conversational AI with emergency triage
β”‚   β”œβ”€β”€ /profile         -> Patient physiological profile & BMI
β”‚   β”œβ”€β”€ /history         -> Traceable medical timeline
β”‚   β”œβ”€β”€ /admin           -> System telemetry & security audit logs
β”‚   └── /demo            -> Guided 5-step mentor presentation walkthrough
β”‚
β”œβ”€β”€ Backend (FastAPI + Async SQLAlchemy + PyTorch)
β”‚   β”œβ”€β”€ Core & Security  -> JWT, bcrypt hashing, RBAC, Request ID, CSP headers
β”‚   β”œβ”€β”€ ML Engine        -> Local RoBERTa-large BC5CDR (355M params, CUDA/CPU)
β”‚   β”œβ”€β”€ Document Pipeline-> PDF/DOCX/TXT parser, chunker, entity aggregator
β”‚   β”œβ”€β”€ AI Assistant     -> Multi-provider LLM (Gemini + Mock) & triage engine
β”‚   └── Persistence      -> Async SQLite / PostgreSQL with audit trail
```

---

## ⚑ Quick Start

### 1. Prerequisites
- **Python**: 3.10+ (Recommended: Python 3.11)
- **Node.js**: 18.x or 20+ (with npm)
- **NVIDIA GPU (Optional)**: CUDA 11.8+ for accelerated inference (CPU fallback automatic)
- **Pretrained NER Model**: Stored locally in `models/bc5cdr-ner`

### 2. Backend Setup
```bash
# Activate virtual environment
python -m venv .venv
.\.venv\Scripts\Activate.ps1  # Windows PowerShell
# source .venv/bin/activate    # Linux / macOS

# Install dependencies
pip install -r requirements.txt

# Run synthetic demo database seeder
python scripts/seed_demo_data.py

# Launch FastAPI backend
uvicorn backend.app.main:app --host 0.0.0.0 --port 8000 --reload
```
*API Swagger UI will be live at `http://localhost:8000/docs`.*

### 3. Frontend Setup
```bash
cd frontend

# Install npm dependencies
npm install

# Run Next.js development server
npm run dev
```
*Application UI will be live at `http://localhost:3000`.*

---

## 🐳 Docker Deployment

To launch the full containerized stack:
```bash
docker-compose up --build
```
- Frontend: `http://localhost:3000`
- Backend API: `http://localhost:8000`
- Health Check: `http://localhost:8000/api/v1/health`

---

## πŸ§ͺ Test Suite & Verification

The platform includes a comprehensive automated test suite in `backend/tests/`:

```bash
pytest backend/tests -v
```

### Verified Test Results (16/16 Passing):
- `test_auth.py`: User registration, login, JWT validation, and invalid credential handling.
- `test_ner.py`: BC5CDR model info, entity extraction, character span alignment, and 422 validation.
- `test_documents.py`: File upload, SHA-256 fingerprinting, raw text extraction, and entity linking.
- `test_chat.py`: Multi-turn consultation, patient profile injection, and heuristic red-flag emergency detection.
- `test_profile.py`: Patient profile updates, vitals calculations, and RBAC admin permission enforcement.
- `test_health.py`: Liveness and readiness probes.

---

## πŸ‘¨β€πŸ« Mentor Demonstration Credentials

Use the **"Demo Roles"** dropdown in the navigation bar or log in with these pre-seeded accounts:

| Account | Email | Password | Role / Access Level |
| :--- | :--- | :--- | :--- |
| **Patient** | `demo.patient@sanjeevani.ai` | `DemoPatient2026!` | Health profile, documents, AI consultation |
| **Doctor** | `demo.doctor@sanjeevani.ai` | `DemoDoctor2026!` | Clinical decision support & document review |
| **Administrator** | `demo.admin@sanjeevani.ai` | `DemoAdmin2026!` | Platform telemetry, model status, security audit logs |

---

## πŸ“š Technical Documentation

- πŸ“ [**System Architecture & Mermaid Diagrams**](docs/ARCHITECTURE.md)
- πŸ”Œ [**REST API Catalog & OpenAPI Specification**](docs/API.md)
- 🧠 [**Machine Learning & Local RoBERTa BC5CDR Specs**](docs/ML_MODELS.md)
- 🎯 [**10-Minute Mentor Presentation Script**](docs/MENTOR_DEMO.md)
- πŸ” [**Initial Project Audit & Gap Analysis**](docs/PROJECT_AUDIT.md)

---

## πŸ›‘οΈ Medical Safety & Privacy Disclaimers

1. **AI-Assisted Decision Support**: SanjeevaniAI generates educational insights to assist healthcare providers and patients. It does not issue binding clinical diagnoses or prescribe treatment plans.
2. **Emergency Triage Protocol**: If severe acute symptoms (e.g. crushing chest pain, difficulty breathing, stroke symptoms) are entered, the platform immediately presents an emergency escalation alert advising immediate contact with emergency medical services (911 / 112 / 108).
3. **Data Security**: Uploaded files are fingerprinted with SHA-256, sensitive credentials hashed with direct bcrypt, and all administrative events logged in an immutable audit table.

---

## πŸ“„ License
MIT License. Developed for healthcare AI intelligence and clinical decision-support research.