Hybrid Clinical Intelligence: ML + LLM Reasoning (2026 Version)
A research-grade clinical decision support system combining Random Forest ML for statistical detection with Gemini LLM for clinical reasoning, explainability, and treatment planning.
Analytical Engine (ML)
- Random Forest trained on real hospital data + synthetic textbook cases.
- Feature engineering includes vitals + derived flags (
fever_high,tachycardia,hypotension,hypoxia). - Outputs preliminary diagnosis with confidence scores.
Reasoning Engine (LLM)
- Google Gemini 1.5 Flash validates ML predictions.
- Provides human-readable clinical reasoning, red flags, and differential diagnosis.
- Generates structured treatment plans.
Hybrid Orchestrator
MedicalOrchestratordynamically combines ML + LLM outputs.- Intelligent override ensures Gemini corrects vague or incorrect ML predictions.
- Severity and urgency scoring based on evidence-based rules.
-
Patient Data Intake
- Flask API receives structured patient data from frontend (
PatientFeatures).
- Flask API receives structured patient data from frontend (
-
ML Prediction
- Random Forest outputs disease category and confidence.
-
LLM Validation
- Gemini AI reviews ML output and applies overrides if needed.
-
Treatment Planning & Reasoning
- Clinical reasoning, differentials, red flags, and treatment plan included.
-
Data Storage & Reporting
- JSON patient records saved.
- PDF reports generated and downloadable.
| File / Folder | Role |
|---|---|
api.py |
Flask server exposing secure endpoints for patient data, predictions, and report downloads. |
AI_diagnosis.py |
Hybrid ML trainer (real + synthetic data). |
gen_ai_module.py |
Gemini LLM integration (validation & treatment planning). |
medical_orchestrator.py |
Hybrid intelligence orchestrator combining ML + LLM outputs. |
report_generator.py |
Generates PDF clinical reports. |
test_system.py |
Validation & stress-testing of the pipeline. |
models/ |
Trained ML model artifacts (.pkl, feature names, disease mapping). |
.env |
Gemini API key, model/report directories, optional rate limits. |
templates/ |
Frontend dashboard (HTML). |
static/ |
CSS/JS frontend assets. |
pip install -r requirements.txtGEMINI_API_KEY=your_key_here
MODEL_DIR=./output
REPORTS_DIR=./output/reports
PATIENT_DIR=./output/patient_data
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5000
FLASK_ENV=developmentpython AI_diagnosis.pypython api.pyPOST /api/predict
Content-Type: application/json
{
"age": 58,
"gender": "male",
"temperature": 37.2,
"heartRate": 95,
"systolicBP": 150,
"diastolicBP": 95,
"respiratoryRate": 20,
"oxygenSaturation": 96,
"painScore": 9,
"symptoms": ["chest pain", "fatigue", "nausea", "dizziness"],
"medical_history": ["hypertension"],
"allergies": [],
"medications": ["aspirin"]
}- Hybrid AI: ML + LLM reasoning.
- Augmented Training: Synthetic cases complement real hospital data.
- Explainable AI: Full clinical reasoning, differentials, red flags.
- Intelligent Overrides: Gemini corrects vague/incorrect ML predictions.
- Treatment Planning: Structured plans generated dynamically.
- Severity & Urgency: Evidence-based scoring and triage.
- Secure API: Rate-limited, CORS-restricted, and path-traversal safe.
- PDF Reports: Downloadable via
/download/. - Patient Data Storage: JSON records with retrieval and deletion endpoints.
| Endpoint | Method | Description |
|---|---|---|
/api/predict |
POST | Hybrid ML+LLM diagnosis, returns PDF link and reasoning. |
/download/<filename> |
GET | Download report PDF securely. |
/api/status |
GET | Server health check & model/LLM availability. |
/api/get-reports |
GET | List latest PDF reports. |
/api/delete-report/<filename> |
DELETE | Delete report PDF. |
/api/get-patients |
GET | List latest patient JSON records. |
/download-patient/<filename> |
GET | Download patient JSON securely. |
/api/delete-patient/<filename> |
DELETE | Delete patient JSON record. |
python test_system.py- Research Prototype: Not intended for real-world clinical diagnosis.
- **Use only under professional supervision.
---