Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-159
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
1
Merge Requests
1
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
2023-159
2023-159
Commits
e9316413
Commit
e9316413
authored
Dec 03, 2023
by
Wijesinghe.K.H
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
57148937
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
0 deletions
+98
-0
it20187682/app.py
it20187682/app.py
+98
-0
No files found.
it20187682/app.py
0 → 100644
View file @
e9316413
import
os
import
shutil
from
flask
import
Flask
,
request
,
jsonify
from
const
import
OUTPUT_DIR
from
detect
import
run
from
predict
import
start_predict
from
flask_cors
import
CORS
#lahiri
from
image_service
import
predict_disease
APP_NAME
=
'DME_IDENTIFIER'
app
=
Flask
(
APP_NAME
)
CORS
(
app
)
def
clean_dir
(
save_dir
):
try
:
shutil
.
rmtree
(
save_dir
)
print
(
f
"Directory '{save_dir}' removed successfully."
)
except
OSError
as
e
:
print
(
f
"Error: {e}"
)
@
app
.
route
(
'/predict'
,
methods
=
[
'POST'
])
def
predict
():
# Check if an image was uploaded
if
'image'
not
in
request
.
files
:
return
jsonify
({
'error'
:
'No image uploaded'
})
file
=
request
.
files
[
'image'
]
# Save the uploaded image to a designated directory
if
file
:
file
=
request
.
files
[
'image'
]
image
=
file
.
read
()
save_dir
=
'temp'
# clean_dir(save_dir)
if
not
os
.
path
.
exists
(
save_dir
):
os
.
makedirs
(
save_dir
)
image_path
=
os
.
path
.
join
(
save_dir
,
"image.png"
)
# Specify the path where you want to save the image
with
open
(
image_path
,
'wb'
)
as
image_file
:
image_file
.
write
(
image
)
# clean output dir befor crop
clean_dir
(
OUTPUT_DIR
)
run
()
predict_class
,
predicted_percentage
=
start_predict
()
# clean output dir after crop
# clean_dir(save_dir)
# clean_dir(OUTPUT_DIR)
prediction
=
predict_class
prediction_label
=
'DME'
if
prediction
==
0
else
'NORMAL'
# my return jsonify({'predicted_class': prediction , "prediction_label" : prediction_label , "predicted_percentage" : predicted_percentage})
return
jsonify
({
'time'
:
prediction
,
"top"
:
prediction_label
,
"confidence"
:
predicted_percentage
,
'image'
:
{
'height'
:
1584
,
'width'
:
2376
},})
@
app
.
route
(
'/predict/glaucoma'
,
methods
=
[
'POST'
])
# @cross_origin(origin='*',headers=['Content- Type','Authorization'])
def
predictG
():
print
(
"hihi"
)
# Check if an image was uploaded
if
'image'
not
in
request
.
files
:
print
(
"hoooo1"
)
return
jsonify
({
'error'
:
'No image uploaded'
})
# Load and preprocess the image received from the Flask API
file
=
request
.
files
[
'image'
]
image
=
file
.
read
()
save_dir
=
'tempG'
# clean_dir(save_dir)
if
not
os
.
path
.
exists
(
save_dir
):
os
.
makedirs
(
save_dir
)
# Save the image as "image.png"
image_path
=
os
.
path
.
join
(
save_dir
,
"image.png"
)
# Specify the path where you want to save the image
with
open
(
image_path
,
'wb'
)
as
image_file
:
image_file
.
write
(
image
)
prediction
=
predict_disease
(
image
)
# return jsonify({'predicted_class': prediction})
return
(
prediction
)
if
APP_NAME
==
'DME_IDENTIFIER'
:
# app.run(debug=False)
app
.
run
(
host
=
'0.0.0.0'
,
port
=
8081
,
debug
=
True
)
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