Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ Edge-ML Medical Diagnosis System

An offline, privacy-first AI diagnostic dashboard that runs entirely on your machine β€” no cloud, no internet required.

Python Flask ONNX Runtime scikit-learn License: MIT


πŸ“‹ Table of Contents


🌟 Overview

The Edge-ML Medical Diagnosis System uses machine learning models converted to ONNX format and served through a local Flask web application. It provides instant, browser-based medical screening for six diseases β€” all running 100% offline on your CPU.

Key design principles:

  • πŸ”’ Privacy-first β€” patient data never leaves your machine
  • ⚑ Real-time β€” sub-second inference with ONNX Runtime on CPU
  • πŸ“‘ Offline-ready β€” works in clinics with no internet
  • 🧩 Extensible β€” add new diseases by dropping in a new .onnx + _meta.json pair

πŸ–₯️ Demo / Screenshots

Dashboard View Prediction Form Analytics View
Summary cards with total predictions, positives, negatives Dynamic form generated from model metadata Confidence bar, trend chart, disease distribution

Launch the app and open http://127.0.0.1:5000 in your browser.


🦠 Supported Diseases

Disease ML Algorithm Key Input Features
Diabetes Random Forest Glucose, BMI, Age, Insulin, Blood Pressure
Heart Disease Random Forest Age, Cholesterol, Chest Pain Type, Max Heart Rate
Lung Cancer Logistic Regression Smoking, Coughing, Chest Pain, Shortness of Breath
Parkinson's Disease SVM (RBF Kernel) 22 voice measurement features (MDVP, Jitter, Shimmer)
Thyroid (Hypothyroid) Gradient Boosting TSH, T3, TT4, T4U, FTI, Age
PCOS Random Forest BMI, Testosterone Level, Antral Follicle Count

πŸ“ Project Structure

edge-ml-medical-diagnosis/
β”‚
β”œβ”€β”€ edge_ui.py              # πŸš€ Main Flask web application (entry point)
β”œβ”€β”€ convert_to_onnx.py      # πŸ€– Model training & ONNX export pipeline
β”œβ”€β”€ requirements.txt        # πŸ“¦ Python dependencies
β”‚
β”œβ”€β”€ templates/
β”‚   └── index.html          # Jinja2 HTML dashboard template
β”‚
β”œβ”€β”€ static/
β”‚   β”œβ”€β”€ style.css           # Complete design system (dark medical theme)
β”‚   β”œβ”€β”€ app.js              # Frontend logic (validation, animations, a11y)
β”‚   └── js/
β”‚       └── chart.min.js    # Bundled Chart.js (offline capable)
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ diabetes_model.onnx       # (generated β€” see Training section)
β”‚   β”œβ”€β”€ diabetes_meta.json        # Feature list + accuracy metadata
β”‚   β”œβ”€β”€ heart_model.onnx
β”‚   β”œβ”€β”€ heart_meta.json
β”‚   β”œβ”€β”€ lung_model.onnx
β”‚   β”œβ”€β”€ lung_meta.json
β”‚   β”œβ”€β”€ parkinsons_model.onnx
β”‚   β”œβ”€β”€ parkinsons_meta.json
β”‚   β”œβ”€β”€ thyroid_model.onnx
β”‚   β”œβ”€β”€ thyroid_meta.json
β”‚   β”œβ”€β”€ pcos_model.onnx
β”‚   └── pcos_meta.json
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ diabetes_data.csv
β”‚   β”œβ”€β”€ heart_disease_data.csv
β”‚   β”œβ”€β”€ survey lung cancer.csv
β”‚   β”œβ”€β”€ parkinson_data.csv
β”‚   β”œβ”€β”€ hypothyroid.csv
β”‚   └── pcos_data.csv
β”‚
└── prediction_history.csv  # (auto-created at runtime)

Note: .onnx model files are excluded from version control (see .gitignore).
Run python convert_to_onnx.py after cloning to regenerate them.


πŸ› οΈ Tech Stack

Backend

Tool Purpose
Python 3.8+ Core language
Flask Local web server & routing
ONNX Runtime CPU inference engine for .onnx models
NumPy Numerical array formatting for model input

ML / Training

Tool Purpose
scikit-learn Model training (Random Forest, SVM, Logistic Regression, Gradient Boosting)
pandas Data loading, cleaning, preprocessing
skl2onnx Converts trained sklearn models β†’ ONNX format

Frontend

Tool Purpose
HTML5 / Jinja2 Dashboard structure & server-side templating
Vanilla CSS Custom dark medical design system, glassmorphism
Vanilla JavaScript Form validation, animations, accessibility
Chart.js Interactive trend and distribution charts (bundled locally)

πŸš€ Getting Started

Prerequisites

  • Python 3.8 or higher
  • pip (comes with Python)
  • Git

Installation

# 1. Clone the repository
git clone https://github.com/your-username/edge-ml-medical-diagnosis.git
cd edge-ml-medical-diagnosis

# 2. Create and activate a virtual environment
python -m venv .venv

# On Windows:
.venv\Scripts\activate

# On macOS/Linux:
source .venv/bin/activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. Generate the ONNX models from the training data
python convert_to_onnx.py

⏱️ Model training takes 2–5 minutes on a standard machine.
You should see βœ… ONNX saved and βœ… Metadata saved messages for each disease.

Running the App

# Start the Flask web server
python edge_ui.py

Open your browser and navigate to:

http://127.0.0.1:5000

βš™οΈ How It Works

User selects disease
        β”‚
        β–Ό
Flask loads ONNX model + metadata (features list)
        β”‚
        β–Ό
Dynamic HTML form rendered (one field per feature)
        β”‚
        β–Ό
User enters clinical values β†’ submits form
        β”‚
        β–Ό
Flask runs ONNX inference (onnxruntime.session.run)
        β”‚
        β–Ό
Confidence score extracted (probability or sigmoid fallback)
        β”‚
        β–Ό
Result saved to prediction_history.csv
        β”‚
        β–Ό
Analytics view: result card + confidence bar + charts

Robust confidence extraction: The ONNX output parser handles multiple output schemas (probability vector, discrete label, raw logit) with multi-stage fallback logic β€” ensuring a valid confidence score regardless of which sklearn model type was used.


πŸ€– Training Your Own Models

The training pipeline (convert_to_onnx.py) is fully configurable. To add a new disease:

1. Add your dataset to the data/ folder.

2. Register it in the DATASETS dictionary inside convert_to_onnx.py:

DATASETS = {
    # ... existing entries ...
    "kidney": {
        "file": "data/kidney_disease.csv",
        "target": "classification",
        "model": "random_forest",      # logistic | random_forest | gradient_boosting | svm_rbf
        "onnx": "kidney_model.onnx"
    }
}

3. Register it in the Flask app (edge_ui.py, line 104):

diseases = ["diabetes", "heart", "lung", "parkinsons", "thyroid", "pcos", "kidney"]

4. Re-run the training pipeline:

python convert_to_onnx.py

The _meta.json file (with features and accuracy) is auto-generated and read by the web app.


πŸ“Š Model Accuracy Summary

Disease Algorithm Test Accuracy
Diabetes Random Forest 73.4%
Heart Disease Random Forest 83.6%
Lung Cancer Logistic Regression 96.8%
Parkinson's Disease SVM (RBF) 89.7%
Thyroid (Hypothyroid) Gradient Boosting 97.5%
PCOS Random Forest 100%*

*PCOS accuracy of 100% on a small dataset may indicate overfitting. Use with caution.
All models are trained on publicly available research datasets.


βš™οΈ Configuration

Setting Location Default
Flask debug mode edge_ui.py β†’ app.run(debug=True) True (dev only)
Flask port edge_ui.py β†’ app.run(port=...) 5000
Model folder edge_ui.py β†’ MODEL_FOLDER "models"
History file edge_ui.py β†’ HISTORY_FILE "prediction_history.csv"
Training datasets convert_to_onnx.py β†’ DATASETS See dict

🀝 Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-disease-model
  3. Commit your changes: git commit -m "feat: add kidney disease model"
  4. Push to your branch: git push origin feature/new-disease-model
  5. Open a Pull Request

Please ensure any new model is accompanied by:

  • A properly labeled dataset in data/
  • A working entry in DATASETS in convert_to_onnx.py
  • Updated accuracy in this README

⚠️ Disclaimer

This tool is for educational and research purposes only.
It is NOT a substitute for professional medical advice, diagnosis, or treatment.
Model predictions are based on publicly available research datasets and have not been clinically validated.
Always consult a qualified healthcare professional for medical decisions.


πŸ“„ License

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


Built with ❀️ for offline, privacy-first AI healthcare

About

Offline Edge AI medical diagnosis system using Flask, ONNX Runtime, and ML.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages