Rammohan0504 commited on
Commit
4bd3719
·
verified ·
1 Parent(s): d9d8e89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -145
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
- from cart_tab import add_to_cart, display_cart
 
 
3
 
4
  menu_data = [
5
  {"name": "Veg Burger", "category": "VEGAN",
@@ -13,189 +15,94 @@ menu_data = [
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
-
85
-
86
- # Spice levels and extras
87
- spice_levels = ["American Mild", "American Medium", "American Spicy",
88
- "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
89
- extras = [
90
- {"name": "Extra Raitha 4oz", "price": "$1.00"},
91
- {"name": "Extra Raitha 8oz", "price": "$2.00"},
92
- {"name": "Extra Onion", "price": "$1.00"},
93
- {"name": "Extra Onion & Lemon", "price": "$2.00"}
94
  ]
95
 
96
-
97
-
98
- # Global cart variable
99
- cart = []
100
-
101
-
102
- def add_to_cart(item_name, spice_level=None, extras=None):
103
- """Add selected item to cart."""
104
- cart.append({"item_name": item_name, "spice_level": spice_level, "extras": extras or []})
105
  return f"{item_name} added to cart!"
106
 
107
-
108
  def display_cart():
109
- """Return the current cart contents."""
110
  if not cart:
111
  return "Your cart is empty."
112
  cart_content = "<h3>Your Cart:</h3><ul>"
113
  for item in cart:
114
- extras = ', '.join(item['extras']) if item['extras'] else "No extras"
115
- cart_content += f"<li>{item['item_name']} - Spice: {item['spice_level'] or 'Default'} - Extras: {extras}</li>"
116
  cart_content += "</ul>"
117
  return cart_content
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
- # JavaScript for popup modal
121
  popup_js = """
122
  <script>
123
  function showPopup(name, description, price, image) {
124
  const popup = document.getElementById("custom-popup");
125
  const overlay = document.getElementById("overlay");
126
  popup.innerHTML = `
127
- <img src="${image}" alt="${name}" style="width: 100%; height: 250px; border-radius: 10px; margin-bottom: 10px;">
128
- <h3 style="margin-top: 10px;">${name}</h3>
129
  <p>${description}</p>
130
  <p style="font-weight: bold;">Price: ${price}</p>
131
-
132
- <h4 style="margin-top: 20px;">Choose a Spice Level</h4>
133
- <div style="display: flex; flex-wrap: wrap; gap: 10px;">
134
- ${["American Mild", "American Medium", "American Spicy", "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"].map(spice => `
135
- <label style="margin-right: 10px;">
136
- <input type="radio" name="spice" value="${spice}"> ${spice}
137
- </label>
138
- `).join("")}
139
- </div>
140
-
141
- <h4 style="margin-top: 20px;">Choose Extras</h4>
142
- <div style="display: flex; flex-wrap: wrap; gap: 10px;">
143
- ${["Extra Raitha 4oz + $1.00", "Extra Raitha 8oz + $2.00", "Extra Onion + $1.00", "Extra Onion & Lemon + $2.00"].map(extra => `
144
- <label style="margin-right: 10px;">
145
- <input type="checkbox" name="extras" value="${extra}"> ${extra}
146
- </label>
147
- `).join("")}
148
- </div>
149
-
150
- <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>
151
- <button onclick="closePopup()" style="margin-top: 20px; margin-left: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
152
  `;
153
  popup.style.display = "block";
154
  overlay.style.display = "block";
155
  }
156
 
157
  function closePopup() {
158
- const popup = document.getElementById("custom-popup");
159
- const overlay = document.getElementById("overlay");
160
- popup.style.display = "none";
161
- overlay.style.display = "none";
 
 
 
162
  }
163
  </script>
164
  """
165
 
166
- # HTML for popup modal
167
  popup_html = """
168
  <div id="overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; z-index: 999;"></div>
169
  <div id="custom-popup"
170
- style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 50%; max-width: 400px; background: white; padding: 20px; border-radius: 10px; box-shadow: 0px 4px 6px rgba(0,0,0,0.1); display: none; z-index: 1000; text-align: center;">
171
  </div>
172
  """
173
 
174
- def display_dishes(category):
175
- """Render dishes dynamically based on the selected category."""
176
- html_content = "<div style='display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;'>"
177
- for dish in menu_data:
178
- if category == "ALL" or dish["category"] == category:
179
- html_content += f"""
180
- <div style='flex: 1 1 calc(30% - 20px); display: flex; flex-direction: column; align-items: center;
181
- justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px;
182
- background-color: #f9f9f9; box-shadow: 0 4px 8px rgba(0,0,0,0.1);'>
183
- <img src='{dish['image']}' alt='{dish['name']}' style='width: 100%; height: 150px; object-fit: cover; border-radius: 10px;'>
184
- <h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3>
185
- <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
186
- <p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
187
- <button style='padding: 10px 20px; background-color: #28a745; color: white; border: none;
188
- border-radius: 5px; cursor: pointer;'
189
- onclick="addToCart('{dish['name']}')">Add to Cart</button>
190
- </div>
191
- """
192
- html_content += "</div>"
193
- return html_content
194
-
195
-
196
-
197
  # Main Gradio App
198
  with gr.Blocks() as demo:
 
 
 
199
  gr.HTML("<h1 style='text-align: center;'>🍛 Welcome to the Biryani Hub 🍛</h1>")
200
 
201
  with gr.Tabs():
 
1
  import gradio as gr
2
+
3
+ # Global variables for cart and menu data
4
+ cart = []
5
 
6
  menu_data = [
7
  {"name": "Veg Burger", "category": "VEGAN",
 
15
  {"name": "Paneer Butter Masala", "category": "VEGAN",
16
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg",
17
  "description": "Paneer cooked in a rich and creamy tomato-based gravy.",
18
+ "price": "$10.99"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  ]
20
 
21
+ # Function to add an item to the cart
22
+ def add_to_cart(item_name):
23
+ cart.append({"item_name": item_name})
 
 
 
 
 
 
24
  return f"{item_name} added to cart!"
25
 
26
+ # Function to display the current cart
27
  def display_cart():
 
28
  if not cart:
29
  return "Your cart is empty."
30
  cart_content = "<h3>Your Cart:</h3><ul>"
31
  for item in cart:
32
+ cart_content += f"<li>{item['item_name']}</li>"
 
33
  cart_content += "</ul>"
34
  return cart_content
35
 
36
+ # Function to generate dish cards
37
+ def display_dishes(category):
38
+ html_content = "<div style='display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;'>"
39
+ for dish in menu_data:
40
+ if category == "ALL" or dish["category"] == category:
41
+ html_content += f"""
42
+ <div style='flex: 1 1 calc(30% - 20px); display: flex; flex-direction: column; align-items: center;
43
+ justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px;
44
+ background-color: #f9f9f9; box-shadow: 0 4px 8px rgba(0,0,0,0.1);'>
45
+ <img src='{dish['image']}' alt='{dish['name']}' style='width: 100%; height: 150px; object-fit: cover; border-radius: 10px;'>
46
+ <h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3>
47
+ <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
48
+ <p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
49
+ <button style='padding: 10px 20px; background-color: #28a745; color: white; border: none;
50
+ border-radius: 5px; cursor: pointer;'
51
+ onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')">
52
+ Add to Cart
53
+ </button>
54
+ </div>
55
+ """
56
+ html_content += "</div>"
57
+ return html_content
58
 
59
+ # Popup JavaScript for handling the modal
60
  popup_js = """
61
  <script>
62
  function showPopup(name, description, price, image) {
63
  const popup = document.getElementById("custom-popup");
64
  const overlay = document.getElementById("overlay");
65
  popup.innerHTML = `
66
+ <img src="${image}" alt="${name}" style="width: 100%; height: 200px; object-fit: cover; border-radius: 10px; margin-bottom: 10px;">
67
+ <h3>${name}</h3>
68
  <p>${description}</p>
69
  <p style="font-weight: bold;">Price: ${price}</p>
70
+ <button onclick="addToCart('${name}')" style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">
71
+ Add to Cart
72
+ </button>
73
+ <button onclick="closePopup()" style="padding: 10px 20px; background-color: #dc3545; color: white; border: none; border-radius: 5px; cursor: pointer; margin-left: 10px;">
74
+ Close
75
+ </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  `;
77
  popup.style.display = "block";
78
  overlay.style.display = "block";
79
  }
80
 
81
  function closePopup() {
82
+ document.getElementById("custom-popup").style.display = "none";
83
+ document.getElementById("overlay").style.display = "none";
84
+ }
85
+
86
+ function addToCart(name) {
87
+ google.colab.kernel.invokeFunction('notebook.add_to_cart', [name], {});
88
+ closePopup();
89
  }
90
  </script>
91
  """
92
 
93
+ # Popup HTML structure
94
  popup_html = """
95
  <div id="overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; z-index: 999;"></div>
96
  <div id="custom-popup"
97
+ style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 400px; max-width: 90%; background: white; padding: 20px; border-radius: 10px; box-shadow: 0px 4px 6px rgba(0,0,0,0.1); display: none; z-index: 1000;">
98
  </div>
99
  """
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  # Main Gradio App
102
  with gr.Blocks() as demo:
103
+ gr.HTML(popup_html) # Add popup container
104
+ gr.HTML(popup_js) # Add popup JavaScript
105
+
106
  gr.HTML("<h1 style='text-align: center;'>🍛 Welcome to the Biryani Hub 🍛</h1>")
107
 
108
  with gr.Tabs():