Skip to content

adamfutur/HAI

Repository files navigation

🩺 HAI - Health AI Diagnostic Tool ❀️

A full-stack machine learning web application for predicting the likelihood of diabetes and heart disease.

Python Flask React Scikit-learn License

πŸ“œ Table of Contents

πŸ“– Introduction

HAI (Health AI) helps users assess their risk for common health conditions by leveraging the power of machine learning. By inputting key health metrics, users receive real-time predictions for Diabetes and Heart Disease. The application features a clean, interactive frontend built with React and a robust backend API powered by Flask, serving pre-trained models.

Note: Replace the link above with a real screenshot of your application's UI.

✨ Key Features

  • πŸ” Dual-Disease Prediction: Assesses risk for both diabetes and heart disease.
  • 🧠 ML-Powered: Utilizes models trained on real-world clinical datasets for accurate predictions.
  • βš›οΈ Interactive UI: Modern, responsive user interface built with React.
  • πŸš€ Fast & Scalable API: Backend powered by Flask to serve model predictions efficiently.
  • πŸ“¦ Pre-packaged Models: Comes with serialized .pkl models and scalers, ready for immediate use.

πŸ› οΈ Tech Stack

Component Technology/Library
Frontend React, JavaScript, HTML/CSS
Backend Flask, Python
ML / Data Scikit-learn, Pandas, NumPy, Seaborn, Matplotlib
Environment venv, npm

πŸ“‚ Project Structure

The project repository is organized as follows:

HAI/
β”œβ”€β”€ 🐍 Flask_heart.py            # Flask backend for Heart Disease prediction
β”œβ”€β”€ 🐍 Flask_diabetes.py         # Flask backend for Diabetes prediction
β”‚
β”œβ”€β”€ πŸ““ diabetes_prediction.ipynb # Jupyter Notebook for Diabetes model training
β”œβ”€β”€ πŸ““ heart_disease_prediction.ipynb # Jupyter Notebook for Heart Disease model training
β”‚
β”œβ”€β”€ πŸ“¦ best_model_d.pkl          # Serialized model for Diabetes
β”œβ”€β”€ πŸ“¦ scaler_D.pkl              # Serialized scaler for Diabetes
β”œβ”€β”€ πŸ“¦ model.pkl                 # Serialized model for Heart Disease
β”œβ”€β”€ πŸ“¦ scaler.pkl                # Serialized scaler for Heart Disease
β”‚
β”œβ”€β”€ πŸ“Š diabetes.csv              # Dataset for Diabetes model
β”œβ”€β”€ πŸ“Š framingham.csv            # Dataset for Heart Disease model
β”‚
β”œβ”€β”€ πŸ“ requirements.txt          # Python dependencies
β”œβ”€β”€ πŸ“„ README.md                 # This file
β”‚
└── 🌐 frontend/                 # (Not included in this repo) React frontend code

πŸš€ Getting Started

Follow these steps to set up and run the project locally.

Prerequisites

Backend Setup (Flask)

  1. Clone the repository:

    git clone https://github.com/your-username/HAI.git
    cd HAI
  2. Create and activate a virtual environment:

    # For macOS/Linux
    python3 -m venv venv
    source venv/bin/activate
    
    # For Windows
    python -m venv venv
    venv\Scripts\activate
  3. Install Python dependencies:

    pip install -r requirements.txt

    Tip: If requirements.txt is missing, generate it via pip freeze > requirements.txt after installing the packages listed in the old README.

  4. Run the Flask server: Choose which prediction server you want to run.

    # To run the diabetes prediction server
    python Flask_diabetes.py
    
    # To run the heart disease prediction server
    python Flask_heart.py

    The API will be available at http://127.0.0.1:5000.

Frontend Setup (React)

Note: The frontend code is not included in this repository snapshot. These are general instructions.

  1. Navigate to the frontend directory:

    cd frontend
  2. Install npm dependencies:

    npm install
  3. Start the React development server:

    npm start

    The application UI will be available at http://localhost:3000. Ensure the frontend is configured to send API requests to the correct Flask URL (http://127.0.0.1:5000).

πŸ’» Usage

  1. Open your web browser and navigate to http://localhost:3000.
  2. Select either the "Diabetes Prediction" or "Heart Disease Prediction" form.
  3. Fill in the required health parameters.
  4. Click the "Predict" button.
  5. View the prediction result returned from the backend model.

πŸ”— API Endpoints

1. Predict Diabetes

  • Endpoint: /predict/diabetes
  • Method: POST
  • Description: Submits user data to predict the likelihood of diabetes.
  • Request Body (JSON):
    {
      "Pregnancies": 2,
      "Glucose": 120,
      "BloodPressure": 70,
      "SkinThickness": 20,
      "Insulin": 79,
      "BMI": 25.6,
      "DiabetesPedigreeFunction": 0.3
    }
  • Success Response (JSON):
    {
      "prediction": "The person is likely to be Diabetic.",
      "prediction_value": 1
    }

2. Predict Heart Disease

  • Endpoint: /predict/heart
  • Method: POST
  • Description: Submits user data to predict the likelihood of heart disease.
  • Request Body (JSON):
    {
      "age": 54, "sex": 1, "cp": 0, "trestbps": 130, "chol": 250, "fbs": 0,
      "restecg": 1, "thalach": 187, "exang": 0, "oldpeak": 1.0, "slope": 2,
      "ca": 0, "thal": 2
    }
  • Success Response (JSON):
    {
      "prediction": "The person is likely to have Heart Disease.",
      "prediction_value": 1
    }

🧠 Model Training

The machine learning models were trained using the following configurations:

Prediction Target Notebook Dataset Models Tested Saved Files
🩺 Diabetes diabetes_prediction.ipynb diabetes.csv KNN, SVC, Decision Tree, Random Forest, Gradient Boosting best_model_d.pkl, scaler_D.pkl
❀️ Heart Disease heart_disease_prediction.ipynb framingham.csv KNN, SVC, Decision Tree, Random Forest, Gradient Boosting model.pkl, scaler.pkl

To retrain the models, open the corresponding Jupyter Notebook, modify the code as needed, and run the cells to generate new .pkl files.

πŸ”Œ Troubleshooting

  • CORS Errors: If the React frontend cannot connect to the Flask API, ensure CORS is enabled in your Flask app.
    from flask_cors import CORS
    # Add this after initializing your app
    CORS(app)
  • Model Not Found (FileNotFoundError): Make sure all .pkl model and scaler files are located in the same directory as your Flask script.
  • Dependency Issues: Ensure you are using the correct virtual environment (source venv/bin/activate) and that all packages in requirements.txt are installed.

πŸ§‘β€πŸ’» Contributors

  • ADAMFUTUR - Development, Model Training, Integration

We welcome contributions! Please feel free to fork the repository, make improvements, and submit a pull request.

πŸ“„ License

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published