-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (28 loc) · 1.06 KB
/
Copy pathapp.py
File metadata and controls
38 lines (28 loc) · 1.06 KB
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
from flask import Flask, request, render_template
import pickle
import numpy as np
app = Flask(__name__)
# Load trained model
model = pickle.load(open("model.pkl", "rb"))
# Home page
@app.route("/")
def home():
return render_template("index.html")
# Prediction route
@app.route("/predict", methods=["POST"])
def predict():
try:
# Get form values
data = [float(x) for x in request.form.values()]
# Convert to numpy array and predict
prediction = model.predict([np.array(data)])[0]
probability = model.predict_proba([np.array(data)])[0]
# Result logic
result = "Diabetic" if prediction == 1 else "Not Diabetic"
confidence = float(probability[prediction]) * 100
return render_template("index.html", prediction_text=result, confidence=round(confidence, 2))
except Exception as e:
return render_template("index.html", prediction_text=f"Error: {e}", confidence=0)
# Run app
if __name__ == "__main__":
app.run(host="0.0.0.0", port=10000, debug=True)