-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (23 loc) · 890 Bytes
/
app.py
File metadata and controls
30 lines (23 loc) · 890 Bytes
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
from flask import Flask, render_template, request
import pickle
import os
# initialised the Flask app
app = Flask(__name__)
# load and saved the SVD model
model_path = os.path.join('model','svd_model.pkl')
with open(model_path, 'rb') as model_file:
model = pickle.load(model_file)
# Dummy data for user and product IDs
users = list(range(1, 1001))
products = list(range(1, 501))
@app.route('/')
def index():
return render_template('index.html', users = users, products = products)
@app.route('/recommend', methods=['POST'])
def recommend():
user_id = int(request.form['user_id'])
product_id = int(request.form['product_id'])
prediction = model.predict(user_id, product_id)
return render_template('result.html', user_id = user_id, product_id = product_id, predicted_rating = prediction.est)
if __name__ == '__main__':
app.run(host='0.0.0.0', port = 5000)