You are on page 1of 23

TYBSC-CS(SEM V)

“HEART DISEASES PREDICTION”


A Project Report
Submitted in partial fulfilment of the
Requirements of the award of the Degree of

BACHELOR OF SCIENCE (COMPUTER SCIENCE)


By

MR. AJAI RADHAKRISHNAN


Roll No : 64
Under the esteemed guidance of

DR. PRIYANKA BRID


Designation
Assistant Professor

DEPARTMENT OF COMPUTER SCIENCE


Vishnu Waman Thakur Charitable Trust’s
Bhaskar Waman Thakur College of Science,
Yashvant Keshav Patil College of Commerce,
Vidhya Dayanand Patil College of Arts.
(Affiliated to University of Mumbai)
VIRAR, 401303
MAHARASHTRA
2022-2023

AJAI RADHAKRISHNAN 1 ROLL NO : 64


TYBSC-CS(SEM V)

Vishnu Waman Thakur Charitable Trust’s


Bhaskar Waman Thakur College of Science,
Yashvant Keshav Patil College of Commerce,
Vidhya Dayanand Patil College of Arts.
(VIVA College)
(Affiliated to University of Mumbai)
NAAC ACCREDITED WITH “B” GRADE (CGPA 2.69)
Virar (W)-401303
DEPARTMENT OF COMPUTER SCIENCE

CERTIFICATE

Roll No. Exam Seat No. ______________

This is to certify that the project entitled,“___________________________________________",is


bonafied work of, ___________________________________________________ bearing
Seat No:_______________ submitted in partial fulfilment of the requirements for the award of degree
of BACHELOR OF SCIENCE in COMPUTER SCIENCE from University of Mumbai.

Internal Guide Head of Department

External Examiner

Date: College Seal

AJAI RADHAKRISHNAN 2 ROLL NO : 64


TYBSC-CS(SEM V)

DECLARATION

We here by declare that the project entitled, “HEART DISEASES PREDICTION” done at
VIVA College, has not been in any case duplicated to submit to any other university for the award of
any degree. To the best of my knowledge other than me, no one has submitted to any other university.
The project is done in partial fulfilment of the requirements for the award of degree of BACHELOR
OF SCIENCE (COMPUTER SCIENCE) to be submitted as final semester project as part of our
curriculum.

AJAI RADHAKRISHNAN

AJAI RADHAKRISHNAN 3 ROLL NO : 64


TYBSC-CS(SEM V)

ACKNOWLEDGEMENT

The gratification and joy that accompanies the successful completion of any task would be
incomplete without the humble and deep-felt expression of gratitude to everyone who has made it
possible.

After month of hard work, I am very happy to present my last year's project. But it wouldn't be
right to do so without thanking those who have helped me in completion of my project. So I would
like to take full advantage of this opportunity to think each and every person who helped me
throughout the completion of my project that is respected teachers, friends, and family.
I express my sincere gratitude to towards our internal guide DR. Priyanka Brid who gave me
unconditional support from the starting point of the project.
I give my special thanks to my Respected H.O.D MRS. Jagruti Raut for encouraging me to
complete this project, guiding me and helping me out through all the obstacles in the project.

I would sincerely thanks to the peoples who guided us throughout the course for this project
work. I would like to express our sincere thanks to DR. Priyanka Brid for his guidance,
encouragement, co-operation and suggestions given to us at progressing stages of the project.

AJAI RADHAKRISHNAN 4 ROLL NO : 64


TYBSC-CS(SEM V)

INDEX

SR NO. CONTENTS PAGE NO.


1. INTRODUCTION 6

2. MODULES 6

3. REQUIREMENTS(H/W -S/W) 7

4. GANTT CHART 8

5. SEQUENCE DIAGRAM 9

6. ACTIVITY DIAGRAM 10

7. CODING 11

8. SCREENSHOTS 20

9. CONCLUSION AND FUTURE ENHANCEMENT 22

10. REFERENCE 23

AJAI RADHAKRISHNAN 5 ROLL NO : 64


TYBSC-CS(SEM V)

INTRODUCTION :-

Heart disease is a major public health problem worldwide, and accurate prediction of the risk of heart
disease is essential for prevention and early detection. Machine learning (ML) algorithms have the
potential to improve the accuracy of heart disease prediction by analyzing large amounts of data and
identifying complex patterns and relationships. Once the dataset has been assembled, it can be split into
training and testing sets, and a machine learning algorithm can be trained on the training set to learn the
patterns and relationships between the features and outcomes. There are various machine learning
algorithms that can be used for heart disease prediction, including decision trees, logistic regression,
support vector machines, and neural networks.Overall, machine learning has the potential to
significantly improve heart disease prediction and prevention by identifying individuals at high risk for
developing heart disease and enabling targeted interventions to reduce that risk.

AJAI RADHAKRISHNAN 6 ROLL NO : 64


TYBSC-CS(SEM V)

REQUIREMENTS:-
HARDWARE–
● Windows – version 7 or +
● RAM– 2GB or more

SOFTWARE –
● Visual Studio Code for Integrated Development Environment.
● Browser for accessing the web application.

FRONT END-
 HTML
 CSS FRAMEWORK - BOOTSTRAP
 JAVASCRIPT. REACT
BACK END-
 Programming language - PYTHON. .
 Framework – FAST API.

AJAI RADHAKRISHNAN 7 ROLL NO : 64


TYBSC-CS(SEM V)

GANTT CHART:-

AJAI RADHAKRISHNAN 8 ROLL NO : 64


TYBSC-CS(SEM V)

SEQUENCE DIAGRAM: -

AJAI RADHAKRISHNAN 9 ROLL NO : 64


TYBSC-CS(SEM V)

ACTIVITY DIAGRAM:-

AJAI RADHAKRISHNAN 10 ROLL NO : 64


TYBSC-CS(SEM V)

CODING:-
BACKEND:
main.py (contain API relates codes)
import uvicorn

import numpy as np

from fastapi import FastAPI, File, UploadFile


from fastapi.middleware.cors import CORSMiddleware

from api.constants import (


ALLOWED_ORIGINS, ALLOWED_METHODS,
ALLOWED_HEADERS, ALLOWED_CREDENTIALS,
CLASS_NAMES
)
from api.utils import image_to_ndarray, load_model

api = FastAPI()

api.add_middleware(
CORSMiddleware,
allow_origins=ALLOWED_ORIGINS,
allow_credentials=ALLOWED_CREDENTIALS,
allow_methods=ALLOWED_METHODS,
allow_headers=ALLOWED_HEADERS,
)

model = load_model("potatoes.h5")

@api.get("/ping")
async def ping():
return "Hello, I'm alive"

@api.post("/api/predict")
async def predict(
file: UploadFile = File(...)
):
image_array = image_to_ndarray(await file.read())
image_batch = np.expand_dims(image_array, 0)

predictions = model.predict(image_batch)

AJAI RADHAKRISHNAN 11 ROLL NO : 64


TYBSC-CS(SEM V)

predicted_class = CLASS_NAMES[np.argmax(predictions[0])]
confidence = np.ndarray.max(predictions[0]).item()

return {
'class': predicted_class,
'confidence': confidence
}

if __name__ == "__main__":
uvicorn.run(api, host="localhost", port=8000)

constants.py (contain all constants)


from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent
MODEL_DIR = BASE_DIR / "models"
CLASS_NAMES = ['Early Blight', 'Late Blight', 'Healthy']

# Cors
ALLOWED_METHODS = ['*']
ALLOWED_HEADERS = ['*']
ALLOWED_CREDENTIALS = True
ALLOWED_ORIGINS = ['*']

utils.py (contains utility functions)


import tensorflow as tf

import numpy as np

from io import BytesIO

from PIL import Image

from api.constants import MODEL_DIR

def image_to_ndarray(data: bytes) -> np.ndarray:


'''
Converts image bytes to numpy array
'''
return np.array(Image.open(BytesIO(data)))

AJAI RADHAKRISHNAN 12 ROLL NO : 64


TYBSC-CS(SEM V)

def load_model(filename: str) -> any:


'''
loads model from `MODEL_DIR / filename` where filename is model name
'''
return tf.keras.models.load_model(MODEL_DIR / filename)

FRONTEND:

home.js (contains main logic rendering, sending files)

import { useState, useEffect } from "react";


import { makeStyles, withStyles } from "@material-ui/core/styles";
import AppBar from "@material-ui/core/AppBar";
import Toolbar from "@material-ui/core/Toolbar";
import Typography from "@material-ui/core/Typography";
import Avatar from "@material-ui/core/Avatar";
import Container from "@material-ui/core/Container";
import React from "react";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import { Paper, CardActionArea, CardMedia, Grid, TableContainer, Table, TableBody, TableHead,
TableRow, TableCell, Button, CircularProgress } from "@material-ui/core";
import logo from "./white-logo.svg";
import image from "./bg.png";
import { DropzoneArea } from 'material-ui-dropzone';
import { common } from '@material-ui/core/colors';
import Clear from '@material-ui/icons/Clear';

const ColorButton = withStyles((theme) => ({


root: {
color: theme.palette.getContrastText(common.white),
backgroundColor: common.white,
'&:hover': {
backgroundColor: '#ffffff7a',
},
},
}))(Button);
const axios = require("axios").default;

const useStyles = makeStyles((theme) => ({

AJAI RADHAKRISHNAN 13 ROLL NO : 64


TYBSC-CS(SEM V)

grow: {
flexGrow: 1,
},
clearButton: {
width: "-webkit-fill-available",
borderRadius: "15px",
padding: "15px 22px",
color: "#000000a6",
fontSize: "20px",
fontWeight: 900,
},
root: {
maxWidth: 345,
flexGrow: 1,
},
media: {
height: 400,
},
paper: {
padding: theme.spacing(2),
margin: 'auto',
maxWidth: 500,
},
gridContainer: {
justifyContent: "center",
padding: "4em 1em 0 1em",
},
mainContainer: {
backgroundImage: `url(${image})`,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundSize: 'auto',
height: "100vh",
overflow: "hidden",
backgroundAttachment: 'fixed',
},
imageCard: {
margin: "auto",
maxWidth: 400,
height: 500,
backgroundColor: 'transparent',
boxShadow: '0px 9px 70px 0px rgb(0 0 0 / 30%) !important',
borderRadius: '15px',
},
imageCardEmpty: {

AJAI RADHAKRISHNAN 14 ROLL NO : 64


TYBSC-CS(SEM V)

height: 'auto',
},
noImage: {
margin: "auto",
width: 400,
height: "400 !important",
},
input: {
display: 'none',
},
uploadIcon: {
background: 'white',
},
tableContainer: {
backgroundColor: 'transparent !important',
boxShadow: 'none !important',
},
table: {
backgroundColor: 'transparent !important',
},
tableHead: {
backgroundColor: 'transparent !important',
},
tableRow: {
backgroundColor: 'transparent !important',
},
tableCell: {
fontSize: '22px',
backgroundColor: 'transparent !important',
borderColor: 'transparent !important',
color: '#000000a6 !important',
fontWeight: 'bolder',
padding: '1px 24px 1px 16px',
},
tableCell1: {
fontSize: '14px',
backgroundColor: 'transparent !important',
borderColor: 'transparent !important',
color: '#000000a6 !important',
fontWeight: 'bolder',
padding: '1px 24px 1px 16px',
},
tableBody: {
backgroundColor: 'transparent !important',
},

AJAI RADHAKRISHNAN 15 ROLL NO : 64


TYBSC-CS(SEM V)

text: {
color: 'white !important',
textAlign: 'center',
},
buttonGrid: {
maxWidth: "416px",
width: "100%",
},
detail: {
backgroundColor: 'white',
display: 'flex',
justifyContent: 'center',
flexDirection: 'column',
alignItems: 'center',
},
appbar: {
background: '#363636',
boxShadow: 'none',
color: 'white'
},
loader: {
color: '#be6a77 !important',
}
}));
export const ImageUpload = () => {
const classes = useStyles();
const [selectedFile, setSelectedFile] = useState();
const [preview, setPreview] = useState();
const [data, setData] = useState();
const [image, setImage] = useState(false);
const [isLoading, setIsloading] = useState(false);
let confidence = 0;

const sendFile = async () => {


if (image) {
let formData = new FormData();
formData.append("file", selectedFile);

let res = await axios({


method: "post",
url: process.env.REACT_APP_API_URL,
data: formData,
});

if (res.status === 200) {

AJAI RADHAKRISHNAN 16 ROLL NO : 64


TYBSC-CS(SEM V)

setData(res.data);
}

setIsloading(false);
}
}

const clearData = () => {


setData(null);
setImage(false);
setSelectedFile(null);
setPreview(null);
};

useEffect(() => {
if (!selectedFile) {
setPreview(undefined);
return;
}
const objectUrl = URL.createObjectURL(selectedFile);
setPreview(objectUrl);
}, [selectedFile]);

useEffect(() => {
if (!preview) {
return;
}
setIsloading(true);
sendFile();
}, [preview]);

const onSelectFile = (files) => {


if (!files || files.length === 0) {
setSelectedFile(undefined);
setImage(false);
setData(undefined);
return;
}
setSelectedFile(files[0]);
setData(undefined);
setImage(true);
};

if (data) {
confidence = (parseFloat(data.confidence) * 100).toFixed(2);

AJAI RADHAKRISHNAN 17 ROLL NO : 64


TYBSC-CS(SEM V)

return (
<React.Fragment>
<AppBar position="static" className={classes.appbar}>
<Toolbar>
<Typography className={classes.title} variant="h6" noWrap>
Potato Disease Classification
</Typography>
<div className={classes.grow} />
<Avatar src={logo}></Avatar>
</Toolbar>
</AppBar>
<Container maxWidth={false} className={classes.mainContainer} disableGutters={true}>
<Grid
className={classes.gridContainer}
container
direction="row"
justify="center"
alignItems="center"
spacing={2}
>
<Grid item xs={12}>
<Card className={`${classes.imageCard} ${!image ? classes.imageCardEmpty : ''}`}>
{image && <CardActionArea>
<CardMedia
className={classes.media}
image={preview}
component="image"
title="Contemplative Reptile"
/>
</CardActionArea>
}
{!image && <CardContent className={classes.content}>
<DropzoneArea
acceptedFiles={['image/*']}
dropzoneText={"Drag and drop an image of a potato plant leaf to process"}
onChange={onSelectFile}
/>
</CardContent>}
{data && <CardContent className={classes.detail}>
<TableContainer component={Paper} className={classes.tableContainer}>
<Table className={classes.table} size="small" aria-label="simple table">
<TableHead className={classes.tableHead}>
<TableRow className={classes.tableRow}>

AJAI RADHAKRISHNAN 18 ROLL NO : 64


TYBSC-CS(SEM V)

<TableCell className={classes.tableCell1}>Label:</TableCell>
<TableCell align="right" className={classes.tableCell1}>Confidence:</TableCell>
</TableRow>
</TableHead>
<TableBody className={classes.tableBody}>
<TableRow className={classes.tableRow}>
<TableCell component="th" scope="row" className={classes.tableCell}>
{data.class}
</TableCell>
<TableCell align="right" className={classes.tableCell}>{confidence}%</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
</CardContent>}
{isLoading && <CardContent className={classes.detail}>
<CircularProgress color="secondary" className={classes.loader} />
<Typography className={classes.title} variant="h6" noWrap>
Processing
</Typography>
</CardContent>}
</Card>
</Grid>
{data &&
<Grid item className={classes.buttonGrid} >

<ColorButton variant="contained" className={classes.clearButton} color="primary"


component="span" size="large" onClick={clearData} startIcon={<Clear fontSize="large" />}>
Clear
</ColorButton>
</Grid>}
</Grid >
</Container >
</React.Fragment >
);
};

AJAI RADHAKRISHNAN 19 ROLL NO : 64


TYBSC-CS(SEM V)

SCREENSHOTS:-

UPLOAD IMAGE SCREEN

AJAI RADHAKRISHNAN 20 ROLL NO : 64


TYBSC-CS(SEM V)

PROCESSING SCREEN

AJAI RADHAKRISHNAN 21 ROLL NO : 64


TYBSC-CS(SEM V)

CONCLUSION & FUTURE ENHANCEMENT :-


The proposed system is GUI-based, user-friendly, scalable, reliable and an expandable system. The
proposed working model can also help in reducing treatment costs by providing Initial diagnostics in
time. The model can also serve the purpose of training tool for medical students and will be a soft
diagnostic tool available for physician and cardiologist. General physicians can utilize this tool for
initial diagnosis of cardio-patients. There are many possible improvements that could be explored to
improve the scalability and accuracy of this prediction system. As we have developed a generalized
system, in future we can use this system for the analysis of different data sets. The performance of the
health’s diagnosis can be improved significantly by handling numerous class labels in the prediction
process, and it can be another positive direction of research. In DM warehouse, generally, the
dimensionality of the heart database is high, so identification and selection of significant attributes for
better diagnosis of heart disease are very challenging tasks for future research.

AJAI RADHAKRISHNAN 22 ROLL NO : 64


TYBSC-CS(SEM V)

REFERENCE:-

1. WWW.GOOGLE.COM
2. WWW.YOUTUBE.COM
3. WWW.GITHUB.COM

AJAI RADHAKRISHNAN 23 ROLL NO : 64

You might also like