A comprehensive web application for predicting diabetes likelihood based on medical input parameters. This project uses machine learning (Random Forest Classifier) and provides both Flask and FastAPI implementations with Docker support.
- main.py: FastAPI application providing REST API endpoints for diabetes prediction with automatic documentation.
- app.py: Flask web application with traditional web interface.
- train.py: Script to train the machine learning model using the dataset.
- models/: Directory where the trained model (diabetes_model.pkl) is saved.
- templates/: HTML files for the Flask web interface.
- static/: CSS and other static assets.
- requirements.txt: List of Python dependencies.
- Dockerfile: Docker configuration for containerized deployment.
- docker-build.bat & docker-run.bat: Windows batch scripts for Docker operations.
- Python 3.8 or higher installed on your system.
- Docker (optional, for containerized deployment).
-
Install Dependencies
Open a terminal in the project directory and run the following command to install the required Python packages:
pip install -r requirements.txt
-
Train the Model
Before running the application, you must generate the machine learning model. Run the training script:
python train.py
This will download the dataset, train the Random Forest model, and save it to
models/diabetes_model.pkl.
Run the FastAPI application with Uvicorn:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload- API Documentation: Visit http://127.0.0.1:8000/docs for interactive API documentation
- Health Check: http://127.0.0.1:8000/health
- API Endpoint: POST to http://127.0.0.1:8000/predict with JSON payload
Start the Flask web server:
python app.pyAccess the web interface at http://127.0.0.1:5000
-
Build the Docker Image
docker-build.bat
-
Run the Container
docker-run.bat
-
Build the Docker Image
docker build -t diabetes-prediction-app . -
Run the Container
docker run -p 8000:8000 diabetes-prediction-app
The application will be available at http://localhost:8000
- Enter the required patient information:
- Number of Pregnancies
- Glucose Level
- Blood Pressure
- BMI
- Age
- Click the "Predict" button.
- The system will display whether the patient is "Diabetic" or "Not Diabetic" along with a confidence percentage.