-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapplication.py
More file actions
39 lines (28 loc) · 1.04 KB
/
application.py
File metadata and controls
39 lines (28 loc) · 1.04 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
from flask import Flask, jsonify, request, render_template, abort
# from Src.utils import ClassificationModelBuilder # Uncomment only if you want to re-train your model
from Src.api.predict import predict_api
from jinja2 import TemplateNotFound
application = Flask(__name__ , template_folder='./Src/templates')
application.register_blueprint(predict_api, url_prefix='/titanic-survival-classification-model')
# Loading home page
@application.route('/', defaults={'page': 'index'})
@application.route('/<page>')
def show(page):
try:
print('home route')
return render_template(f'{page}.html', app_name='Titanic Survival: Classification Problem')
except TemplateNotFound:
abort(404)
# Handling 400 Error
@application.errorhandler(400)
def bad_request(error=None):
message = {
'status': 400,
'message': 'Bad Request: ' + request.url + '--> Please check your data payload...',
}
resp = jsonify(message)
resp.status_code = 400
return resp
# run application
if __name__ == "__main__":
application.run()