Rammohan0504 commited on
Commit
02720f4
·
verified ·
1 Parent(s): ac70e91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -117
app.py CHANGED
@@ -10,88 +10,19 @@ menu_data = [
10
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg",
11
  "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
12
  "price": "$12.99"},
13
- {"name": "Paneer Butter Masala", "category": "VEGAN",
14
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg",
15
- "description": "Paneer cooked in a rich and creamy tomato-based gravy.",
16
- "price": "$10.99"},
17
- {"name": "Beef Steak", "category": "HALAL",
18
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/beef_steak.jpg",
19
- "description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
20
- "price": "$15.99"},
21
- {"name": "Mushroom Soup", "category": "VEGAN",
22
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mushroom_soup.jpg",
23
- "description": "Creamy mushroom soup with fresh herbs.",
24
- "price": "$7.99"},
25
- {"name": "Tandoori Chicken", "category": "HALAL",
26
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/tandoori_chicken.jpg",
27
- "description": "Grilled chicken marinated in yogurt and spices, cooked in a tandoor.",
28
- "price": "$11.99"},
29
- {"name": "Grilled Veggies", "category": "VEGAN",
30
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/grilled_veggies.jpg",
31
- "description": "A healthy mix of grilled seasonal vegetables with olive oil.",
32
- "price": "$9.99"},
33
- {"name": "Butter Naan", "category": "VEGAN",
34
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/butter_naan.jpg",
35
- "description": "Soft and buttery flatbread, perfect to pair with any curry.",
36
- "price": "$2.99"},
37
- {"name": "Fish Curry", "category": "HALAL",
38
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/fish_curry.jpg",
39
- "description": "Fresh fish cooked in a spicy and tangy curry.",
40
- "price": "$13.99"},
41
- {"name": "Vegetable Salad", "category": "VEGAN",
42
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/vegetable_salad.jpg",
43
- "description": "A mix of fresh greens, tomatoes, cucumbers, and a light dressing.",
44
- "price": "$6.99"},
45
- {"name": "Veg Spring Rolls", "category": "VEGAN",
46
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_spring_rolls.jpg",
47
- "description": "Crispy spring rolls filled with fresh vegetables.",
48
- "price": "$5.99"},
49
- {"name": "Chicken Kebab", "category": "HALAL",
50
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_kebab.jpg",
51
- "description": "Juicy chicken kebabs grilled to perfection with a mix of spices.",
52
- "price": "$9.99"},
53
- {"name": "Dal Makhani", "category": "VEGAN",
54
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/dal_makhani.jpg",
55
- "description": "Rich and creamy black lentils slow-cooked with spices.",
56
- "price": "$8.99"},
57
- {"name": "Lamb Curry", "category": "HALAL",
58
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/lamb_curry.jpg",
59
- "description": "Tender lamb pieces cooked in a flavorful curry sauce.",
60
- "price": "$14.99"},
61
- {"name": "Mixed Veg Curry", "category": "VEGAN",
62
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mixed_veg_curry.jpg",
63
- "description": "A medley of fresh vegetables cooked in a lightly spiced curry.",
64
- "price": "$9.99"},
65
- {"name": "Chicken Wings", "category": "HALAL",
66
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_wings.jpg",
67
- "description": "Crispy chicken wings tossed in a tangy sauce.",
68
- "price": "$12.99"},
69
- {"name": "Aloo Paratha", "category": "VEGAN",
70
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/aloo_paratha.jpg",
71
- "description": "Indian flatbread stuffed with spiced mashed potatoes.",
72
- "price": "$3.99"},
73
- {"name": "Egg Curry", "category": "HALAL",
74
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/egg_curry.jpg",
75
- "description": "Boiled eggs cooked in a spiced tomato gravy.",
76
- "price": "$9.99"},
77
- {"name": "Chickpea Salad", "category": "VEGAN",
78
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chickpea_salad.jpg",
79
- "description": "A refreshing salad made with chickpeas, fresh vegetables, and herbs.",
80
- "price": "$7.99"}
81
  ]
82
 
 
 
83
 
84
  # Spice levels and extras
85
  spice_levels = ["American Mild", "American Medium", "American Spicy",
86
  "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
87
  extras = [
88
  {"name": "Extra Raitha 4oz", "price": "$1.00"},
89
- {"name": "Extra Raitha 8oz", "price": "$2.00"},
90
- {"name": "Extra Salan 4oz", "price": "$1.00"},
91
  {"name": "Extra Salan 8oz", "price": "$2.00"},
92
- {"name": "Extra Onion", "price": "$1.00"},
93
- {"name": "Extra Onion & Lemon", "price": "$2.00"},
94
- {"name": "Extra Fried Onion 4oz", "price": "$2.00"},
95
  ]
96
 
97
  # Filter dishes by category
@@ -117,7 +48,7 @@ def display_dishes(category):
117
  <div style='text-align: center;'>
118
  <img src='{dish['image']}' alt='{dish['name']}'
119
  style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
120
- <button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')"
121
  style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
122
  border-radius: 5px; cursor: pointer;">Add</button>
123
  </div>
@@ -126,77 +57,76 @@ def display_dishes(category):
126
  html_content += "</div>"
127
  return html_content
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  # Main Gradio App
130
  with gr.Blocks() as demo:
131
- gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
132
 
133
- # Buttons for category selection
134
- with gr.Row():
135
- btn_all = gr.Button("ALL")
136
- btn_vegan = gr.Button("VEGAN")
137
- btn_halal = gr.Button("HALAL")
 
 
138
 
139
- # Dish display
140
- dish_display = gr.HTML(value=display_dishes("ALL"))
141
 
142
  # JavaScript for managing the pop-up
143
  gr.HTML(f"""
144
  <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
145
  background-color: white; padding: 20px; border-radius: 10px;
146
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
147
- <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
148
  <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
149
  <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
150
  <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
151
-
152
  <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
153
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
154
- """ + "".join([f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>' for spice in spice_levels]) + """
155
  </div>
156
-
157
  <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
158
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
159
- """ + "".join([f'<label style="margin-right: 10px; display: block;"><input type="checkbox" name="extras" value="{extra["name"]}" style="margin-right: 5px;">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
160
  </div>
161
-
162
- <button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
163
- style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
164
- border-radius: 5px; cursor: pointer;">Add to Cart</button>
165
- <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
166
- color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
167
  </div>
168
  <script>
169
- function showPopup(image, title, description, price) {
170
- document.getElementById('popup-image').src = image;
171
  document.getElementById('popup-title').textContent = title;
172
  document.getElementById('popup-description').textContent = description;
173
- document.getElementById('popup-price').textContent = "Price: " + price;
174
-
175
- // Display the popup
176
  document.getElementById('popup').style.display = 'block';
177
  }
178
  function closePopup() {
179
  document.getElementById('popup').style.display = 'none';
180
  }
181
- function addToCart(dishName, spiceLevel) {
182
- const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
183
- alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
184
- }
185
  </script>
186
  """)
187
 
188
  # Button click events
189
- btn_all.click(
190
- lambda: gr.update(value=display_dishes("ALL")),
191
- outputs=dish_display
192
- )
193
- btn_vegan.click(
194
- lambda: gr.update(value=display_dishes("VEGAN")),
195
- outputs=dish_display
196
- )
197
- btn_halal.click(
198
- lambda: gr.update(value=display_dishes("HALAL")),
199
- outputs=dish_display
200
- )
201
 
202
- demo.launch()
 
10
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg",
11
  "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
12
  "price": "$12.99"},
13
+ # Add more dishes here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ]
15
 
16
+ # Cart data (persistent across sessions)
17
+ cart_items = []
18
 
19
  # Spice levels and extras
20
  spice_levels = ["American Mild", "American Medium", "American Spicy",
21
  "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
22
  extras = [
23
  {"name": "Extra Raitha 4oz", "price": "$1.00"},
 
 
24
  {"name": "Extra Salan 8oz", "price": "$2.00"},
25
+ # Add more extras here
 
 
26
  ]
27
 
28
  # Filter dishes by category
 
48
  <div style='text-align: center;'>
49
  <img src='{dish['image']}' alt='{dish['name']}'
50
  style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
51
+ <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}')"
52
  style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
53
  border-radius: 5px; cursor: pointer;">Add</button>
54
  </div>
 
57
  html_content += "</div>"
58
  return html_content
59
 
60
+ # Function to handle adding items to the cart
61
+ def add_to_cart(dish_name, spice_level, selected_extras):
62
+ cart_items.append({
63
+ "name": dish_name,
64
+ "spice_level": spice_level,
65
+ "extras": selected_extras
66
+ })
67
+ return update_cart()
68
+
69
+ # Update cart display
70
+ def update_cart():
71
+ if not cart_items:
72
+ return "<p>Your cart is empty.</p>"
73
+ html_content = "<h3>Cart Items</h3><ul>"
74
+ for item in cart_items:
75
+ extras = ", ".join(item["extras"])
76
+ html_content += f"<li>{item['name']} - Spice Level: {item['spice_level']}, Extras: {extras}</li>"
77
+ html_content += "</ul>"
78
+ return html_content
79
+
80
  # Main Gradio App
81
  with gr.Blocks() as demo:
82
+ gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Dynamic Menu with Cart 🍛</h1>")
83
 
84
+ with gr.Tabs():
85
+ with gr.Tab("Menu"):
86
+ with gr.Row():
87
+ btn_all = gr.Button("ALL")
88
+ btn_vegan = gr.Button("VEGAN")
89
+ btn_halal = gr.Button("HALAL")
90
+ dish_display = gr.HTML(value=display_dishes("ALL"))
91
 
92
+ with gr.Tab("Cart"):
93
+ cart_display = gr.HTML(value="<p>Your cart is empty.</p>")
94
 
95
  # JavaScript for managing the pop-up
96
  gr.HTML(f"""
97
  <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
98
  background-color: white; padding: 20px; border-radius: 10px;
99
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
 
100
  <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
101
  <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
102
  <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
 
103
  <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
104
+ <div style="display: flex; flex-wrap: wrap; justify-content: space-between;">
105
+ """ + "".join([f'<label><input type="radio" name="spice" value="{spice}">{spice}</label>' for spice in spice_levels]) + """
106
  </div>
 
107
  <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
108
+ <div style="display: flex; flex-wrap: wrap;">
109
+ """ + "".join([f'<label><input type="checkbox" name="extras" value="{extra["name"]}">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
110
  </div>
111
+ <button onclick="addToCart()" style="margin-top: 20px;">Add to Cart</button>
112
+ <button onclick="closePopup()">Close</button>
 
 
 
 
113
  </div>
114
  <script>
115
+ function showPopup(title, description, price) {
 
116
  document.getElementById('popup-title').textContent = title;
117
  document.getElementById('popup-description').textContent = description;
118
+ document.getElementById('popup-price').textContent = price;
 
 
119
  document.getElementById('popup').style.display = 'block';
120
  }
121
  function closePopup() {
122
  document.getElementById('popup').style.display = 'none';
123
  }
 
 
 
 
124
  </script>
125
  """)
126
 
127
  # Button click events
128
+ btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
129
+ btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
130
+ btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
 
 
 
 
 
 
 
 
 
131
 
132
+ demo.launch()