forked from darkness071104/Flask-Diabetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
36 lines (24 loc) · 1.16 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flask import Flask, render_template, request
import joblib
import pandas as pd
app = Flask(__name__)
clf = joblib.load('diabetes.pkl')
scaler = joblib.load('scaler.pkl')
@app.route('/', methods=['GET', 'POST'])
def predict():
prediction = None
if request.method == 'POST':
user_data = pd.DataFrame(columns=['gender', 'age', 'hypertension',
'heart_disease', 'smoking_history', 'bmi',
'HbA1c_level', 'blood_glucose_level'])
for column in user_data.columns:
user_input = request.form.get(column)
user_data.at[0, column] = float(user_input)
user_data = user_data.apply(pd.to_numeric, errors='coerce')
# Normalize the user data using the fitted scaler
user_data_scaled_array = scaler.transform(user_data.values.reshape(1, -1))
user_prediction = clf.predict(user_data_scaled_array)
prediction = 'Diabetes' if user_prediction[0] == 1 else 'Not Diabetes'
return render_template('index.html', prediction=prediction)
if __name__ == "__main__":
app.run(debug=True)