Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Salamander - API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Herman Andersen Dyrkorn
Salamander - API
Commits
6e4c9a9d
Commit
6e4c9a9d
authored
Feb 18, 2021
by
Herman Andersen Dyrkorn
Browse files
Options
Downloads
Patches
Plain Diff
storing images in tempfolder for matching and storing
parent
be76a47e
No related branches found
No related tags found
1 merge request
!18
Resolve "refactoring matchsalamander and register location endpoint"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/endpoints/findsalamanderinfo.py
+22
-4
22 additions, 4 deletions
api/endpoints/findsalamanderinfo.py
with
22 additions
and
4 deletions
api/endpoints/findsalamanderinfo.py
+
22
−
4
View file @
6e4c9a9d
...
@@ -2,17 +2,35 @@ from flask import request, jsonify
...
@@ -2,17 +2,35 @@ from flask import request, jsonify
from
flask_restful
import
Resource
from
flask_restful
import
Resource
from
flask_jwt_extended
import
get_jwt_identity
,
jwt_required
from
flask_jwt_extended
import
get_jwt_identity
,
jwt_required
ALLOWED_EXTENSIONS
=
[
'
jpeg
'
,
'
png
'
,
'
jpg
'
]
# findSalamanderInfo endpoint
# findSalamanderInfo endpoint
class
FindSalamanderInfo
(
Resource
):
class
FindSalamanderInfo
(
Resource
):
@staticmethod
@staticmethod
@jwt_required
@jwt_required
def
post
():
def
post
():
if
"
image
"
not
in
request
.
files
:
return
jsonify
({
"
message
"
:
"
no file given
"
})
image
=
request
.
files
[
'
image
'
]
image
=
request
.
files
[
'
image
'
]
user_id
=
get_jwt_identity
()
if
image
.
filename
!=
''
:
if
image
.
filename
!=
''
:
if
image
and
allowed_image
(
image
.
filename
):
# run AI on image
# run AI on image
output
=
{
"
sex
"
:
"
AI_sex
"
,
"
species
"
:
"
AI_species
"
}
# store processed and original image
image
.
filename
=
str
(
user_id
)
+
"
.
"
+
extension
(
image
.
filename
)
image
.
save
(
"
temp_images/
"
+
image
.
filename
)
return
jsonify
({
"
sex
"
:
"
AI_sex
"
,
"
species
"
:
"
AI_species
"
})
else
:
return
jsonify
({
"
message
"
:
"
file extension not allowed
"
})
else
:
else
:
output
=
{
"
message
"
:
"
something wrong with image
"
}
return
jsonify
({
"
message
"
:
"
something wrong with image
"
})
def
allowed_image
(
filename
):
return
'
.
'
in
filename
and
\
filename
.
rsplit
(
'
.
'
,
1
)[
1
].
lower
()
in
ALLOWED_EXTENSIONS
return
output
def
extension
(
filename
):
return
filename
.
rsplit
(
'
.
'
,
1
)[
1
].
lower
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment