Skip to content

kadzaki/NeuroGuard-NICU

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ NICU Neonate Risk Dashboard

AI-powered neonatal risk assessment using MedGemma β€” built for the MedGemma Impact Challenge

MedGemma EmbeddingGemma React FastAPI llama.cpp


πŸ“‹ Overview

A real-time clinical decision support dashboard for Neonatal Intensive Care Units (NICU) at CHU Oujda, Morocco. The system ingests free-text French medical reports, extracts 70+ structured clinical fields using MedGemma, performs risk assessment through RAG against a corpus of 1,230 real patient records, and provides explainable clinical interpretation β€” all running 100% locally with no cloud dependencies.

Key Features

  • 🧠 MedGemma-powered extraction β€” Parses unstructured French medical text into 70+ structured clinical fields
  • πŸ“Š Hybrid RAG retrieval β€” Field-based matching (60%) + embedding similarity (40%) across 1,230 real NICU cases
  • ⚠️ Risk assessment β€” Mortality and complication risk scoring grounded in similar historical cases
  • πŸ” Full case comparison β€” Shows complete clinical reports of similar cases organized by medical sections
  • πŸ₯ Clinical interpretation β€” AI-generated analysis explicitly referencing real similar cases
  • 🌍 Bilingual β€” Full French / English interface (i18n)
  • πŸ”’ Privacy-first β€” Everything runs locally via llama.cpp, no patient data leaves the hospital

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Frontend (React 19)                      β”‚
β”‚  HomePage β†’ PatientPage β†’ RiskCards / RAG Cases / Timeline   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚ REST API
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Backend (FastAPI)                          β”‚
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ LLM Service β”‚  β”‚ RAG Service  β”‚  β”‚    Storage (JSON)  β”‚   β”‚
β”‚  β”‚ (MedGemma)  β”‚  β”‚ Field+Embed  β”‚  β”‚  patients.json     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚         β”‚                β”‚                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                β”‚
  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  MedGemma    β”‚  β”‚ EmbeddingGemma β”‚
  β”‚  (llama.cpp) β”‚  β”‚ (llama.cpp)    β”‚
  β”‚  :8080       β”‚  β”‚ :8081          β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Two-Model Safety Architecture

Component Model Purpose
Extraction + Interpretation MedGemma 4B IT (French fine-tune) Parses reports β†’ structured JSON, generates clinical narrative
Risk Scoring RAG (field + embedding) Retrieves similar cases, computes weighted similarity β€” no LLM black-box risk

This separation ensures risk scores are auditable and explainable: clinicians can inspect exactly which historical cases drove the assessment and why.


πŸš€ Quick Start

Prerequisites

  • Node.js β‰₯ 18
  • Python β‰₯ 3.10
  • llama.cpp (build instructions)
  • MedGemma GGUF model (French fine-tune)
  • EmbeddingGemma GGUF model

1. Clone & Install

git clone https://github.com/<your-username>/nicu-neonate-dashboard.git
cd nicu-neonate-dashboard/neonate-dashboard

# Frontend
npm install

# Backend
cd backend
pip install -r requirements.txt

2. Download Models

# MedGemma (French fine-tune, ~3GB for Q5_K_M)
python download.py

# EmbeddingGemma β€” download a GGUF embedding model
# e.g., from https://huggingface.co

3. Start LLM Servers

# Terminal 1: MedGemma (structured extraction + interpretation)
llama-server -m MedGemmaModel/medgemma-4b-it-french-medical-assistant-q5_k_m.gguf --port 8080

# Terminal 2: EmbeddingGemma (semantic similarity for RAG)
llama-server -m <embedding-gemma.gguf> --port 8081 --embedding

4. Precompute Embeddings (one-time)

cd backend
python precompute_embeddings.py
# β†’ Generates embeddings.npy (1,224 vectors) for the RAG corpus

5. Launch the Application

# Terminal 3: Backend
cd backend
python main.py
# β†’ FastAPI server at http://localhost:8000

# Terminal 4: Frontend
cd neonate-dashboard
npm run dev
# β†’ Vite dev server at http://localhost:5173

Open http://localhost:5173 β€” submit a French medical report and watch MedGemma analyze it.


πŸ“ Project Structure

neonate-dashboard/
β”œβ”€β”€ src/                          # React 19 + TypeScript frontend
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ RagSimilarCases.tsx   # Full clinical reports of similar RAG cases
β”‚   β”‚   β”œβ”€β”€ RiskSummaryCards.tsx  # Risk level cards with trends
β”‚   β”‚   β”œβ”€β”€ ContributingFactors.tsx
β”‚   β”‚   β”œβ”€β”€ TrendTimeline.tsx     # Vitals timeline visualization
β”‚   β”‚   β”œβ”€β”€ ClinicalInterpretation.tsx
β”‚   β”‚   β”œβ”€β”€ SimilarCases.tsx      # LLM-generated case summaries
β”‚   β”‚   └── NewReportModal.tsx    # Report submission form
β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ HomePage.tsx          # Unit-wide patient overview
β”‚   β”‚   β”œβ”€β”€ PatientPage.tsx       # Individual patient risk profile
β”‚   β”‚   └── PatientRecordPage.tsx # Structured record viewer (70+ fields)
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ api.ts                # Backend API client
β”‚   β”‚   └── types.ts              # TypeScript interfaces
β”‚   β”œβ”€β”€ i18n.tsx                  # Bilingual translations (EN/FR)
β”‚   └── App.tsx                   # Router setup
β”‚
β”œβ”€β”€ backend/                      # FastAPI + Python backend
β”‚   β”œβ”€β”€ main.py                   # FastAPI app + CORS
β”‚   β”œβ”€β”€ routes.py                 # API endpoints (/api/reports, /api/patients, /api/stats)
β”‚   β”œβ”€β”€ llm_service.py            # MedGemma integration (Gemma chat template)
β”‚   β”œβ”€β”€ rag_service.py            # Hybrid RAG: field matching + embedding similarity
β”‚   β”œβ”€β”€ precompute_embeddings.py  # One-time embedding generation script
β”‚   β”œβ”€β”€ storage.py                # JSON-based patient record persistence
β”‚   β”œβ”€β”€ models.py                 # Pydantic schemas (70+ clinical fields)
β”‚   β”œβ”€β”€ .env                      # Server configuration
β”‚   β”œβ”€β”€ requirements.txt          # Python dependencies (zero OpenAI)
β”‚   └── rag_data/                 # RAG corpus
β”‚       β”œβ”€β”€ cr_1.json ... cr_1230.json  # 1,230 real patient records
β”‚       β”œβ”€β”€ embeddings.npy        # Precomputed embedding vectors
β”‚       └── embeddings_index.json # Filename-to-index mapping

πŸ”¬ How It Works

Pipeline: Report β†’ Analysis

1. Clinician pastes French medical report
          β”‚
2. Quick regex extraction (weight, GA, sex, CRP, APGAR)
          β”‚
3. RAG retrieval: field matching (60%) + embedding similarity (40%)
   β†’ Top 10 similar cases from 1,230-record corpus
          β”‚
4. MedGemma prompt: system instructions + report + similar cases
   β†’ Gemma chat template: <start_of_turn>user ... <end_of_turn>
          β”‚
5. MedGemma outputs JSON with:
   β€’ "record": 70+ structured clinical fields
   β€’ "dashboard": risk assessment, contributing factors,
     clinical interpretation grounded in real similar cases
          β”‚
6. Frontend renders: risk cards, trend timeline,
   full RAG case reports, clinical interpretation

RAG Similarity Scoring

The hybrid RAG engine combines two complementary approaches:

Method Weight Strengths
Field-based 60% Precise clinical matching (weight Β±200g, GA Β±2 weeks, same sex, CRP range)
Embedding-based 40% Semantic similarity (catches diagnosis paraphrasing, related conditions)

Field matching provides explainability (highlighted per-field comparisons in the UI), while embeddings improve recall for semantically similar but differently worded cases.


πŸ› οΈ Tech Stack

Layer Technology
Frontend React 19, TypeScript, Vite, React Router
Backend FastAPI, Pydantic, Uvicorn
LLM MedGemma 4B IT (French fine-tune, GGUF)
Embeddings EmbeddingGemma (GGUF)
Inference llama.cpp (local, no cloud)
RAG Field-based + cosine similarity (NumPy)
Data JSON files (1,230 real NICU records)
i18n Custom React Context (EN/FR)

Zero external API dependencies. Everything runs on-premise for maximum patient data privacy.


πŸ” Privacy & Safety

  • 100% local inference β€” Patient data never leaves the hospital network
  • No cloud APIs β€” MedGemma and EmbeddingGemma run via llama.cpp on local hardware
  • Explainable risk scores β€” RAG-based, not black-box LLM predictions
  • Clinical decision support β€” Assists clinicians, never replaces their judgment
  • Auditable β€” Every risk score can be traced back to specific similar cases and matching fields

πŸ“Š RAG Corpus

The system includes a corpus of 1,230 real neonatal patient records from CHU Oujda NICU:

Statistic Value
Total records 1,230
Structured fields per record 70+
Embedded records 1,224
Embedding dimensions 1,536
Survival rate ~85%

πŸŽ₯ Demo

πŸ“Ή Watch the demo video


🀝 Contributing

Contributions are welcome! Areas of interest:

  • Improving MedGemma prompt engineering for French medical text
  • Adding new clinical sections to the RAG corpus
  • Implementing embedding-based reranking
  • Database migration (JSON β†’ PostgreSQL) for production scale
  • Additional language support

πŸ“„ License

This project was built for the MedGemma Impact Challenge by Google Research.


Built with ❀️ for neonatal care at CHU Oujda, Morocco

About

NeuroGuard-NICU: Explainable AI Risk Intelligence for Neonatal Intensive Care

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors