Real-Time Vitals Telemetry • Multi-Class ML Risk Stratification • Context-Aware Gemini AI Medical Chatbot
🚀 The Next Generation of Proactive Healthcare: An end-to-end intelligent IoT and clinical intelligence platform. It seamlessly ingests continuous physiological telemetry (Heart Rate, SpO2, Temperature), computes early-warning hemodynamic scores (MEWS/NEWS2, Shock Index, MAP), executes real-time multi-class Machine Learning inference across 12 clinical scenarios, and equips patients and clinicians with context-grounded AI guidance powered by Google Gemini.
- ✨ Key Features
- 📸 Application Walkthrough & Screenshots
- 🏗️ System Architecture
- 🧠 Machine Learning & Clinical Risk Engine
- 🔌 Hardware & IoT Telemetry Architecture
- 🛠️ Technology Stack
- 🚀 Quickstart & Setup Guide
- 📡 API Reference
- Intelligent Patient Triage: Unified roster displaying all assigned patients with immediate AI-calculated Risk Levels (Low, Moderate, High, Critical) and NEWS2 scores.
- Live Telemetry & Temporal Trends: Real-time stream visualization with interactive Recharts charting Heart Rate, Blood Oxygen (SpO2), and Temperature over time.
- Automated Clinical Diagnostic Reports: One-click generation of comprehensive medical assessment reports detailing differential diagnosis probabilities, hemodynamic derivations (Shock Index, Mean Arterial Pressure, Rate-Pressure Product), and WHO clinical protocols.
- Continuous Monitoring & Telemetry Linking: Integration with ESP32 devices via patient identification codes and remote Wi-Fi configuration.
- Personalized Health Dashboard: Clean, intuitive interface displaying live vital metrics, status indicators, and historical recovery/stability trends.
- Predictive Early Warning: Immediate visual feedback when vitals deviate from baseline, empowering patients to seek timely intervention.
- Automated Health Assessment: Self-service diagnostic summaries explaining current vital stability in plain, reassuring language.
- Context-Grounded Medical Intelligence: Powered by Google Gemini, the chatbot injects the patient's age, BMI, comorbidities, latest vitals, and 24-hour temporal slope directly into the reasoning prompt.
- Multilingual Interaction: Communicates fluidly in English, Hindi (हिंदी), and Marathi (मराठी) based on user preference.
- Clinical Safety Guardrails: Strict conservative medical prompting prevents hallucinated diagnoses, refuses unauthorized drug prescriptions, and provides immediate emergency triage protocols.
High-level operational overview for physicians, showcasing assigned patient rosters, risk categories, and direct clinical action shortcuts.
Detailed patient inspection view featuring real-time vital gauges, historical multi-metric temporal graphs, and physiological trend trajectories.
Automated clinical report summarizing multi-class ML classification, probability distributions, MEWS/NEWS2 scores, and WHO self-care guidance.
Patient-facing interface providing personal health tracking, vital sign summaries, trend indicators, and access to their full clinical report.
Floating conversational agent capable of analyzing live telemetry and delivering immediate, conservative guidance tailored to the patient's status.
Role-based portal with streamlined login, multi-factor verification, and registration for both doctors and patients.
graph TD
subgraph Hardware_IoT["🔌 Hardware & IoT Layer"]
S1["MAX30102 PPG Sensor<br/>(Heart Rate & SpO2)"] --> MCU["ESP32 Microcontroller<br/>(Wi-Fi Telemetry Node)"]
S2["DS18B20 / MLX90614<br/>(Body Temperature)"] --> MCU
MCU -- "JSON HTTP POST<br/>/api/patients/{id}/vitals" --> API
end
subgraph Backend_Core["⚙️ Backend Server (Flask RESTful API)"]
API["Flask API Router & Auth Controller"]
DB[("SQLite Database<br/>users • patients • vitals")]
API <--> DB
subgraph ML_Risk_Engine["🧠 ML & Clinical Engine"]
PIPE["Scikit-Learn Pipeline<br/>(MODEL3.py)"]
NORM["StandardScaler & LabelEncoder"]
CLF["Gradient Boosting & Random Forest<br/>12 Clinical Scenarios"]
SCORE["Clinical Calculator<br/>MEWS • NEWS2 • Shock Index • MAP"]
PROTO["WHO Protocol Matcher<br/>Clinical Knowledge Base"]
NORM --> CLF
PIPE --> NORM
PIPE --> SCORE
PIPE --> PROTO
end
subgraph AI_Context["🤖 Generative AI Engine"]
CTX["Context Aggregator<br/>(Demographics + Telemetry + Trends)"]
GUARD["Medical Safety Prompt Gate<br/>(Non-diagnostic • Emergency Triage)"]
GEMINI["Google Gemini 2.5 Flash API"]
CTX --> GUARD --> GEMINI
end
API --> PIPE
API --> CTX
end
subgraph Frontend_Client["🖥️ Frontend Client (React 19 + Vite)"]
DOC_UI["🧑⚕️ Doctor Portal<br/>Roster • Live Monitoring • Clinical Reports"]
PAT_UI["🤒 Patient Portal<br/>Personal Metrics • Historical Trends"]
CHAT_UI["💬 Multilingual AI Chatbot<br/>(English • Hindi • Marathi)"]
API <== "JSON REST API" ==> DOC_UI
API <== "JSON REST API" ==> PAT_UI
GEMINI <== "Contextual Guidance" ==> CHAT_UI
end
flowchart TD
A["Raw Vitals Telemetry Ingested<br/>(HR, SpO2, Temp, Timestamp)"] --> B{"Input Validation & Schema Check"}
B -- Invalid --> ERR["400 Bad Request / Discard"]
B -- Valid --> C["Store Raw Record in SQLite `vitals`"]
C --> D["Feature Engineering & Physiological Derivations"]
D --> D1["Shock Index = HR / SBP"]
D --> D2["MAP = (2*DBP + SBP) / 3"]
D --> D3["MEWS / NEWS2 Calculation"]
D --> D4["Rate-Pressure Product & Stress Index"]
D1 & D2 & D3 & D4 --> E["Multi-Class ML Inference<br/>Gradient Boosting Classifier"]
E --> F["Probability Distribution across 12 Scenarios<br/>(Healthy, Hypoxia, Sepsis, Cardiac Event, etc.)"]
F --> G["Risk Stratification & Scoring (0 - 100)"]
G --> H{"Risk Category"}
H -- "< 20" --> R1["🟢 LOW RISK<br/>Routine self-care monitoring"]
H -- "20 - 50" --> R2["🟡 MODERATE RISK<br/>Increased monitoring frequency"]
H -- "> 50" --> R3["🔴 HIGH / CRITICAL RISK<br/>Immediate clinical escalation alert"]
R1 & R2 & R3 --> I["Package Assessment JSON & Broadcast to Frontend"]
sequenceDiagram
autonumber
actor Patient as 🤒 Patient
participant UI as 💬 Chat Drawer (React)
participant API as ⚙️ Flask API (/api/chat)
participant DB as 🗄️ SQLite DB
participant Engine as 🧠 Health Engine & Trends
participant Gemini as 🤖 Google Gemini API
Patient->>UI: Enters query ("I feel dizzy, are my vitals okay?")
UI->>API: POST /api/chat { patient_id, message, lang, history }
API->>DB: Query patient profile (Age, Gender, BMI, comorbidities)
API->>DB: Query latest recorded vitals (HR, SpO2, Temp)
API->>Engine: Compute 24h vital trends (HR slope, SpO2 stability)
Note over API: Synthesize Context Envelope:<br/>• Patient: 22y Female, BMI: 24<br/>• Current: HR 75, SpO2 98%, Temp 36.6°C<br/>• ML Prediction: Healthy (Confidence: 47%)<br/>• NEWS2 Score: 12/8 (Stable)
API->>API: Inject Clinical Safety System Instruction<br/>(Conservative, no prescriptions, emergency triage)
API->>Gemini: generate_content(contents, system_instruction, lang)
Gemini-->>API: Streamed plain-language medical response
API-->>UI: Return JSON { reply }
UI-->>Patient: Render localized advice in Chat UI
The intelligence layer combines rule-based clinical early warning scores with supervised machine learning:
| Component | Specification | Description |
|---|---|---|
| Model Algorithm | Gradient Boosting & Random Forest | Multi-class classification trained on comprehensive physiological datasets. |
| Classified Scenarios | 12 Clinical Conditions |
healthy, hypoxia, fever, asthma_exacerbation, copd_exacerbation, heart_failure, sepsis, respiratory_distress, cardiac_event, hypertension_crisis, pneumonia, critical. |
| Hemodynamic Derivations | MEWS & NEWS2 | Modified Early Warning Score & National Early Warning Score 2 composite calculations. |
| Cardiovascular Proxies | Shock Index, MAP, RPP | Non-invasive derivation of Shock Index ( |
| Clinical Guidelines | WHO Self-Care 2019 | Standardized, evidence-based triage and self-care steps matched to active scenario. |
The system supports real-time hardware telemetry transmission from portable edge devices:
- Microcontroller: ESP32-WROOM-32 (Dual-core 240MHz, 2.4GHz Wi-Fi + BLE).
- PPG Pulse Oximeter: MAX30102 optical sensor (I2C address
0x57) measuring real-time Photoplethysmogram waveforms for Heart Rate & SpO2. - Temperature Sensor: DS18B20 1-Wire digital probe or MLX90614 infrared ambient/skin sensor.
- Firmware: Arduino/C++ (
sketch_oct4a/sketch_oct4a.ino) with automated Wi-Fi reconnect and JSON serialization.
[ MAX30102 PPG ] --- (I2C: SDA/SCL) ---> [ ESP32 MCU ]
[ DS18B20 Temp ] --- (1-Wire: GPIO) ---> [ ESP32 MCU ]
|
(Wi-Fi 802.11 b/g/n)
|
v
[ Flask API: /api/patients/{id}/vitals ]
| Layer | Technologies |
|---|---|
| Frontend Framework | React.js 19, Vite 8, React Router 7 |
| Styling & UI | TailwindCSS 4, Lucide React Icons |
| Data Visualization | Recharts 3 (Interactive Time-series Area & Line Charts) |
| Backend Framework | Python 3.10+, Flask RESTful API, Flask-CORS |
| Machine Learning | Scikit-Learn, Pandas, NumPy, Joblib |
| Generative AI | Google Generative AI SDK (google-genai), Gemini 2.5 Flash |
| Database | SQLite3 with Thread-safe Connection Pools |
| Hardware | ESP32, MAX30102 (PPG), DS18B20/MLX90614 |
- Node.js: v18.0.0 or higher
- Python: v3.10 or higher
- Google Gemini API Key: Obtain from Google AI Studio
# Clone the repository
git clone https://github.com/divyani-22/Cep-project.git
cd Cep-project/backend
# Create and activate virtual environment
python -m venv venv
# On Windows:
venv\Scripts\activate
# On Linux/macOS:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Configure your Gemini API Key
# Create a .env file in the backend directory:
echo GEMINI_API_KEY=your_gemini_api_key_here > .env
# Initialize database and start Flask API server
python app.pyBackend runs on http://localhost:5000
# In a new terminal window, navigate to frontend:
cd Cep-project/frontend
# Install dependencies
npm install
# Start Vite development server
npm run devFrontend runs on http://localhost:5173
- Open
sketch_oct4a/sketch_oct4a.inoin Arduino IDE. - Install
SparkFun MAX3010x Pulse and Proximity Sensor LibraryandOneWire/DallasTemperature. - Configure your local Wi-Fi SSID, Password, and Backend host IP (
http://<YOUR_PC_IP>:5000/api/patients/<ID>/vitals). - Flash the code to your ESP32 board.
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/login |
Authenticate user (Doctor or Patient) |
POST |
/api/auth/register |
Register new clinician or patient account |
GET |
/api/doctors |
List all registered doctors |
GET |
/api/patients |
List patients linked to authenticated doctor |
GET |
/api/patients/<id> |
Fetch detailed patient profile and recent vitals |
POST |
/api/patients/<id>/vitals |
Ingest new physiological telemetry reading |
GET |
/api/patients/<id>/vitals |
Query historical time-series vitals readings |
GET |
/api/patients/<id>/trends |
Compute temporal slope and stability indicators |
GET |
/api/patients/<id>/report |
Generate comprehensive AI diagnostic clinical report |
POST |
/api/chat |
Send conversational prompt to context-aware Gemini AI assistant |
GET |
/api/health |
Health check endpoint and ML model status |





