How milan-tj/disease-prediction-system works
Purpose and Entry Points
This repository is a Flask-deployed disease prediction system. Users select symptoms, receive an ML disease prediction with ranked probabilities, disease context/precautions, and an optional Gemini-generated diet and lifestyle recommendation.
Primary runtime entry point: app/app.py. Core inference and GenAI integration are split between app/predictor.py and reusable models/pipeline.py.
Web Request and Presentation Layer
The Flask application serves a symptom-selection form and renders prediction results. It is the boundary between browser form data and model-ready symptom inputs.
• app/app.py
• app/templates/home.html
• app/templates/result.html
The UI submits one or more symptom identifiers; the result view displays selected symptoms, predicted disease, confidence/top predictions, description, precautions, and generated recommendations. Styling is isolated in app/static/style.css.
Inference Feature Contract
Inference depends on a fixed ordered set of 132 binary symptom features. Selected symptom names are converted to a zero-filled vector with enabled positions set to 1; ordering must exactly match training-time feature order.
• models/symptom_cols.json
• app/predictor.py
• models/pipeline.py
This feature-schema artifact is a critical compatibility boundary: changing symptom names or ordering requires retraining and regenerating serialized model artifacts.
Model Serving and Ranking
The production model is serialized Bernoulli Naive Bayes, selected for small size and fast inference. The serving pipeline loads artifacts once at startup, invokes prediction and probability APIs, then maps class IDs to disease names and returns the highest-confidence result plus top-three candidates.
• models/best_model.pkl
• models/bernoulli_nb.pkl
• models/disease_label_mapping.csv
Alternative trained classifiers exist for evaluation or future model selection: models/random_forest.pkl, models/svm_rbf.pkl, models/xgboost.pkl, and models/decision_tree.pkl.
Disease Knowledge Enrichment
Prediction output is enriched using tabular reference data rather than generated solely from the classifier. Disease descriptions and precaution records are joined by disease name; severity is derived from selected symptoms and severity weights.
• data/symptom_Description.csv
• data/symptom_precaution.csv
• data/Symptom-severity.csv
These data files form the deterministic health-information layer feeding both UI results and the GenAI prompt.
Gemini Recommendation Boundary
The recommendation stage builds a structured prompt from predicted disease, selected symptoms, descriptions, precautions, and computed severity. It calls Google Gemini through the google-genai SDK, using GEMINI_API_KEY from the environment. Missing credentials, quota exhaustion, or API failure should resolve through the pipeline’s structured mock/fallback response rather than blocking core prediction.
• app/predictor.py
• models/pipeline.py
External dependency: Google Gemini (documented as Gemini Flash / configured model variant). This is the sole network-dependent stage; ML prediction and reference-data enrichment remain local.
Training Artifacts and Offline Lifecycle
The deployed artifacts originate from cleaned symptom datasets and model-development notebooks. Training, validation, deduplication analysis, and comparative model evaluation are offline concerns; deployment consumes only their persisted outputs.
• data/Training_cleaned.csv
• data/Testing_cleaned.csv
• notebook/Ticket2_Model_Development.ipynb
Operational runtime is Python with Flask, pandas, scikit-learn, joblib, and google-genai; dependencies are declared in requirements.txt.
Main entry points: pipeline.py Inference pipeline · app.py Flask application · predictor.py Prediction adapter · Ticket2_Model_Development.ipynb Model development
Components 15
Web interface
- Symptom-selection browser
- Symptom form
app/templates/home.html - Prediction results
app/templates/result.html - Flask application · Translates form selections into prediction requests and renders responses.
app/app.py
Local serving pipeline
- Prediction adapter
app/predictor.py - Inference pipeline · Loads artifacts once and coordinates inference, enrichment, and recommendation fallback.
models/pipeline.py - 132-symptom feature order · Ordered binary-feature compatibility contract.
models/symptom_cols.json - Bernoulli NB model
models/best_model.pkl - Disease label mapping
models/disease_label_mapping.csv
Health knowledge
- Disease descriptions & precautions · Deterministic disease context joined by disease name.
data/symptom_Description.csv - Symptom severity weights
data/Symptom-severity.csv
Offline model lifecycle
- Cleaned train/test data
data/Training_cleaned.csv - Model development · Trains and compares candidate classifiers offline.
notebook/Ticket2_Model_Development.ipynb - Alternative classifiers · Random forest, SVM, XGBoost, and decision tree artifacts.
models/random_forest.pkl
Other components
- Google Gemini · Optional network recommendation provider.
Connections 16
- Symptom-selection browser → Flask application: submits symptoms
- Flask application → Symptom form: renders form
- Flask application → Prediction adapter: prediction request
- Prediction adapter → Inference pipeline: selected symptoms
- Inference pipeline → 132-symptom feature order: vectorizes in fixed order
- Inference pipeline → Bernoulli NB model: predicts probabilities
- Inference pipeline → Disease label mapping: maps class to disease
- Inference pipeline → Disease descriptions & precautions: joins description and precautions
- Inference pipeline → Symptom severity weights: computes severity
- Inference pipeline → Google Gemini: optional structured prompt · Uses environment API key; failures return a local fallback.
- Prediction adapter → Flask application: enriched result
- Flask application → Prediction results: renders result
- Cleaned train/test data → Model development: offline training and validation
- Model development → Bernoulli NB model: selected deployment artifact
- Model development → Alternative classifiers: comparative artifacts
- 132-symptom feature order → Bernoulli NB model: training-serving contract