-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
55 lines (40 loc) · 1.19 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
50
51
52
53
54
import os
import sys
import logging
from flask import Flask, request, render_template
from flask_cors import CORS
from serve import get_model_api
# define the app
app = Flask(__name__, static_url_path='')
CORS(app) # needed for cross-domain requests, allow everything by default
# logging for heroku
if 'DYNO' in os.environ:
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.INFO)
# load the model
model_api = get_model_api()
@app.route('/predict', methods=['POST'])
def predict():
if request.method == 'POST':
message = request.form['message']
my_prediction = model_api(message)
return render_template('result.html', prediction=my_prediction)
@app.route('/')
def index():
return render_template("home.html")
# HTTP Errors handlers
@app.errorhandler(404)
def url_error(e):
return """
Wrong URL!
<pre>{}</pre>""".format(e), 404
@app.errorhandler(500)
def server_error(e):
return """
An internal error occurred: <pre>{}</pre>
See logs for full stacktrace.
""".format(e), 500
if __name__ == '__main__':
# This is used when running locally.
# app.run(host='0.0.0.0', debug=True)
app.run()