Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
Flask
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Metrics
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Administrator
Flask
Commits
e1305cde
Commit
e1305cde
authored
Jun 19, 2020
by
Fia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update with image
parent
640d6d4c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
hello_app.py
hello_app.py
+14
-0
static/predict.html
static/predict.html
+46
-0
No files found.
hello_app.py
View file @
e1305cde
import
base64
import
io
from
PIL
import
Image
from
flask
import
request
from
flask
import
jsonify
from
flask
import
Flask
...
...
@@ -14,3 +17,14 @@ def hello():
return
jsonify
(
response
)
@
app
.
route
(
'/predict'
,
methods
=
[
'POST'
])
def
predict
():
message
=
request
.
get_json
(
force
=
True
)
encoded
=
message
[
'image'
]
decoded
=
base64
.
b64decode
(
encoded
)
image
=
Image
.
open
(
io
.
BytesIO
(
decoded
))
response
=
{
'prediction'
:
'Hello, !'
}
return
jsonify
(
response
)
\ No newline at end of file
static/predict.html
0 → 100644
View file @
e1305cde
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
Hello, GNOME!
</title>
<style
type=
"text/css"
>
body
{
font-face
:
Cantarell
,
sans-serif
;
text-align
:
center
;
}
</style>
</head>
<body>
<input
id=
"name-input"
types=
"text"
>
<button
id=
"name-button"
>
Submit Name
</button>
<p><span
id=
"dog-prediction"
></span></p>
<script
src=
"https://code.jquery.com/jquery-3.3.1.min.js"
></script>
<script>
let
base64Image
;
$
(
"
#image-selector
"
).
change
(
function
(){
let
reader
=
new
FileReader
();
reader
.
onload
=
funciton
(
e
)
{
let
dataURL
=
reader
.
result
;
$
(
'
#selected-image
'
).
attr
(
"
src
"
,
dataURL
);
base64Image
=
dataURL
.
replace
(
"
date:image/png;base64,
"
,
""
);
console
.
log
(
base64Image
);
}
reader
.
readAsDataURL
(
$
(
"
#image-selector
"
)[
0
].
files
[
0
]);
alert
(
'
aaaaaa
'
);
});
$
(
"
#predict-button
"
).
click
(
function
(
event
){
let
message
=
{
image
:
base64Image
}
console
.
log
(
message
);
$
.
post
(
"
http://127.0.0.1:5000/predict
"
,
JSON
.
stringify
(
message
),
function
(
response
){
$
(
"
#dog-prediction
"
).
text
(
response
.
greeting
);
console
.
log
(
response
);
});
});
</script>
</body>
</html>
\ No newline at end of file
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