-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
56 lines (43 loc) · 1.5 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
# render_template - api uses to generate html
# request - object we need for forms
from flask import Flask, jsonify, request, redirect, render_template, flash
import pandas as pd
import pickle
from scipy import spatial
import os
import json
from recommend_GloVe.recommend_GloVe_average import recommend
with open("./static/courses.json", "r") as courses_file:
courses = json.load(courses_file)
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/rec',methods=['POST'])
def getvalue():
try:
coursename = request.form['search'].split(" ")[0]
lowlvl = 'lowlvl' in request.form
dept_filter = 'dept_filter' in request.form
df = recommend([coursename], blacklist_lowerlevel=lowlvl, blacklist_dept=dept_filter)
return render_template('result.html', tables = df, course = coursename)
except Exception as e:
error = "Invalid Course ID. Please Try Again"
return render_template('index.html', error = error)
@app.route('/search', methods=['POST'])
def search():
term = request.form['q']
print ('term: ', term)
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
json_url = os.path.join(SITE_ROOT, "data", "newresults.json")
json_data = json.loads(open(json_url).read())
#print (json_data)
#print (json_data[0])
filtered_dict = [v for v in json_data if term.lower() in v.lower()]
# print(filtered_dict)
resp = jsonify(filtered_dict)
resp.status_code = 200
print(resp)
return resp
if __name__ == '__main__':
app.run(debug=True)