A web app that gives pregnant women a simple pregnancy-risk reading (low, moderate, or high) and explains in plain language what is driving it. Built as my BSE capstone project at African Leadership University.
ml/- data analysis and the model training notebookbackend/- FastAPI service that serves the modelfrontend/- React + TypeScript interfacedocs/- proposal and project documents
- Model: XGBoost, scikit-learn, SHAP, imbalanced-learn (SMOTE)
- Backend: Python, FastAPI
- Frontend: React, TypeScript, Vite, Tailwind CSS
Backend:
cd backend
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reload
API docs are at http://127.0.0.1:8000/docs
Frontend:
cd frontend
npm install
npm run dev
Notebook: open ml/pregnacare_risk_model.ipynb in Google Colab and run all cells.
The app is deployed and verified running in its live environment.
Tools and environments
- Frontend: React (Vite) on Vercel.
- Backend: FastAPI serving the XGBoost model on Render.
- Auth and data: Supabase (managed PostgreSQL).
- The frontend connects to the backend through the
VITE_API_URLvariable.
Steps
- Push code to GitHub; Render and Vercel build automatically from the repo.
- Backend on Render (root
backend, startuvicorn app.main:app), with Python pinned viaruntime.txt. - Frontend on Vercel (root
frontend, buildnpm run build), with the API and Supabase keys set as environment variables. - Supabase redirect URLs updated for the live domain; CORS and HTTPS enabled.
Verification
/healthreturns{"status": "ok"}./predictwas tested from the live site with healthy, borderline, and high-risk values, returning the expected risk levels.- Invalid inputs are rejected with range hints instead of crashing.
Note: The backend uses a free tier that sleeps when idle, so the first request after inactivity takes a few seconds to wake.
- Live app: PregnaCare Link
- Backend API (docs): Backend Documentation
- Demo video: Demo Link
- Source code: Github Link
- Browsers: tested in Arc and Chrome, with no difference in behaviour.
- Local vs deployed: runs the same locally (
npm run devwith the local FastAPI backend) as it does deployed on Vercel and Render. - Hosting note: on the deployed free tier the backend sleeps when idle, so the first request after inactivity takes a few seconds to wake, then responds normally.
PregnaCare is built in a responsive manner (mobile), since most users will access it on a phone.
The model is trained on the public UCI Maternal Health Risk dataset (clinical vitals). The Rwanda DHS 2019-20 is used only for context analysis of the Rwandan setting. It is not committed here because access requires registration with the DHS Program.
Three models were compared on the same data: Logistic Regression (a simple baseline), Random Forest, and XGBoost. XGBoost performed best and was chosen. On the held-out test set it reached a weighted F1 of 0.78 and an AUC of 0.90. Most importantly, it caught 90% of high-risk cases, missing only one out of 41, which matters most for a screening tool. SHAP analysis showed blood sugar and blood pressure as the main risk drivers, which are medically sensible factors. The train, validation, and test scores were compared and show a mild gap, pointing to some over-fitting that is expected for this model and dataset size.
The results show that pregnancy risk can be estimated from a small set of obtainable clinical readings and explained to users in plain language. The high recall on high-risk cases suggests the tool is suitable as a risk-awareness and referral aid, not a diagnosis. The main limitations are that the training data is not Rwandan (the Rwanda DHS is used only to describe the local context), the dataset contains duplicate records that were disclosed, and evaluation with real users is planned once a health-centre partnership are in place. The mild over-fitting gap also means the reported test score is the honest measure of performance.
- Reduce over-fitting through stronger regularisation and more data.
- Complete usability sessions and a need-and-feasibility survey with pregnant women at a health centre.
- Have the Kinyarwanda content reviewed by a health professional and a native speaker, especially the danger-sign wording.
- Explore phone-based access for women without smartphones or email.