rbbist commited on
Commit
42f39de
·
verified ·
1 Parent(s): 88bdedf

Initial Commit

Browse files
Files changed (4) hide show
  1. app.py +12 -0
  2. menu_chromadb_semantic_search.py +50 -0
  3. menu_items.csv +202 -0
  4. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from menu_chromadb_semantic_search import search_dishes
3
+
4
+ iface = gr.Interface(
5
+ fn=search_dishes,
6
+ inputs=gr.Textbox(label="Search for a dish"),
7
+ outputs=gr.Textbox(label="Top 5 Similar Dishes"),
8
+ title="Menu Item Semantic Search",
9
+ description="Type a dish name to find the top 5 similar menu items."
10
+ )
11
+
12
+ iface.launch()
menu_chromadb_semantic_search.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import chromadb
2
+ from chromadb.utils import embedding_functions
3
+ import csv
4
+
5
+ # --- Setup ChromaDB (in-memory for Hugging Face Spaces free tier) ---
6
+ chroma_client = chromadb.Client()
7
+
8
+ # SentenceTransformer embedding function
9
+ sentence_transformer_ef = embedding_functions.SentenceTransformerEmbeddingFunction(
10
+ model_name="all-MiniLM-L6-v2"
11
+ )
12
+
13
+ # Create collection
14
+ collection = chroma_client.create_collection(
15
+ name="my_collection",
16
+ embedding_function=sentence_transformer_ef
17
+ )
18
+
19
+ # --- Load CSV data ---
20
+ with open("menu_items.csv") as file:
21
+ lines = csv.reader(file)
22
+ documents = []
23
+ metadatas = []
24
+ ids = []
25
+
26
+ for i, line in enumerate(lines):
27
+ if i == 0:
28
+ continue # skip header
29
+ documents.append(line[1])
30
+ metadatas.append({"item_id": line[0]})
31
+ ids.append(str(i))
32
+
33
+ # Add to ChromaDB
34
+ collection.add(
35
+ documents=documents,
36
+ metadatas=metadatas,
37
+ ids=ids
38
+ )
39
+
40
+ def search_dishes(query: str) -> str:
41
+ """Search for top 5 similar dishes."""
42
+ results = collection.query(
43
+ query_texts=[query],
44
+ n_results=5,
45
+ include=["documents", "metadatas"]
46
+ )
47
+ hits = results["documents"][0]
48
+ ids_meta = results["metadatas"][0]
49
+ output = [f"{ids_meta[i]['item_id']}: {hits[i]}" for i in range(len(hits))]
50
+ return "\n".join(output)
menu_items.csv ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "item_id","item_name"
2
+ "A1","Vegan Chicken Salad"
3
+ "A2","Spring Rolls (4 pieces)"
4
+ "A3","Pot Stickers (6 pieces)"
5
+ "A4","Fried Wonton (10 pieces)"
6
+ "A5","Fried Tofu with Soy Sauce"
7
+ "A6","Salt and Pepper Tofu"
8
+ "A7","Vegetable Tempura"
9
+ "A11","Salt and Pepper Fresh Mushrooms"
10
+ "A12","Salt and Pepper Vegan Chicken"
11
+ "A13","Moo Shu Vegetable (6 pieces)"
12
+ "A15","Salt and Pepper Pumpkin"
13
+ "A16","Salt and Pepper Green Beans"
14
+ "A17","Chinese Doughnut"
15
+ "A18","French Fries"
16
+ "B3","San Pellegrino"
17
+ "B6","Thai Ice Almond Milk Tea"
18
+ "B7","Lemon Ice Tea"
19
+ "B8","Snapple"
20
+ "B14","Soda"
21
+ "B15","Bottled Water"
22
+ "B16","Strawberry Popping Boba Tea"
23
+ "B17","Mango Popping Boba Tea"
24
+ "B18","Lemon Popping Boba Tea"
25
+ "B19","Passionfruit Popping Boba Tea"
26
+ "B21","Wintermelon Tea with Popping Boba"
27
+ "B22","Grapefruit Tea with Popping Boba"
28
+ "B24","Mango Smoothie"
29
+ "B25","Strawberry Smoothie"
30
+ "B26","Strawberry Jelly Tea"
31
+ "B27","Mango Jelly Tea"
32
+ "B28","Passionfruit Jelly Tea"
33
+ "B29","Grapefruit Jelly Tea"
34
+ "B30","Fresh Orange Juice"
35
+ "B31","Veggie Lee Secret Drink"
36
+ "B32","Avocado Smoothie"
37
+ "B33","Banana Smoothie"
38
+ "B34","Taro Tapioca Pearl Coconut Milk"
39
+ "B35","Pearl Milk Tea"
40
+ "B36","Brown Sugar Pearl Cream Tea"
41
+ "B37","Passionfruit Pearl Green Tea"
42
+ "B38","Mango Pearl Green Tea"
43
+ "B39","Strawberry Pearl Green Tea"
44
+ "E1","Ginger with Pea Leaves"
45
+ "E2","Pea Leaves with Bamboo Fungus"
46
+ "E3","Pea Leaves with Ginko Nuts and Dry Bean Curd"
47
+ "E5","Pea Leaves with Black Mushrooms"
48
+ "E6","Pea Leaves with Abalone Mushrooms"
49
+ "E11","Bok Choy with Ginger"
50
+ "E12","Chinese Broccoli with Ginger"
51
+ "E13","Sauteed Basil and Chinese Broccoli"
52
+ "E14","Broccoli with 3 Types of Mushrooms"
53
+ "E15","Broccoli with Szechuan Sauce"
54
+ "E16","Broccoli with Ginger"
55
+ "E17","Sauteed Basil Green Beans"
56
+ "E18","Dry Sauteed Green Beans"
57
+ "E19","Green Beans with Ginger"
58
+ "E20","Eggplant in Szechuan Sauce"
59
+ "E21","Satay Eggplant"
60
+ "E22","Sauteed Fried Tofu with Eggplant"
61
+ "E23","Braised Fried Tofu with Greens"
62
+ "E24","Mushrooms and Tofu in Satay Sauce"
63
+ "E25","Sauteed Assorted Vegetables"
64
+ "E27","Soft Tofu with Minced Vegan Pork and Chili"
65
+ "E28","Sauteed Lotus Root"
66
+ "E29","Mixed Vegetables with Fungus"
67
+ "E30","Braised Mixed Vegetables"
68
+ "E31","Fried Tofu with Golden Mushrooms and Goji Berry"
69
+ "E33","Kung Pao Tofu"
70
+ "E34","Sweet and Sour Tofu"
71
+ "E35","Sizzling Fried Tofu with Black Bean Sauce"
72
+ "E36","Sizzling Vegan Chicken with Black Pepper"
73
+ "E37","Sizzling Vegan Beef and Mushroom"
74
+ "E38","Sizzling Eggplant and Vegan Fish Steak"
75
+ "E39","Sizzling 3 Flavors Vegan Chicken"
76
+ "E40","Sizzling Vegan Fish with Black Pepper Sauce"
77
+ "E41","Thai Style Vegan Fish Fillet"
78
+ "E42","Vegan Assorted Meat with Tofu Hot Pot"
79
+ "E43","Mixed Fresh Mushrooms Hot Pot"
80
+ "E45","Healthy Herbal Rice Hot Pot"
81
+ "E46","Thai Style Rice Hot Pot"
82
+ "E48","Pumpkin and Tofu with Curry Sauce"
83
+ "E49","Eggplant Wheat Gluten with Pumpkin"
84
+ "E50","Melon and Vermicelli"
85
+ "E53","Vegan Prawns with Mixed Nuts"
86
+ "E54","Vegan Prawns and Mushrooms with Black Pepper Sauce"
87
+ "E56","Vegan Prawns and Mushrooms and Vegetables"
88
+ "E57","Vegan Kung Pao Prawns"
89
+ "E58","House Saute with Marinated Bean Curd"
90
+ "E59","Snow Pea, Broccoli and Black Mushrooms"
91
+ "E63","Vegan Sesame Chicken"
92
+ "E64","General Tso's Vegan Chicken"
93
+ "E65","Vegan Orange Chicken"
94
+ "E66","Vegan Chicken with Mushrooms"
95
+ "E67","Vegan Kung Pao Chicken"
96
+ "E68","Vegan Chicken with Broccoli"
97
+ "E69","Vegan Chicken with Curry Sauce"
98
+ "E70","Vegan Chicken with Sichuan-Style"
99
+ "E71","Vegan Chicken with Sweet and Sour Sauce"
100
+ "E72","Kung Pao Vegan Beef, Chicken and Prawns"
101
+ "E74","Vegan Beef with Bitter Melon"
102
+ "E75","Mongolian Vegan Beef"
103
+ "E76","Vegan Beef with Satay Sauce"
104
+ "E77","Vegan Beef with Green Beans"
105
+ "E78","Vegan Beef with Black Pepper Sauce"
106
+ "E79","Vegan Beef with Chinese Broccoli"
107
+ "E80","Vegan Beef with Assorted Vegetables"
108
+ "E81","Vegan Beef with Broccoli"
109
+ "E83","Vegan Pork with Sichuan Sauce"
110
+ "E84","Mixed Mushrooms and Mixed Nuts"
111
+ "E85","Salt and Pepper Vegan Prawns"
112
+ "L1","Assorted Vegetables"
113
+ "L2","Snow Bean Vege Chicken and Tofu"
114
+ "L3","Eggplant in Sichuan Style"
115
+ "L4","Broccoli in Sichuan Style"
116
+ "L5","Vegan Pork in Sichuan Style"
117
+ "L6","Vegan Pork and Sweet and Sour Sauce"
118
+ "L7","Vegan Beef with Broccoli"
119
+ "L8","Vegan Beef with Mongolian-Style"
120
+ "L9","Vegan Beef with Sichuan-Style"
121
+ "L10","Vegan Beef with Black Pepper Sauce"
122
+ "L11","Vegan Pork and Cabbage"
123
+ "L12","Vegan Sesame Chicken"
124
+ "L13","General Tso's Vegan Chicken"
125
+ "L14","Orange Vegan Chicken"
126
+ "L15","Fresh Mushrooms with Vegan Chicken"
127
+ "L16","Salt and Pepper Vegan Chicken"
128
+ "L17","Kung Pao Vegan Chicken"
129
+ "L18","Vegan Chicken with Cashew Nuts"
130
+ "L19","Vegan Chicken with Black Bean Sauce"
131
+ "L20","Vegan Chicken with Curry Sauce"
132
+ "L21","Vegan Pork with Green Beans"
133
+ "L22","Dry Sauteed Green Beans"
134
+ "L23","Soft Tofu with Vegan Minced Pork and Chili"
135
+ "L24","Braised Fried Tofu with Greens"
136
+ "L25","Kung Pao Sauce with Mixed Vegetables"
137
+ "L26","Kung Pao Vegan Prawns"
138
+ "L27","Vegan Prawns with Mixed Vegetables"
139
+ "L28","Bok Choy with Ginger"
140
+ "L29","Deluxe Mixed Vegetables"
141
+ "L30","Black and White Mushrooms with Tofu"
142
+ "R1","Veggie Lee Style Fried Rice"
143
+ "R2","Yin-Yang Fried Rice"
144
+ "R3","Fu-Kin Fried Rice"
145
+ "R4","Chef Lee Fried Rice"
146
+ "R5","Mixed Vegetable Fried Rice"
147
+ "R6","Vegan Chicken and Pineapple Fried Rice"
148
+ "R8","Vegan Beef Fried Rice"
149
+ "R9","Chao-Style Fried Rice"
150
+ "R10","Crispy Dry Soy Seaweed Fried Rice"
151
+ "R11","Mixed Vegetable and Tofu Pan Fried Noodle"
152
+ "R12","Pan Fried Noodle with Tofu and Curry Sauce"
153
+ "R13","Mixed Vegetable Pan Fried Noodle"
154
+ "R14","Vegan Pork and Cabbage Pan Fried Noodle"
155
+ "R15","Vegan Pork Chow Mein"
156
+ "R16","Vegetable Chow Mein"
157
+ "R17","Soy Sauce Chow Mein"
158
+ "R18","Vegan Pork and Rice Noodle in Preserved Vegetable Soup"
159
+ "R19","Wonton Soup with Noodle"
160
+ "R20","Vegetable Noodle Soup"
161
+ "R21","Vegan Beef Chow Fun"
162
+ "R22","Chinese Broccoli Basil Chow Fun"
163
+ "R23","Vegan Beef with Black Pepper Sauce Over Chow Fun"
164
+ "R24","Vegan Beef with Black Bean Sauce Over Chow Fun"
165
+ "R25","Malaysian-Style Chow Fun"
166
+ "R26","Singaporean-Style Rice Noodle"
167
+ "R28","Rice Noodle with Vegan Pork and Preserved Vegetable"
168
+ "R29","Chao-Style Rice Noodle"
169
+ "R30","Braised Noodle"
170
+ "R32","Mapo Tofu Over Noodle"
171
+ "R34","Plain Steamed Rice"
172
+ "R35","Brown Steamed Rice"
173
+ "S1","Vegan Shark's Fin Soup"
174
+ "S3","Vegan Shark's Fin with Bamboo Fungus Soup"
175
+ "S4","Snow Mushroom Soup"
176
+ "S6","Corn Tofu Soup"
177
+ "S7","Seaweed and Tofu Soup"
178
+ "S8","Hot and Sour Soup"
179
+ "S9","Wonton Soup"
180
+ "S12","Sizzling Rice and Vegetable Soup"
181
+ "SP1","Fresh Bean Curd Skin with Vegetable"
182
+ "C1","Vegan BBQ Bun (cold item - steam at home)"
183
+ "SP2","Mixed Vegetables and Avocado with Black Pepper"
184
+ "C2","Steamed Dumplings (cold item - steam at home)"
185
+ "C3","Pan Fried Turnip Cake"
186
+ "SP3","Double Mushroom with Vegetable"
187
+ "SP5","Lemon Grass Bean Curd Roll with Lemon"
188
+ "C5","Sesame Ball"
189
+ "SP7","Pan Fried Bean Curd Roll"
190
+ "SP8","Avocado with Tofu"
191
+ "SP11","Tofu with Toons"
192
+ "SP13","Toons Pan Cake"
193
+ "SP16","House Assorted Platter"
194
+ "C18","Happy Ball"
195
+ "A19","Homemade Hot Sauce (Chili Oil) - 1 Jar"
196
+ "SP19","Fresh Mushroom with Vegan Sea Cucumber"
197
+ "SP20","Pinenuts with Toons Fried Rice"
198
+ "SP27","Fried Turnip Ball"
199
+ "SP28","Fried Curd"
200
+ "SP30","Stuffed Eggplant"
201
+ "SP31","Black Pepper Vegan Chicken Roll"
202
+ "SP32","Crispy Vegan Chicken with Mixed Nuts"
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ chromadb
3
+ sentence-transformers