Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 52
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 52
22_23-J 52
Commits
163c3762
Commit
163c3762
authored
May 19, 2023
by
J D N S De Silva
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Routes File
parent
59f794bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
147 additions
and
0 deletions
+147
-0
routes.py
routes.py
+147
-0
No files found.
routes.py
0 → 100644
View file @
163c3762
from
keras.models
import
load_model
from
flask
import
render_template
,
request
from
app
import
app
import
numpy
as
np
# linear algebra
import
pandas
as
pd
# data processing, CSV file I/O (e.g. pd.read_csv)
import
os
import
cv2
from
pathlib
import
Path
import
pickle
import
tensorflow
as
tf
import
sklearn
from
tensorflow.keras.models
import
load_model
from
tensorflow.keras.preprocessing
import
image
#### Home Page ####
@
app
.
route
(
'/'
)
@
app
.
route
(
'/home'
)
def
home
():
return
render_template
(
'home.html'
)
@
app
.
route
(
'/about'
)
def
about
():
return
render_template
(
'about.html'
)
######################## Stroke ############################
@
app
.
route
(
'/stroke'
)
def
stroke
():
return
render_template
(
'strokePage.html'
)
@
app
.
route
(
'/predictStrokepage'
)
def
predictStrokepage
():
return
render_template
(
'stroke_predict.html'
)
# predict stroke
@
app
.
route
(
'/predictStroke'
,
methods
=
[
'POST'
])
def
predictStroke
():
gender
=
request
.
form
[
'gender'
]
age
=
request
.
form
[
'age'
]
hypertension
=
request
.
form
[
'hypertension'
]
heart_disease
=
request
.
form
[
'heart_disease'
]
ever_married
=
request
.
form
[
'ever_married'
]
work_type
=
request
.
form
[
'work_type'
]
Residence_type
=
request
.
form
[
'Residence_type'
]
avg_glucose_level
=
request
.
form
[
'avg_glucose_level'
]
bmi
=
request
.
form
[
'bmi'
]
smoking_status
=
request
.
form
[
'smoking_status'
]
with
open
(
'models/finalized_model_stroke_prediction_RF.sav'
,
'rb'
)
as
f
:
model
=
pickle
.
load
(
f
)
input_data
=
(
gender
,
age
,
hypertension
,
heart_disease
,
ever_married
,
work_type
,
Residence_type
,
avg_glucose_level
,
bmi
,
smoking_status
)
# input_data3 = np.array(input_data).astype(int)
input_data_as_numpy_array
=
np
.
asarray
(
input_data
)
input_data_reshaped
=
input_data_as_numpy_array
.
reshape
(
1
,
-
1
)
prediction
=
model
.
predict
(
input_data_reshaped
)
print
(
input_data
)
if
(
prediction
==
1
):
result
=
"You are at risk of having a stroke"
disease
=
'stroke'
return
docRec
(
disease
,
result
,
value
=
"stroke"
)
else
:
result
=
"You are not at risk of having a stroke"
return
render_template
(
'results.html'
,
result
=
result
)
# CT image detection
@
app
.
route
(
'/predictStrokeCt'
)
def
predictStrokeCt
():
return
render_template
(
'stroke_detection_CT.html'
)
def
predict4
(
img
):
model
=
tf
.
keras
.
models
.
load_model
(
'models/finalized_model_strokeCT.h5'
)
# model = load_model('finalized_model_strokeCT.h5')
model
=
load_model
(
'models/finalized_model_strokeCT.h5'
)
pic
=
[]
img
=
cv2
.
resize
(
img
,
(
224
,
224
))
# Convert the image to a numpy array and preprocess it
x
=
image
.
img_to_array
(
img
)
x
=
np
.
expand_dims
(
x
,
axis
=
0
)
x
/=
255
# Make a prediction using the model
prediction
=
model
.
predict
(
x
)
# Print the predicted class (0 = non-stroke, 1 = stroke)
if
prediction
<
0.5
:
return
(
"You don't have a stroke"
)
else
:
return
(
"You have a Stroke"
)
@
app
.
route
(
'/process_image_stroke'
,
methods
=
[
'POST'
])
def
process_image_stroke
():
if
request
.
method
==
'POST'
:
file
=
request
.
files
[
'file'
]
img_bytes
=
file
.
read
()
# Read image data as bytes
# Convert bytes to OpenCV image
img
=
cv2
.
imdecode
(
np
.
frombuffer
(
img_bytes
,
np
.
uint8
),
-
1
)
img
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
)
# Convert BGR to RGB
prediction
=
predict4
(
img
)
# Make prediction using img
disease
=
'stroke'
return
docRec
(
disease
,
prediction
,
value
=
"stroke"
)
return
'File uploaded successfully!'
def
docRec
(
disease
,
result
,
value
):
df
=
pd
.
read_excel
(
'docs
\
RELEVANTDOCTORS.xlsx'
)
# find rows that contain a keyword in a specific column
keyword
=
str
(
disease
)
column_name
=
'Disease'
rec
=
df
[
df
[
column_name
]
.
str
.
contains
(
keyword
)]
rec
=
rec
.
iloc
[:,
1
:]
table_classes
=
'table table-striped table-bordered table-hover'
if
value
==
"skinT"
:
textshow
=
True
else
:
textshow
=
False
if
value
==
"lung"
:
show_button
=
True
# render the output in a table format
return
render_template
(
'results.html'
,
rec
=
rec
.
to_html
(
index
=
False
,
classes
=
table_classes
),
result
=
result
,
show_button
=
show_button
,
textshow
=
textshow
)
else
:
show_button
=
False
return
render_template
(
'results.html'
,
rec
=
rec
.
to_html
(
index
=
False
,
classes
=
table_classes
),
result
=
result
,
show_button
=
show_button
,
textshow
=
textshow
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment