-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
51 lines (40 loc) · 1.6 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Flask, render_template, request
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import StandardScaler
from joblib import load
import pandas as pd
app = Flask(__name__)
# Load the pre-trained Random Forest model and StandardScaler
model = load("random_forest_model.joblib")
scaler = load("scaler.joblib")
@app.route("/")
def index():
return render_template("index.html")
@app.route("/predict", methods=["POST"])
def predict():
if request.method == "POST":
# Get input parameters from the form
input_data = {
"Pregnancies": int(request.form["pregnancies"]),
"Glucose": int(request.form["glucose"]),
"BloodPressure": int(request.form["blood_pressure"]),
"SkinThickness": int(request.form["skin_thickness"]),
"Insulin": int(request.form["insulin"]),
"BMI": float(request.form["bmi"]),
"DiabetesPedigreeFunction": float(
request.form["diabetes_pedigree_function"]
),
"Age": int(request.form["age"]),
}
# Preprocess the input data
input_df = pd.DataFrame([input_data])
input_df_scaled = scaler.transform(
input_df
) # Use the same scaler used during training
# Make predictions using the pre-trained model
prediction = model.predict(input_df_scaled)
# Display the prediction result
result = "Diabetic" if prediction[0] == 1 else "Non-Diabetic"
return render_template("result.html", result=result)
if __name__ == "__main__":
app.run(debug=True)