-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
35 lines (27 loc) · 1.06 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
from flask import Flask, render_template, jsonify, request
import os
from prediction_service import prediction
params_path = "params.yaml"
webapp_root = "webapp"
static_dir = os.path.join(webapp_root, "static")
template_dir = os.path.join(webapp_root, "templates")
app = Flask(__name__, static_folder=static_dir, template_folder=template_dir)
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
try:
if request.form:
data_request = dict(request.form)
response = prediction.form_response(data_request)
return render_template("index.html", response=response)
elif request.json:
response = prediction.api_response(request.json)
return jsonify(response)
except Exception as e:
print(e)
error = {"error": e}
return render_template("404.html", error=error)
else:
return render_template("index.html")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)