Snigs98 commited on
Commit
5a302bb
·
verified ·
1 Parent(s): f59cfba

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +86 -0
  2. restaurants.pkl +3 -0
  3. similarity.pkl +3 -0
  4. vectorizer.pkl +3 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ import joblib
4
+ import pandas as pd
5
+ from sklearn.metrics.pairwise import cosine_similarity
6
+
7
+ # ==============================
8
+ # Load Saved Files
9
+ # ==============================
10
+ df = joblib.load("restaurants.pkl")
11
+ vectorizer = joblib.load("vectorizer.pkl")
12
+ similarity_matrix = joblib.load("similarity.pkl")
13
+
14
+ # ==============================
15
+ # Prepare Dropdown Lists
16
+ # ==============================
17
+
18
+ # Cities
19
+ cities = sorted(df["Location"].unique())
20
+
21
+ # Extract cuisines
22
+ cuisines = sorted(
23
+ set(
24
+ cuisine.strip()
25
+ for sublist in df["Cuisine"].astype(str).str.split(",")
26
+ for cuisine in sublist
27
+ )
28
+ )
29
+
30
+ # ==============================
31
+ # Recommendation Function
32
+ # ==============================
33
+
34
+ def recommend_restaurants(cuisine, city, veg_pref):
35
+
36
+ filtered = df[df["Location"] == city]
37
+
38
+ if veg_pref != "Any":
39
+ filtered = filtered[filtered["Pure Veg"] == veg_pref]
40
+
41
+ if len(filtered) == 0:
42
+ return "No restaurants found for this selection."
43
+
44
+ # Vectorize selected cuisine
45
+ cuisine_vec = vectorizer.transform([cuisine.lower()])
46
+ tfidf_filtered = vectorizer.transform(filtered["Cuisine"])
47
+
48
+ sim_scores = cosine_similarity(cuisine_vec, tfidf_filtered).flatten()
49
+
50
+ top_idx = sim_scores.argsort()[-5:][::-1]
51
+
52
+ recs = filtered.iloc[top_idx]
53
+
54
+ result = ""
55
+
56
+ for _, row in recs.iterrows():
57
+ result += f"""
58
+ 🍽 Restaurant: {row['Restaurant Name']}
59
+ 🍜 Cuisine: {row['Cuisine']}
60
+ ⭐ Rating: {row['Rating']}
61
+ 💰 Price: ₹{row['Average Price']}
62
+ 📍 Area: {row['Area']}
63
+
64
+ -------------------------
65
+ """
66
+
67
+ return result
68
+
69
+
70
+ # ==============================
71
+ # Gradio UI
72
+ # ==============================
73
+
74
+ interface = gr.Interface(
75
+ fn=recommend_restaurants,
76
+ inputs=[
77
+ gr.Dropdown(cuisines, label="Select Cuisine"),
78
+ gr.Dropdown(cities, label="Select City"),
79
+ gr.Dropdown(["Any", "Yes", "No"], label="Pure Veg Preference"),
80
+ ],
81
+ outputs=gr.Textbox(label="Recommended Restaurants"),
82
+ title="🍔 AI Food Recommendation System",
83
+ description="Select cuisine and city to get restaurant recommendations."
84
+ )
85
+
86
+ interface.launch()
restaurants.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:002dbca40009fb6528432ca5db2e8e3ad0866f38e7c79616526742b6d3281b5f
3
+ size 1312083
similarity.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2045533bf9316677d719501e66229e00f8f5a600f01005572c979b9257134ecf
3
+ size 421544889
vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b9532e1b4fa8593f8e82124a6d5c58487f78281d4b31b0ed58a510077d1e699c
3
+ size 2720