32
loading...
This website collects cookies to deliver better user experience
!python --version
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
if __name__ == "__main__":
app.run()
python app.py
from joblib import load
pipeline = load("resource/diseaseprediction.joblib")
def hello_world():
return render_template('home.html')
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2 style="text-align:center">Do I have heart disease?</h2>
<p style="text-align:center">Fill out this form and check!</p>
<div>
<form>
<div>
<div>
<label for="age">Age</label>
</div>
<div>
<input type="text" id="age" name="age" placeholder="Your Age" required>
</div>
</div>
<div>
<div>
<label for="sex">Sex</label>
</div>
<div>
<input type="radio" id="sex" name="sex" value="1">
<label for="sex">Male</label><br>
</div>
<div>
<input type="radio" id="sex" name="sex" value="0" required>
<label for="sex">Female</label><br>
</div>
</div>
<div>
<div>
<label for="cp">Chest Pain Type</label>
</div>
<div>
<select id="cp" name="cp" required>
<option value="0">None</option>
<option value="1">Mild</option>
<option value="2">Medium</option>
<option value="3">Severe</option>
</select>
</div>
</div>
<div>
<div>
<label for="rbp">Resting Blood Pressure</label>
</div>
<div>
<input type="text" id="trestbps" name="trestbps" placeholder="Your bp in mm Hg" required>
</div>
</div>
<div>
<div>
<label for="chol">Cholesterol</label>
</div>
<div>
<input type="text" id="chol" name="chol" placeholder="Your serum cholestoral in mg/dl" required>
</div>
</div>
<div>
<div>
<label for="fbs">Fasting Blood Sugar</label>
</div>
<div>
<input type="radio" id="fbs" name="fbs" value="1" required>
<label for="fbs">Diabetic</label><br>
</div>
<div>
<input type="radio" id="fbs" name="fbs" value="0">
<label for="fbs">Non diabatic</label><br>
</div>
</div>
<div>
<div
<label for="restecg">Resting Electrocardiographic Results</label>
</div>
<div
<select id="restecg" name="restecg" required>
<option value="0">None</option>
<option value="1">Medium</option>
<option value="2">Severe</option>
</select>
</div>
</div>
<div>
<div>
<label for="thalach">Maximum Heart Rate Achieved</label>
</div>
<div
<input type="text" id="thalach" name="thalach" placeholder="Your maximum achieved heart rate" required>
</div>
</div>
<div
<div>
<label for="exang">Exercise Induced Angina</label>
</div>
<div>
<input type="radio" id="exang" name="exang" value="1">
<label for="exang">Yes</label><br>
</div>
<div>
<input type="radio" id="exang" name="exang" value="0" required>
<label for="exang">No</label><br>
</div>
</div>
<div>
<div>
<label for="oldpeak">OldPeak (floating point value)</label>
</div>
<div>
<input type="text" id="oldpeak" name="oldpeak"
placeholder="ST depression induced by exercise relative to rest" required>
</div>
</div>
<div>
<div>
<label for="slope">The Slope of the Peak Exercise ST Segment</label>
</div>
<div>
<select id="slope" name="slope" required>
<option value="0">None</option>
<option value="1">Medium</option>
<option value="2">Severe</option>
</select>
</div>
</div>
<div>
<div>
<label for="ca">Number of Major Vessels (0-3)</label>
</div>
<div>
<select id="ca" name="ca" required>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
</div>
<div>
<div>
<label for="thal">Thal: 3 = normal; 6 = fixed defect; 7 = reversable defect</label>
</div>
<div>
<select id="thal" name="thal" required>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</div>
</div>
<div>
<button type="submit">Submit Data</button>
</div>
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
* {
box-sizing: border-box;
}
input[type=text], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
label {
padding: 12px 12px 12px 0;
display: inline-block;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 75%;
margin-top: 6px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
.center {
display: flex;
justify-content: center;
align-items: center;
height: 200px;
}
/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
.col-25, .col-75, input[type=submit] {
width: 100%;
margin-top: 0;
}
}
</style>
</head>
<body>
<h2 style="text-align:center">Do I have heart disease?</h2>
<p style="text-align:center">Fill out this form and check!</p>
<div class="container">
<form action="http://localhost:5000/" method="post">
<div class="row">
<div class="col-25">
<label for="age">Age</label>
</div>
<div class="col-75">
<input type="text" id="age" name="age" placeholder="Your Age" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="sex">Sex</label>
</div>
<div class="col-25">
<input type="radio" id="sex" name="sex" value="1">
<label for="sex">Male</label><br>
</div>
<div class="col-25">
<input type="radio" id="sex" name="sex" value="0" required>
<label for="sex">Female</label><br>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="cp">Chest Pain Type</label>
</div>
<div class="col-75">
<select id="cp" name="cp" required>
<option value="0">None</option>
<option value="1">Mild</option>
<option value="2">Medium</option>
<option value="3">Severe</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="rbp">Resting Blood Pressure</label>
</div>
<div class="col-75">
<input type="text" id="trestbps" name="trestbps" placeholder="Your bp in mm Hg" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="chol">Cholesterol</label>
</div>
<div class="col-75">
<input type="text" id="chol" name="chol" placeholder="Your serum cholestoral in mg/dl" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="fbs">Fasting Blood Sugar</label>
</div>
<div class="col-25">
<input type="radio" id="fbs" name="fbs" value="1" required>
<label for="fbs">Diabetic</label><br>
</div>
<div class="col-25">
<input type="radio" id="fbs" name="fbs" value="0">
<label for="fbs">Non diabatic</label><br>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="restecg">Resting Electrocardiographic Results</label>
</div>
<div class="col-75">
<select id="restecg" name="restecg" required>
<option value="0">None</option>
<option value="1">Medium</option>
<option value="2">Severe</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="thalach">Maximum Heart Rate Achieved</label>
</div>
<div class="col-75">
<input type="text" id="thalach" name="thalach" placeholder="Your maximum achieved heart rate" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="exang">Exercise Induced Angina</label>
</div>
<div class="col-25">
<input type="radio" id="exang" name="exang" value="1">
<label for="exang">Yes</label><br>
</div>
<div class="col-25">
<input type="radio" id="exang" name="exang" value="0" required>
<label for="exang">No</label><br>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="oldpeak">OldPeak (floating point value)</label>
</div>
<div class="col-75">
<input type="text" id="oldpeak" name="oldpeak"
placeholder="ST depression induced by exercise relative to rest" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="slope">The Slope of the Peak Exercise ST Segment</label>
</div>
<div class="col-75">
<select id="slope" name="slope" required>
<option value="0">None</option>
<option value="1">Medium</option>
<option value="2">Severe</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="ca">Number of Major Vessels (0-3)</label>
</div>
<div class="col-75">
<select id="ca" name="ca" required>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="thal">Thal: 3 = normal; 6 = fixed defect; 7 = reversable defect</label>
</div>
<div class="col-75">
<select id="thal" name="thal" required>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</div>
</div>
<div class="center">
<button class="w3-button w3-green" type="submit">Submit Data</button>
</div>
</form>
</div>
</body>
</html>
@app.route('/', methods=['GET', 'POST'])
def inputForm():
print("type", type(request.form))
# type ImmutableMultiDict
import pandas as pd
@app.route('/', methods=['GET', 'POST'])
def inputForm():
print("type", type(request.form.to_dict(flat=False))) #changing to a dictionary
print("checking form", request.form.to_dict()) #dictionary to datframe
data = request.form.to_dict()
df = pd.DataFrame(data, index=[0])
print("prediction", pipeline.predict(df))
if pipeline.predict(df) == [1]:
prediction = "You are in risk of heart disease"
elif pipeline.predict(df) == [0]:
prediction = "You don't have risk of heart disease"
else: prediction = "Can't predict anything"
return render_template('home.html', prediction = prediction, show_predictions_modal = True )
{% if show_predictions_modal %}
<div class="center">
<button onclick="document.getElementById('id01').style.display='block'" class="w3-button w3-black"
type="submit">See
Result
</button>
</div>
<div id="id01" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('id01').style.display='none'"
class="w3-button w3-display-topright">×</span>
<div class="w3-container">
<p style="text-align:center">{{ prediction }}</p>
</div>
</div>
</div>
</div>
{% endif %}