Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
gurvinder08 authored Dec 14, 2021
1 parent f58f880 commit 67e789c
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 0 deletions.
44 changes: 44 additions & 0 deletions heart disease.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-

import numpy as np
import pickle
from flask import Flask, request, render_template

# Load ML model
model = pickle.load(open('model.pkl', 'rb'))

# Create application
app = Flask(__name__)


# Bind home function to URL
@app.route('/')
def home():
return render_template('Heart Disease Classifier.html')


# Bind predict function to URL
@app.route('/predict', methods=['POST'])
def predict():
# Put all form entries values in a list
features = [float(i) for i in request.form.values()]
# Convert features to array
array_features = [np.array(features)]
# Predict features
prediction = model.predict(array_features)

output = prediction

# Check the output values and retrive the result with html tag based on the value
if output == 1:
return render_template('Heart Disease Classifier.html',
result='The patient is not likely to have heart disease!')
else:
return render_template('Heart Disease Classifier.html',
result='The patient is likely to have heart disease!')


if __name__ == '__main__':
# Run the application
app.run()

Binary file added model.pkl
Binary file not shown.
147 changes: 147 additions & 0 deletions templates/Heart Disease Classifier.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<html>
<head>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<title>Heart Disease Prediction</title>
</head>
<body>
<!-- Java Script -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>


<!-- Navbar-->
<nav class="navbar navbar-dark bg-dark">
<span class="navbar-brand mb-0 h1">Heart Disease Prediction</span>
</nav>
<div class="container">
<br>
<!--Form-->
<form action = "{{url_for('predict')}}" method ="POST" >
<fieldset>
<legend>Heart Disease Test</legend><br>
<div class="card card-body" >
<div class="form-group row">
<div class="col-sm-3">
<label for="age">Age</label>
<input type="number" class="form-control" id="age" name="age" required>
</div>
<div class="col-sm-3">
<label for="sex">Sex</label>
<select class="form-control" id="sex" name="sex" required>
<option disabled selected value> -- Select an Option -- </option>
<option value = "0">Male</option>
<option value = "1">Female</option>
</select>
</div>
</div>
<br>
<div class="form-group row">
<div class="col-sm">
<label for="cp">Chest Pain Type</label>
<select class="form-control" id="cp" name = "cp" required>
<option disabled selected value> -- Select an Option -- </option>
<option value = "0">Typical Angina</option>
<option value = "1">Atypical Angina</option>
<option value = "2">Non-anginal Pain</option>
<option value = "3">Asymptomatic</option>
</select>
</div>
<div class="col-sm">
<label for="trestbps">Resting Blood Pressure in mm Hg</label>
<input type="number" class="form-control" id="trestbps" name="trestbps" required>
</div>
<div class="col-sm">
<label for="chol">Serum Cholestoral in mg/dl</label>
<input type="number" class="form-control" id="chol" name="chol" required>
</div>
<div class="col-sm">
<label for="fbs">Fasting Blood Sugar > 120 mg/dl</label>
<select class="form-control" id="fbs" name="fbs" required>
<option disabled selected value> -- Select an Option -- </option>
<option value = "0">False</option>
<option value = "1">True</option>
</select>
</div>
</div>

<br>
<div class="form-group row">
<div class="col-sm">
<label for="restecg">Resting ECG Results </label>
<select class="form-control" id="restecg" name="restecg" required>
<option disabled selected value> -- Select an Option -- </option>
<option value = "0">Normal</option>
<option value = "1">Having ST-T wave abnormality </option>
<option value = "2"> Probable or definite left ventricular hypertrophy </option>
</select>
</div>
<div class="col-sm">
<label for="thalach">Maximum Heart Rate</label>
<input type="number" class="form-control" id="thalach" name="thalach" required>
</div>
<div class="col-sm">
<label for="exang">ST Depression Induced</label>
<input type="number" step="any" class="form-control" id="exang" name="exang" required>
</div>
<div class="col-sm">
<label for="exang">Exercise Induced Angina </label>
<select class="form-control" id="oldpeak" name="oldpeak" required>
<option disabled selected value> -- Select an Option -- </option>
<option value = "0">No</option>
<option value = "1">Yes</option>
</select>
</div>
</div>
<br>
<div class="form-group row">
<div class="col-sm">
<label for="slope">Slope of the Peak Exercise ST Segment </label>
<select class="form-control" id="slope" name="slope" required>
<option disabled selected value> -- Select an Option -- </option>
<option value = "0">Upsloping</option>
<option value = "1">Flat</option>
<option value = "2">Downsloping</option>
</select>
</div>
<div class="col-sm">
<label for="ca">Number of Vessels Colored by Flourosopy</label>
<select class="form-control" id="ca" name = "ca" required>
<option disabled selected value> -- Select an Option -- </option>
<option value = "0">0</option>
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
</select>
</div>
<div class="col-sm">
<label for="thal">Thalassemia</label>
<select class="form-control" id="thal" name = "thal" required>
<option disabled selected value> -- Select an Option -- </option>
<option value = "3">Normal</option>
<option value = "6">Fixed defect</option>
<option value = "7">Reversable defect</option>
</select>
</div>
</div>
<br>
<div class="form-group">
<input class="btn btn-primary" type="submit" value="Result">
</div>

<!--Prediction Result-->
<div id ="result">
<strong style="color:red">{{result}}</strong>
</div>
</div>
</fieldset>
</form>

</div>

</body>
</html>

0 comments on commit 67e789c

Please sign in to comment.