AI-powered neonatal risk assessment using MedGemma β built for the MedGemma Impact Challenge
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.
- π§ 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
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β
ββββββββββββββββ βββββββββββββββββ
| 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.
- Node.js β₯ 18
- Python β₯ 3.10
- llama.cpp (build instructions)
- MedGemma GGUF model (French fine-tune)
- EmbeddingGemma GGUF model
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# MedGemma (French fine-tune, ~3GB for Q5_K_M)
python download.py
# EmbeddingGemma β download a GGUF embedding model
# e.g., from https://huggingface.co# 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 --embeddingcd backend
python precompute_embeddings.py
# β Generates embeddings.npy (1,224 vectors) for the RAG corpus# 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:5173Open http://localhost:5173 β submit a French medical report and watch MedGemma analyze it.
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
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
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.
| 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.
- 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
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% |
πΉ Watch the demo video
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
This project was built for the MedGemma Impact Challenge by Google Research.
Built with β€οΈ for neonatal care at CHU Oujda, Morocco