An offline, privacy-first AI diagnostic dashboard that runs entirely on your machine β no cloud, no internet required.
- Overview
- Demo / Screenshots
- Supported Diseases
- Project Structure
- Tech Stack
- Getting Started
- How It Works
- Training Your Own Models
- Model Accuracy Summary
- Configuration
- Contributing
- Disclaimer
- License
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.jsonpair
| 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:5000in your browser.
| 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 |
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:
.onnxmodel files are excluded from version control (see.gitignore).
Runpython convert_to_onnx.pyafter cloning to regenerate them.
| 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 |
| 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 |
| 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) |
- Python 3.8 or higher
pip(comes with Python)- Git
# 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 savedandβ Metadata savedmessages for each disease.
# Start the Flask web server
python edge_ui.pyOpen your browser and navigate to:
http://127.0.0.1:5000
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.
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.pyThe _meta.json file (with features and accuracy) is auto-generated and read by the web app.
| 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.
| 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 |
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-disease-model - Commit your changes:
git commit -m "feat: add kidney disease model" - Push to your branch:
git push origin feature/new-disease-model - Open a Pull Request
Please ensure any new model is accompanied by:
- A properly labeled dataset in
data/ - A working entry in
DATASETSinconvert_to_onnx.py - Updated accuracy in this README
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.
This project is licensed under the MIT License.
See the LICENSE file for details.
Built with β€οΈ for offline, privacy-first AI healthcare