Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PregnaCare

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.

Structure

  • ml/ - data analysis and the model training notebook
  • backend/ - FastAPI service that serves the model
  • frontend/ - React + TypeScript interface
  • docs/ - proposal and project documents

Tech stack

  • Model: XGBoost, scikit-learn, SHAP, imbalanced-learn (SMOTE)
  • Backend: Python, FastAPI
  • Frontend: React, TypeScript, Vite, Tailwind CSS

Running it

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.

Deployment

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_URL variable.

Steps

  1. Push code to GitHub; Render and Vercel build automatically from the repo.
  2. Backend on Render (root backend, start uvicorn app.main:app), with Python pinned via runtime.txt.
  3. Frontend on Vercel (root frontend, build npm run build), with the API and Supabase keys set as environment variables.
  4. Supabase redirect URLs updated for the live domain; CORS and HTTPS enabled.

Verification

  • /health returns {"status": "ok"}.
  • /predict was 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.

Links

Performance across environments

  • Browsers: tested in Arc and Chrome, with no difference in behaviour.
  • Local vs deployed: runs the same locally (npm run dev with 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.

Mobile view

PregnaCare is built in a responsive manner (mobile), since most users will access it on a phone.

Data

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.

Analysis

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.

Discussion

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.

Recommendations

  • 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.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages