-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (60 loc) · 2.45 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
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
from flask import Flask, render_template, url_for, redirect, request, session
from typing import Any
import os
from load_models import load_models
from pnumonia_detection_model.pnumonia import predict_pnumonia
from malaria.malaria import predict_malaria
from heart_disease.heart_disease import predict_heart_disease
app = Flask(__name__)
app.secret_key = 'admin'
@app.route('/home')
def index() -> Any:
return render_template('index.html')
@app.route('/')
def login_page() -> Any:
return render_template('login.html')
@app.route('/login', methods=['POST'])
def login() -> Any:
if request.method == 'POST':
session['username'] = request.form['uname']
return redirect('/home')
@app.route('/submit_pnumonia', methods=['GET'])
def submit_pnumonia() -> Any:
filename = request.args.get('pneumonia')
return redirect(url_for('pnumonia_result', filename=filename))
@app.route('/results_pnumonia/<filename>')
def pnumonia_result(filename: str) -> Any:
path = 'templates/assets/img/' + filename
if os.path.exists(path):
model = load_models()['pnumonia']
return render_template('pnumonia_result.html', result=predict_pnumonia(path, model))
else:
return redirect('/home')
@app.route('/submit_malaria', methods=['GET'])
def submit_malaria() -> Any:
user = request.args.get('malaria')
return redirect(url_for('malaria_result', filename=user))
@app.route('/results_malaria/<filename>')
def malaria_result(filename: str) -> Any:
path = 'templates/assets/img/' + filename
if os.path.exists(path):
model = load_models()['malaria']
return render_template('pnumonia_result.html', result=predict_malaria(path, model))
else:
return request('/home')
@app.route('/submit_heart_disease', methods=['GET'])
def submit_heart_disease() -> Any:
age = int(request.args.get('age'))
sex = 1 if request.args.get('sex') == 'male' else 0
bp = int(request.args.get('bp'))
ch = int(request.args.get('ch'))
bs = 1 if request.args.get('bs') == 'yes' else 0
hr = int(request.args.get('hr'))
return redirect(url_for('heart_disease_result', info=str([age, sex, bp, bs, hr, ch])))
@app.route('/results_heart_disease/<info>')
def heart_disease_result(info: str) -> Any:
model = load_models()['heart disease']
prediction = predict_heart_disease(eval(info), model)
return render_template('pnumonia_result.html', result=prediction)
if __name__ == '__main__':
app.run(debug=True)