-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_flask.py
41 lines (40 loc) · 1.59 KB
/
deploy_flask.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
from importlib.resources import contents
from flask import Flask, render_template, template_rendered, request, redirect
import pickle
import numpy as np
input_data = []
model = pickle.load(open('final_model.sav','rb'))
app = Flask(__name__)
def preprocess(input_data):
# changing the input_data to numpy array
input_data_as_numpy_array = np.asarray(input_data)
# reshape the array as we are predicting for one instance
input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
return input_data_reshaped
def loadmodel(input):
return model.predict(input)
@app.route("/",methods=["POST","GET"])
def welcome():
return render_template("welcome.html")
@app.route("/insert-data",methods=["POST","GET"])
def insertdata():
data_m = ""
if request.method == "POST":
input_data=[]
input_data.append(float(request.form["Pregnancies"]))
input_data.append(float(request.form["Glucose"]))
input_data.append(float(request.form["BloodPressure"]))
input_data.append(float(request.form["SkinThickness"]))
input_data.append(float(request.form["Insulin"]))
input_data.append(float(request.form["BMI"]))
input_data.append(float(request.form["DiabetesPedigreeFunction"]))
input_data.append(float(request.form["Age"]))
last_data = preprocess(input_data)
out = loadmodel(last_data)
if out[0] == 0:
data_m = "NOT Diabetic"
else:
data_m = "Diabetic"
return render_template("insert-data.html",content=data_m)
if __name__ == "__main__":
app.run(debug=True,host="0.0.0.0",port=8080)