-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
38 lines (28 loc) · 1.11 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
from flask import Flask, render_template, request, jsonify
import os
import numpy as np
from prediction_service import prediction
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:
dict_req = dict(request.form)
response = prediction.form_response(dict_req)
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": "Something went wrong!! Try again later!"}
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)