-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
38 lines (30 loc) · 1011 Bytes
/
api.py
File metadata and controls
38 lines (30 loc) · 1011 Bytes
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
from flask import Flask, request, jsonify
import logging
import os
import model_core
#fire up Flask
app = Flask(__name__)
#fire up logging framework and log to std output
log = logging.getLogger("assessment")
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
@app.route('/model', methods = ['POST'])
def model_api():
input_data = request.json
#log incoming data in standard output
log.info("New input request received by API:")
log.info(str(input_data))
#send data to the prediction model
try:
prediction = model_core.get_prediction(log, input_data)
except Exception as e:
log.error('ERROR: model crashed for the given input')
log.error(str(e))
prediction = -1
if prediction > 0:
result = {
'popular_make_probability': prediction
}
return jsonify(result), 200
return 'Error occurred. See server logs...', 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)