-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
executable file
·104 lines (83 loc) · 2.31 KB
/
application.py
File metadata and controls
executable file
·104 lines (83 loc) · 2.31 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
comorbidity-ml: a webapplication to the users the chance of morbidity
"""
from flask import Flask, render_template, request,session
import joblib
import numpy as np
import pandas as pd
from checker import check_logged_in, home_logged_in, wrong_info
# Loads the machine learning model
df = pd.read_csv("data/conditions.csv")
lr_cv_model = joblib.load("data/comorbid-trained-model.pkl")
application = Flask(__name__)
application.secret_key = "notasecret"
@application.route("/")
@home_logged_in
def home():
"""
Function: home
Input: none
Returns: The main page of the webapplication
"""
return render_template("home.html")
@application.route("/login")
def login():
"""
Function: login
Input: none
Returns: The login page of the webapplication
"""
return render_template("login.html")
@application.route("/check", methods=['POST'])
@wrong_info
def check():
"""
Function: check
Input: none
Returns: Check username and password
"""
session['logged_in'] = True
return render_template("home.html")
@application.route("/logout", methods=['POST'])
def logout():
"""
Function: logout
Input: none
Returns: logout session
"""
session.pop('logged_in')
return render_template("login.html")
@application.route("/survey")
@check_logged_in
def survey():
"""
Function: entry
Input: none
Returns: The survey form to predict morbidity
"""
return render_template("survey.html")
@application.route('/predict', methods=['POST'])
def result():
"""
Function: result
Input: none
Returns: The result page of the user's prediction
"""
letters = ['age', 'sex', 'smoking', 'alcohol', 'hypertension',
'diabetes', 'rheuma', 'dementia', 'cancer', 'copd',
'asthma', 'chd', 'ccd', 'cnd', 'cld', 'ckd', 'aids']
pred_date = [int(request.form[letter]) for letter in letters]
arr = np.array([pred_date])
pred = lr_cv_model.predict(arr)
return render_template('results.html', data=pred)
@application.route('/charts')
@check_logged_in
def charts() -> render_template:
"""
Function: charts
Input: none
Returns: Returns the charts page in the webapplication
"""
return render_template('charts.html')
if __name__ == "__main__":
application.run(debug=True)