-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (46 loc) · 2.66 KB
/
main.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
52
import pickle
import pandas as pd
from flask import Flask, render_template, request
model = pickle.load(open('finalized_svm_model_diabetes.pkl', 'rb'))
app = Flask(__name__)
@app.route("/")
def home():
return render_template("home.html")
@app.route("/result", methods=["POST"])
def submit():
# HTML to .py
global age, gender, polyuria, polydipsia, sudden_weight_loss
global weakness, polyphagia, genital_thrush
global visual_blurring, itching, irritability
global delayed_healing, partial_paresis
global muscle_stiffness, alopecia
if request.method == "POST":
age = int(request.form["num__age"]) # variable 1
gender = request.form["cat__gender_Male"] # variable 2
polyuria = request.form["cat__polyuria_Yes"] # variable 3
polydipsia = request.form["cat__polydipsia_Yes"] # variable 4
sudden_weight_loss = request.form["cat__sudden_weight_loss_Yes"] # variable 5
weakness = request.form["cat__weakness_Yes"] # variable 6
polyphagia = request.form["cat__polyphagia_Yes"] # variable 7
genital_thrush = request.form["cat__genital_thrush_Yes"] # variable 8
visual_blurring = request.form["cat__visual_blurring_Yes"] # variable 9
itching = request.form["cat__itching_Yes"] # variable 10
irritability = request.form["cat__irritability_Yes"] # variable 11
delayed_healing = request.form["cat__delayed_healing_Yes"] # variable 12
partial_paresis = request.form["cat__partial_paresis_Yes"] # variable 13
muscle_stiffness = request.form["cat__muscle_stiffness_Yes"] # variable 14
alopecia = request.form["cat__alopecia_Yes"] # variable 15
# .py to HTML
# Get prediction results
user_input = pd.DataFrame({'age':[age], 'gender':[gender], 'polyuria':[polyuria], 'polydipsia':[polydipsia],
'sudden_weight_loss':[sudden_weight_loss], 'weakness': [weakness], 'polyphagia': [polyphagia],
'genital_thrush': [genital_thrush], 'visual_blurring': [visual_blurring], 'itching': [itching],
'irritability': [irritability], 'delayed_healing': [delayed_healing], 'partial_paresis': [partial_paresis],
'muscle_stiffness': [muscle_stiffness],'alopecia': [alopecia]})
prediction = model.predict(user_input)
if prediction == 1:
return render_template('result.html', prediction="have diabetes. Please consult to a doctor.")
elif prediction == 0:
return render_template('result.html', prediction="have no diabetes.")
if __name__ == "__main__":
app.run(debug=True)