forked from imshreyshah/Courses-Recommendation-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
47 lines (34 loc) · 1.26 KB
/
server.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
#Setting path variables
import sys
from configs import *
sys.path.append(PROJECT_PATH)
#Importing required libraries
from flask import Flask,render_template,request
from Recommendation_Generator.generator import recommendationGenerator
features,data = recommendationGenerator.load_data(recommendationGenerator, datapath= DATA_PATH)
users = data['userID'].unique()
app = Flask(__name__)
#HomePage
@app.route("/")
def home():
return render_template("index.html",max = users.shape[0] -1)
#ResultPage
@app.route("/result", methods=["GET", "POST"])
def result():
if request.method == "POST":
#Collecting the form responses
userdata = request.form
#Extracting the values for UserIndex and No. of recommendations
user = int(userdata.get("index"))
N = int(userdata.get("N"))
#Getting the userID from the user Index
users = data['userID'].unique()
userID = int(users[user])
#Running the model, generating recommendations and passing the list to the HTML page
model = recommendationGenerator(userID, N)
recomm = model.generate_recommendations(features,data)
return render_template("result.html",userID = userID ,rec_list= recomm)
else:
return "Sorry, there was an error."
if __name__ == "__main__":
app.run(debug= True)