-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (35 loc) · 1.43 KB
/
main.py
File metadata and controls
41 lines (35 loc) · 1.43 KB
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
from flask import Flask, render_template, make_response, request
from database import *
import json
app = Flask(__name__)
@app.route('/')
def index():
product_data = GetProduct()
clicked_product = []
home_recommend={}
if request.cookies.get('clicked_product') is not None:
clicked_product = json.loads(request.cookies.get('clicked_product'))
home_recommend = homeRecommendation(clicked_product)
res= make_response(render_template('index.html', data=product_data, clicked_product=clicked_product, home_recommend=home_recommend))
if request.cookies.get('clicked_product') is None:
res.set_cookie('clicked_product', '[]')
return res
@app.route("/product/<id>")
def product(id):
product_data = GetProductById(int(id))
if product_data is None:
return "Product not found", 404
clicked_product = request.cookies.get('clicked_product')
if clicked_product:
clicked_product = json.loads(clicked_product)
else:
clicked_product = []
if id not in clicked_product:
clicked_product.append(id)
recommend = vectorSearch(product_data['plot_embedding'])
res = make_response(render_template('product.html', id=id, data=product_data, recommend=recommend))
# Update the cookie with the new clicked_product list
res.set_cookie('clicked_product', json.dumps(clicked_product))
return res
if __name__ == '__main__':
app.run(debug=True)