Page 171 - FULL REPORT 30012024
P. 171
cursor.close()
mydb.close()
return redirect(url_for('admindata'))
# Homepage route
@app.route('/')
def home():
return render_template('index.html')
# Prediction page route
@app.route('/predict', methods=['GET', 'POST'])
def index():
bmi_category = None
stroke_risk = None
personalized_advice = []
if request.method == 'POST':
gender = request.form['gender']
age = float(request.form['age'])
hypertension = int(request.form['hypertension'])
heart_disease = int(request.form['heart_disease'])
weight = float(request.form['weight'])
height = float(request.form['height']) / 100 # Convert height to
meters
bmi = weight / (height ** 2) # Calculate BMI
bmi = round(bmi, 2) # Round BMI to two decimal places
smoking_status = request.form['smoking_status']
ever_married = request.form['ever_married']
work_type = request.form['work_type']
Residence_type = request.form['Residence_type']
# Predict stroke risk
stroke_risk = predict_stroke_risk(gender, age, hypertension,
heart_disease,
bmi,
smoking_status,
ever_married,
work_type, Residence_type)
if stroke_risk < 20:
stroke_level = "Low"
elif stroke_risk < 50:
stroke_level = "Moderate"
else:
stroke_level = "High"
if bmi < 18.5:
bmi_category = 'Underweight'
elif bmi < 25:
bmi_category= 'Normal weight'
elif bmi < 30:
bmi_category= 'Overweight'
else:
154