MCPcopy Create free account
hub / github.com/aliviahossain/Disease-prediction

github.com/aliviahossain/Disease-prediction @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
709 symbols 2,050 edges 89 files ⚖ MIT 303 documented · 43% ● updated 11d ago★ 6925 open issues

Browse by type

⨍ Functions 597◇ Types & classes 52↳ Endpoints 60
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

🧠 Disease Prediction System

Python Flask License Status Educational

An ML-powered web app that uses Bayes' Theorem and machine learning to estimate disease likelihood from symptoms — built for students, researchers, and developers.

🚀 Live Demo · 🐛 Report a Bug · 💡 Request a Feature

🎬 Watch the 60-second demo

Disease Prediction — 60 second demo video

Click the preview to play the demo video (MP4, 1080p, with sound).


⚠️ Disclaimer: Educational Use Only This project is for learning and demonstration purposes only. It is not a medical tool and must not be used for real-world diagnosis or treatment. Always consult a qualified healthcare professional.


📋 Table of Contents


🔍 About the Project

The Disease Prediction System makes medical reasoning transparent and interactive. It combines classical Bayesian probability with modern ML to show users not just what a prediction is, but why — step by step.

It's designed to bridge the gap between complex statistical concepts and intuitive understanding, with visual charts, AI-powered explanations, and multi-language support.


✨ Key Features

📘 Educational

Feature Description
Bayes' Theorem Visualizer Step-by-step breakdown of prior → posterior probability
Interactive Sliders Experiment with probability values in real time
Built-in Glossary Plain-English definitions of medical/statistical terms

🤖 ML & Prediction

Feature Description
Symptom-Based Prediction Select symptoms to get ML-generated probability scores
BMI Integration Height/weight inputs contribute to risk estimation
Risk Categorization Results classified as Low / Medium / High risk
Prediction History Stored timeline of past predictions with analytics

🧠 AI Features

Feature Description
AI Explanations Gemini-powered interpretation of results
Next-Step Guidance Suggests consultation, testing, or lifestyle review
Multi-Language Output English 🇬🇧 · Hindi 🇮🇳 · Gujarati 🇮🇳 · Tamil 🇮🇳

📊 Analytics Dashboard

  • Comparative probability trend charts
  • Risk distribution graphs
  • Historical prediction tables

🛠 Tech Stack

Layer Technology
Backend Python, Flask
Frontend HTML, CSS, JavaScript
ML / Math Bayesian Inference, ResNet CNN
AI Google Gemini API
Dashboard Streamlit
Data CSV (data/hospital_data.csv)

🚀 Quick Start

Option 1 — View Online (instant, no setup) 👉 https://disease-prediction-nwnu.onrender.com

Option 2 — Run Locally (no configuration needed)

git clone https://github.com/aliviahossain/Disease-prediction.git
cd Disease-prediction
pip install -r requirements.txt
python run.py

Then open your browser at: http://127.0.0.1:5001/

That's it. You don't need a .env file to run locally. python run.py starts in development mode, generates a temporary SECRET_KEY, and turns off the AI features until you add a GEMINI_API_KEY (see step 4).

Want to… Command
Use a different port PORT=8000 python run.py (PowerShell: $env:PORT=8000; python run.py)
Open the Streamlit analytics dashboard streamlit run dashboard/dashboard.py → http://127.0.0.1:8501
Run with Docker instead docker compose up --build (needs a .env; see below)

🛠️ Detailed Setup

1. Create a Virtual Environment (Recommended)

python -m venv venv
source venv/bin/activate      # macOS / Linux
venv\Scripts\activate         # Windows

2. Install Dependencies

pip install -r requirements.txt

3. Configure Environment Variables (optional for local use)

You can skip this step for a quick local run. Create a .env when you want AI features, a persistent SECRET_KEY (so you stay logged in across restarts), or a Docker/production deployment.

Create your local .env by copying the provided template:

cp .env.example .env          # macOS / Linux
copy .env.example .env        # Windows (cmd)
Copy-Item .env.example .env   # Windows (PowerShell)

Then open .env and fill in the values. At minimum, generate a fresh SECRET_KEY:

python -c "import secrets; print(secrets.token_hex(32))"

Paste the output into the SECRET_KEY= line. The default SECRET_KEY in .env.example is public — never reuse it.

4. (Optional) Enable AI Recommendations

Get a free API key from Google AI Studio, then set GEMINI_API_KEY in your .env:

GEMINI_API_KEY=your_key_here

Alternatively, export it as an environment variable:

export GEMINI_API_KEY=your_key_here    # macOS / Linux
set GEMINI_API_KEY=your_key_here       # Windows

5. Run the App

python run.py

The app is served at http://127.0.0.1:5001/. Set PORT or HOST to change where it listens. To run the Flask app and the Streamlit dashboard together the way production does, use bash scripts/start.sh.


📦 Deployment

The application can be deployed to Google Cloud Run.

See docs/deployment/gcp-cloud-run.md for deployment instructions.


🧮 How It Works

Bayes' Theorem

The app updates disease probability after observing symptoms or test results using:

P(Disease | Evidence) = [ P(Evidence | Disease) × P(Disease) ]
                        ─────────────────────────────────────────────────────────
                        [ P(Evidence | Disease) × P(Disease) + P(Evidence | No Disease) × P(No Disease) ]
Term Meaning
P(Disease) Prior probability — baseline disease prevalence
P(Evidence\|Disease) Sensitivity — how often evidence appears given disease
P(Evidence\|No Disease) False positive rate
P(Disease\|Evidence) Posterior — updated probability after new evidence

BMI Integration

The system accepts height (cm) and weight (kg) to compute BMI, which adjusts risk estimates:

BMI = weight (kg) / (height in meters)²
BMI Range Category
Below 18.5 Underweight
18.5 – 24.9 Normal
25 – 29.9 Overweight
30+ Obese

🗂️ Project Structure

Disease-prediction/
├── run.py                         # App entry point (python run.py)
├── requirements.txt               # Python dependencies
├── .env.example                   # Environment variable template
├── Dockerfile, docker-compose.yml # Container / deployment config
├── backend/                       # Flask application
│   ├── routes/                    # Flask routes (auth, ML, calculator)
│   ├── models/                    # Database & ML models
│   ├── utils/                     # Bayesian calculator & AI helpers
│   ├── static/                    # JS, CSS & images
│   ├── templates/                 # HTML templates
│   └── tests/                     # Backend test suite (run in CI)
├── dashboard/
│   └── dashboard.py               # Streamlit analytics dashboard
├── data/                          # All datasets
│   ├── hospital_data.csv          # Bayesian stats used by the app
│   ├── hospital_data.example.csv  # Format template
│   ├── raw/                       # Source datasets
│   └── cleaned/                   # Pipeline output
├── database/                      # Your local data: accounts & history (git-ignored)
├── docs/                          # All documentation (setup, deployment, security, …)
├── scripts/                       # Data pipeline & maintenance scripts
│   ├── fetch_datasets.py          # Download raw datasets
│   ├── preprocess.py              # Rebuild data/hospital_data.csv
│   ├── seed_diseases.py           # Seed the diseases DB table
│   └── start.sh                   # Run Flask + Streamlit together
├── tests/                         # Additional tests
├── README.md
└── LICENSE

You can run every script from any directory, for example python scripts/preprocess.py.


📊 Dataset & Model

Bayesian Calculator Datasets

Disease Dataset Source
Heart Disease UCI Heart Disease Dataset UCI Repository
Diabetes Pima Indians Diabetes Dataset Kaggle
Breast Cancer Breast Cancer Wisconsin UCI Repository

To regenerate data/hospital_data.csv from the raw datasets in data/raw/:

python scripts/preprocess.py

To re-download the raw datasets, run pip install ucimlrepo and then python scripts/fetch_datasets.py.

Image Classification Datasets

Model Dataset Conditions
Eye Disease CNN Eye Diseases Classification (Kaggle) Glaucoma, Diabetic Retinopathy, Cataract, Normal
Skin Disease CNN Skin Diseases Image Dataset (Kaggle) Melanoma, Eczema, Psoriasis, and 7 others

The CNN architecture is based on ResNet, inspired by He et al. (2016) — Deep Residual Learning for Image Recognition.


🔒 Privacy & Data Handling

  • ✅ All calculations run locally on your machine
  • ✅ No symptoms, images, or personal data are uploaded or stored externally
  • ✅ AI requests only transmit probability values — never user identity
  • ✅ Accounts and prediction history are stored in a local database on your machine (see below)

🗄️ Data Storage

All app data is stored in one dedicated database file:

database/
├── disease_prediction.db   # accounts, password hashes, profiles, prediction history,
│                           # and Streamlit dashboard history
└── .secret_key             # local dev key that keeps you signed in across restarts
  • You only register once. Your account is kept between runs and restarts. Signing up also signs you in straight away.
  • You stay signed in for 30 days. "Keep me signed in" is on by default on the login page.
  • Passwords are never stored in plain text. Only bcrypt hashes are saved.
  • The folder is git-ignored, so your data is never committed. Back it up by copying the database/ folder.
  • Upgrading from an older version? Your existing backend/site.db and JSON history are imported automatically the first time you start the app. The old files are left in place.
  • Docker: docker compose mounts ./database into the container, so data survives rebuilds.
  • Custom location or external database: set DATABASE_DIR=/path/to/folder, or DATABASE_URL=postgresql://… to use PostgreSQL or MySQL instead.
  • Tests use a temporary database and never touch your real data.

🔧 Troubleshooting

AI recommendations not working?

  • Make sure GEMINI_API_KEY is set correctly
  • Restart the application after setting the key
  • Check your internet connection
  • Verify your API quota at Google AI Studio

App not starting?

  • Confirm Python version is 3.9 or higher: python --version
  • Activate your virtual environment before running
  • Reinstall dependencies: pip install -r requirements.txt
  • Run from the project root: python run.py
  • Port 5001 already in use? Start on another port: PORT=8000 python run.py
  • SECRET_KEY environment variable is required? Your .env or shell sets FLASK_ENV=production. For local work, change it to FLASK_ENV=development or set a SECRET_KEY.

🤝 Contributing

Contributions are warmly welcome! Here's how to get started:

  1. Fork the repository
  2. Create a new branch: git checkout -b feature/your-feature-name
  3. Make your changes and commit: git commit -m "Add: your meaningful message"
  4. Push to your fork: git push origin feature/your-feature-name
  5. Open a Pull Request

Please read CONTRIBUTING.md and CODE_OF_CONDUCT.md before contributing. More guides (setup, deployment, Gemini, security, privacy) are in docs/.


📜 License

This project is licensed under the MIT License — see the LICENSE file for details.


Created and maintained by Alivia Hossain

⭐ If you find this project useful, consider giving it a star!

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 371
Method 226
Route 60
Class 52

Languages

Python93%
TypeScript7%

Modules by API surface

backend/middleware/security.py37 symbols
backend/middleware/error_handler.py34 symbols
backend/tests/test_uncertainty_handler.py27 symbols
backend/middleware/logger.py27 symbols
backend/static/script.js26 symbols
backend/tests/test_doctor_dashboard.py25 symbols
backend/routes/auth_routes.py24 symbols
backend/tests/test_patient_history.py23 symbols
backend/routes/disease_routes.py23 symbols
backend/tests/test_fetch_endpoints.py22 symbols
tests/test_calculator.py21 symbols
backend/models/ml_model.py20 symbols

Datastores touched

(mysql)Database · 1 repos
disease_dbDatabase · 1 repos
disease_dbDatabase · 1 repos

For agents

$ claude mcp add Disease-prediction \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page