-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (28 loc) · 899 Bytes
/
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
# Create a flask app
from flask import Flask, jsonify
from flask_cors import CORS
from service import get_all_users, predict, get_user_details
app = Flask(__name__)
CORS(app, supports_credentials=True)
app.config["CORS_HEADERS"] = "Content-Type"
@app.route("/")
def hello_world():
return "Hello, World!"
# Returns users in the database
@app.route("/users")
def get_users():
users = get_all_users()
return jsonify(users)
# Returns demographic and payment details of one user
@app.route("/users/<int:user_id>")
def get_userdetails(user_id):
user_details = get_user_details(user_id)
return jsonify(user_details)
# Returns the default prediction and prediction
# confidence of one user
@app.route("/users/<int:user_id>/prediction")
def predict_(user_id):
prediction = predict(user_id)
return jsonify(prediction)
if __name__ == "__main__":
app.run(debug=True)