-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
132 lines (112 loc) · 4.36 KB
/
app.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from itertools import count
from flask import Flask, render_template ,url_for ,request,Response
import numpy as np
import database
import prediction
import json
import io
import random
import visualization
from pymongo import MongoClient
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import modelbuild
app = Flask ( __name__ )
# @app.route('/plot1.png')
# def plot_png1():
# fig = visualization.create_figure2(data1)
# output = io.BytesIO()
# FigureCanvas(fig).print_png(output)
# return Response(output.getvalue(), mimetype='image/png')
# @app.route('/plot2.png')
# def plot_png2():
# fig = visualization.create_figure2(data2)
# output = io.BytesIO()
# FigureCanvas(fig).print_png(output)
# return Response(output.getvalue(), mimetype='image/png')
def create_figure1(data1):
fig = plt.subplots(figsize =(12, 8))
barWidth = 0.25
normal = data1[0]
user = data1[1]
br1 = np.arange(len(normal))
br2 = [x + barWidth for x in br1]
# br3 = [x + barWidth for x in br2]
plt.bar(br1, normal, color ='g', width = barWidth,edgecolor ='grey', label ='Normal Value')
plt.bar(br2, user, color ='r', width = barWidth,edgecolor ='grey', label ="Yours Value")
# plt.bar(br3, CSE, color ='b', width = barWidth, edgecolor ='grey', label ='CSE')
plt.xlabel('Health status defining attributes', fontweight ='bold', fontsize = 15)
plt.ylabel('respective values', fontweight ='bold', fontsize = 15)
plt.xticks([r + barWidth for r in range(len(normal))],['cp','chol','fbs','exang','oldpeak','slope','ca','thal'])
plt.legend()
plt.savefig('static/plotng.png')
def create_figure2(data2):
fig = plt.subplots(figsize =(12, 8))
barWidth = 0.25
normal = data2[0]
user = data2[1]
br1 = np.arange(len(normal))
br2 = [x + barWidth for x in br1]
plt.bar(br1, normal, color ='g', width = barWidth,edgecolor ='grey', label ='Normal Value')
plt.bar(br2, user, color ='r', width = barWidth,edgecolor ='grey', label ="Yours Value")
plt.xlabel('Health status defining attributes', fontweight ='bold', fontsize = 15)
plt.ylabel('respective values', fontweight ='bold', fontsize = 15)
plt.xticks([r + barWidth for r in range(len(normal))],['trestbps','chol','thalach'])
plt.legend()
plt.savefig('static/plotng2.png')
@app.route('/')
def home():
global counter2
counter2+=1
return render_template('home.html',all_count=counter2)
global counter
counter=0
global counter2
counter2=0
@app.route('/predict',methods=['POST'])
def predict():
global data1
global data2
global counter
global counter2
if request.method == 'POST':
nameofpatient= request.form ['name']
age= request.form ['age']
sex=request.form ['sex']
cp= request.form ['cp']
trestbps= request.form ['trestbps']
chol= request.form ['chol']
fbs= request.form ['fbs']
restecg=request.form ['restecg']
thalach=request.form ['thalach']
exang=request.form ['exang']
oldpeak=request.form ['oldpeak']
slope=request.form ['slope']
ca=request.form ['ca']
thal=request.form ['thal']
counter+=1
if(counter<=50):
result=prediction.preprocess(age,sex,cp,trestbps,restecg,chol,fbs,thalach,exang,oldpeak,slope,ca,thal )
else:
#modelbuild.bulidmodel()
result=prediction.preprocess(age,sex,cp,trestbps,restecg,chol,fbs,thalach,exang,oldpeak,slope,ca,thal )
counter=0
#database.crudOperation(age,sex,cp,trestbps,restecg,chol,fbs,thalach,exang,oldpeak,slope,ca,thal,result)
data1,data2=visualization.visualizationpreprocess(age,sex,cp,trestbps,restecg,chol,fbs,thalach,exang,oldpeak,slope,ca,thal,result)
create_figure1(data1)
create_figure2(data2)
return render_template ('result.html',prediction = result, nameofpatient=nameofpatient, model_counter=counter, total_counter=counter2)
@app.route('/about')
def about():
return render_template('disease.html')
@app.errorhandler(500)
def internal_error(error):
return render_template('error.html')
@app.errorhandler(404)
def not_found(error):
return "404 error",404
if __name__ == '__main__':
app.run( debug = True)