forked from newsdev/who-the-hill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
44 lines (37 loc) · 1.25 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
from flask import Flask, request, Response, jsonify
import boto3
import botocore
import base64
import logging
from log_filter import HealthcheckFilter
app = Flask(__name__)
healthcheck_filter = HealthcheckFilter()
log = logging.getLogger('werkzeug')
log.addFilter(healthcheck_filter)
log.setLevel(logging.INFO)
logging.basicConfig(level=logging.INFO)
client = boto3.client('rekognition')
@app.route('/healthcheck', methods=["GET"])
def healthcheck():
'''
Checks that the app is properly running.
'''
return 'shazongress'
@app.route('/recognize', methods=["POST"])
def recongize():
'''
Receives POST request from Twilio. Sends data from request to Amazon Rekognize and receives the API's analysis.
Returns the resulting analysis as JSON.
'''
# Reads image data from incoming request
r = request
data = r.files['file'].read()
# Sends image data to Amazon Rekognize for analysis. Returns JSON response of results.
try:
results = client.recognize_celebrities(Image={'Bytes': data})
except botocore.exceptions.ClientError as e:
results = {"Rekognition Client Error": str(e)}
logging.info(results)
return jsonify(results)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8888, debug=True)