Commit e1305cde authored by Fia's avatar Fia

update with image

parent 640d6d4c
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
<!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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment