-
Notifications
You must be signed in to change notification settings - Fork 49
/
app.py
49 lines (35 loc) · 1.01 KB
/
app.py
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
# Digital OCEAN FLASK SERVER RECEIVES IMAGE
from flask import Flask, request, jsonify
import classify
import base64
import json
import firebase
import env
# Instantiate Flask
app = Flask(__name__)
# health check
@app.route('/status')
def health_check():
return 'Running!'
# Performing image Recognition on Image, sent as bytes via POST payload
@app.route('/detect', methods=["POST"])
def detect():
imgBytes = request.data
imgdata = base64.b64decode(imgBytes)
with open("temp.png", 'wb') as f:
f.write(imgdata)
print("successfully receieved image")
# Pass image bytes to classifier
result = classify.analyse("temp.png")
# Return results as neat JSON object, using
result = jsonify(result)
print(result.json)
response_data = result.json
print(response_data)
db = firebase.Firebase()
db.authenticate()
db.push(response_data)
print("Updated Firebase.")
return result
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80, debug=True)