-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
81 lines (73 loc) · 2.26 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from flask import Flask, request, jsonify
import json
import Litmus as lt
import utils
import os
import markdown
app = Flask(__name__)
TIMEOUT = 1800
recommender_system = lt.Litmus()
@app.route('/', methods = ["GET"])
def index():
with open(os.path.dirname(app.root_path) + '/Chirp/README.md','r') as readme:
content = readme.read()
return markdown.markdown(content)
# @app.route('/recommend', methods = ["GET"])
# def recommendation():
# data = request.get_json()
# try:
# new_data = utils.normalizeJson(data)
# result = recommender_system.recommendContent(
# new_data["current_data"], new_data["data_pool"],
# new_data["interest_score"], new_data["number_of_recommendations"],
# 0.0
# )
# if result["status"] == "failed":
# return jsonify(
# {"data" : [],
# "message" : "System failed, please use /recommend_debug to see the error",
# "status" : "failed"
# }
# )
# return jsonify(
# {"data" : result["new content"],
# "message" : "",
# "status" : result["status"]}
# )
# except:
# return jsonify(
# {
# "data" : [],
# "message" : "System failed, please use /recommend_debug to see the error",
# "status" : "failed"
# }
# )
@app.route('/recommend',methods = ["GET"])
def recommendationDebug():
data = request.get_json()
parse = utils.chirpJsonParser(data)
if parse[0]:
new_data = utils.normalizeJson(data)
# print(new_data)
result = recommender_system.recommendContent(
new_data["current_data"], new_data["data_pool"],
new_data["interest_score"], new_data["number_of_recommendations"],
0.0
)
if result["status"] == "failed":
return jsonify(
{"data" : [],
"message" : result["error"],
"status" : result["status"]
}
)
return jsonify(
{"data" : result["new content"],
"message" : "",
"status" : result["status"]}
)
else:
return jsonify({"data" : [], "message" : parse[1], "status" : "Failed"})
if __name__ == "__main__":
app.run(debug = True)
pass