-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
201 lines (153 loc) · 5.37 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from flask import Flask,request,render_template,redirect,url_for
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.models import load_model
import cv2
import numpy
import pickle
import PIL
import os
from werkzeug import secure_filename
app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@app.route('/about')
def homepage():
return render_template('imagewebsite.html')
@app.route('/dataset')
def datasetpage():
return render_template('datasetimage.html')
@app.route('/login', methods=['GET','POST'])
def loginpage():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
print(password)
file = open('register.txt','r+')
flag = 0
for lines in file:
line = lines.split(" ")
if line[0] == username :
passcode = line[1].strip()
if passcode == password :
flag = 1
break
if flag == 1:
return redirect('/main')
else:
return ' <script> alert("username or password wrong, try another") </script> '
return render_template('loginpage.html')
@app.route('/register', methods=['GET','POST'])
def registerpage():
if request.method == 'POST' :
username = request.form['username']
password = request.form['password']
name = request.form['name']
mail = request.form['mail']
phno = request.form['phno']
file = open('register.txt','r+')
flag = 0
for lines in file:
line = lines.split(" ")
if line[0] == username :
flag = 1
break
if flag == 1:
return ' <script> alert("username already taken, try another") </script> '
else :
file.write(username+" "+password+"\n")
file.close()
return redirect('/login')
return render_template('registerpage.html')
@app.route('/main')
def main():
return render_template('index.html')
@app.route('/display')
def display():
with open('details.txt') as details_log:
details_lines = details_log.readlines()
data = []
details = len(details_lines)
for x in range(details):
data.append(details_lines[x].split(" "))
return render_template('display.html', details=details, data=data)
@app.route('/enter_data')
def form():
return render_template('form.html')
@app.route('/result' , methods = ['POST'])
def result():
if request.method == 'POST':
# data = request.form
name = request.form['name']
age = request.form['age']
gender = request.form['gender']
spiral_image = request.files['spiral_image']
meander_image = request.files['meander_image']
s_img = spiral_image.filename
m_img = meander_image.filename
spiral_loc = save_image(spiral_image)
meander_loc = save_image(meander_image)
spiral_res = predict_spiral(spiral_loc)
meander_res = predict_meander(meander_loc)
if spiral_res == meander_res :
if spiral_res == 0:
res = 'is Healthy'
final_res = 'Healthy'
else:
res = 'has Parkinson'
final_res = 'Parkinson'
else:
if spiral_res == 0:
res = 'is Healthy'
final_res = 'Healthy'
else:
res = 'has Parkinson'
final_res = 'Parkinson'
file = open('details.txt','a')
file.write(name+" "+age+" "+gender+" "+final_res+"\n")
file.close()
return render_template('result.html',result = res,name=name, age=age, gender=gender)
#save images uploaded in image folder
def save_image(file):
target = os.path.join(APP_ROOT, 'images')
print(target)
if not os.path.isdir(target):
os.mkdir(target)
filename = file.filename
destination = "/".join([target, filename])
print("Accept incoming file:", filename)
print(destination)
file.save(destination)
return destination
# load and prepare the image
def predict_spiral(filename):
img = load_img(filename, target_size=(512, 512))
img = img_to_array(img)
img = img.reshape(1, 512, 512, 3)
model = pickle.load(open('spiral_model.pkl', 'rb'))
result = model.predict(img)
print(result[0])
res = result[0]
res = int(res)
if res == 0:
return 0
else:
return 1
def predict_meander(filename):
img = load_img(filename, target_size=(512, 512))
img = img_to_array(img)
img = img.reshape(1, 512, 512, 3)
model = pickle.load(open('meander_model.pkl', 'rb'))
result = model.predict(img)
print(result[0])
res = result[0]
res = int(res)
if res == 0:
return 0
else:
return 1
# main driver function
if __name__ == '__main__':
# run() method of Flask class runs the application
# on the local development server.
app.run()
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024