-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (45 loc) · 1.33 KB
/
app.py
File metadata and controls
61 lines (45 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
# Cloud for ML Final Project
# Cole Smith
# app.py
#
import base64
import os
from io import BytesIO
from PIL import Image
from flask import Flask, request, jsonify
import load_model as load_model
# ------------------------------------------------------------------
# FLASK APP
# ------------------------------------------------------------------
# Make dirs for ingress and egress
if not os.path.exists("tmp"):
os.makedirs("tmp")
if not os.path.exists("output"):
os.makedirs("output")
app = Flask(__name__)
@app.route('/', methods=["POST"])
def upload_image():
"""
Returns JSON in the form:
{
'class': str(cls),
'probability': float(conf),
'blurredImage': str(encoded_img),
'maskImage': str(encoded_img_mask),
'unblurredMask': str(encoded_img_saliency)
}
Where images are in base64.
@return: JSON
"""
data = request.get_json()
# Handle empty request
if data is None:
print("[ ERR ] Request body invalid: empty")
return "Error: Missing Request"
# Decode image and predict output
img = Image.open(BytesIO(base64.urlsafe_b64decode(data['img'])))
print("[ INF ] Success: Image Loaded")
return jsonify(load_model.predict(img))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)