File size: 1,524 Bytes
3aaa0a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, jsonify, request
import pickle
import pandas as pd
import numpy as np

app = Flask(__name__)

# Load pickled data
# Open the file using 'with' statement
with open('popular1.pkl', 'rb') as f:
    popular_df = pd.read_pickle(f)
with open('pt1.pkl', 'rb') as fi:
    pt = pd.read_pickle(fi)
with open('banquet.pkl', 'rb') as fil:
    banquets = pd.read_pickle(fil)
with open('similarity_scores1.pkl', 'rb') as file:
    similarity_scores = pd.read_pickle(file)
# Define a route to get recommendations
@app.route('/recommend/<string:n>',methods=['GET'])
def recommend(n):
    # Get user input from request
   

    # Perform recommendation logic
    if n not in pt.index:
       return "Banquet not found in the index"

    index = np.where(pt.index == n)[0][0]
    similar_items = sorted(enumerate(similarity_scores[index]), key=lambda x: x[1], reverse=True)[1:5]

    data = []
    for i in similar_items:
        item = []
        temp_df = banquets[banquets['Hall-Name'] == pt.index[i[0]]]
        item.extend(temp_df.drop_duplicates('Hall-Name')['Hall-Name'].values)
        item.extend(temp_df.drop_duplicates('Hall-Name')['Address'].values)
        item.extend(temp_df.drop_duplicates('Hall-Name')['Contact'].values)
        item.extend(temp_df.drop_duplicates('Hall-Name')['Rating'].values)
        item.extend(temp_df.drop_duplicates('Hall-Name')['Jn12ke src'].values)
        data.append(item)

    return jsonify({'recommendations': data})

if __name__ == "__main__":
    app.run(debug=True)