Rammohan0504 commited on
Commit
261a3f3
·
verified ·
1 Parent(s): a294a10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +112 -162
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,121 +15,85 @@ 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
- # JavaScript for popup modal
97
  popup_js = """
98
  <script>
99
  function showPopup(name, description, price, image) {
100
  const popup = document.getElementById("custom-popup");
101
  const overlay = document.getElementById("overlay");
102
- popup.innerHTML =
103
- <img src="${image}" alt="${name}" style="width: 100%; height: 250px; border-radius: 10px; margin-bottom: 10px;">
104
- <h3 style="margin-top: 10px;">${name}</h3>
 
105
  <p>${description}</p>
106
  <p style="font-weight: bold;">Price: ${price}</p>
107
-
108
- <h4 style="margin-top: 20px;">Choose a Spice Level</h4>
109
- <div style="display: flex; flex-wrap: wrap; gap: 10px;">
110
- ${["American Mild", "American Medium", "American Spicy", "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"].map(spice =>
111
- <label style="margin-right: 10px;">
112
- <input type="radio" name="spice" value="${spice}"> ${spice}
113
- </label>
114
- ).join("")}
115
- </div>
116
-
117
- <h4 style="margin-top: 20px;">Choose Extras</h4>
118
- <div style="display: flex; flex-wrap: wrap; gap: 10px;">
119
- ${["Extra Raitha 4oz + $1.00", "Extra Raitha 8oz + $2.00", "Extra Onion + $1.00", "Extra Onion & Lemon + $2.00"].map(extra =>
120
- <label style="margin-right: 10px;">
121
- <input type="checkbox" name="extras" value="${extra}"> ${extra}
122
- </label>
123
- ).join("")}
124
- </div>
125
-
126
- <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>
127
- <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>
128
- ;
129
  popup.style.display = "block";
130
  overlay.style.display = "block";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
132
 
133
  function closePopup() {
@@ -139,68 +105,52 @@ popup_js = """
139
  </script>
140
  """
141
 
142
- # HTML for popup modal
143
  popup_html = """
144
  <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>
145
  <div id="custom-popup"
146
- 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;">
147
  </div>
148
  """
149
 
150
- # Generate dish cards
151
- def display_dishes(category):
152
- html_content = "<div style='display: flex; flex-direction: column; gap: 20px; width: 80%; margin: 0 auto;'>"
153
- for dish in menu_data:
154
- if category == "ALL" or dish["category"] == category:
155
- html_content += f"""
156
- <div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'>
157
- <div style='flex: 3; text-align: left;'>
158
- <h3 style='margin: 0; font-size: 20px;'>{dish['name']}</h3>
159
- <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
160
- <p style='margin: 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
161
- </div>
162
- <div style='flex: 1; text-align: center;'>
163
- <img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'>
164
- <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"
165
- style='margin-top: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>
166
- Add
167
- </button>
168
- </div>
169
- </div>
170
- """
171
- html_content += "</div>"
172
- return html_content
173
-
174
-
175
-
176
- # Main Gradio App
177
  with gr.Blocks() as demo:
178
- gr.HTML(popup_html) # Add the popup container and overlay
179
- gr.HTML(popup_js) # Add the JavaScript
180
-
181
- gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")
182
-
183
- # Buttons for filtering categories
184
- with gr.Row():
185
- btn_all = gr.Button("ALL")
186
- btn_vegan = gr.Button("VEGAN")
187
- btn_halal = gr.Button("HALAL")
188
-
189
- # Dish display
190
- dish_display = gr.HTML(value=display_dishes("ALL"))
191
-
192
- # Button click events
193
- btn_all.click(
194
- lambda: gr.update(value=display_dishes("ALL")),
195
- outputs=dish_display
196
- )
197
- btn_vegan.click(
198
- lambda: gr.update(value=display_dishes("VEGAN")),
199
- outputs=dish_display
200
- )
201
- btn_halal.click(
202
- lambda: gr.update(value=display_dishes("HALAL")),
203
- outputs=dish_display
204
- )
205
-
206
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
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 {"status": "success", "message": f"'{item_name}' has been added to your 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 onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')" style='padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>
50
+ Add to Cart
51
+ </button>
52
+ </div>
53
+ """
54
+ html_content += "</div>"
55
+ return html_content
56
 
57
+ # JavaScript for Popup Handling
 
 
 
 
 
 
 
 
 
 
 
 
58
  popup_js = """
59
  <script>
60
  function showPopup(name, description, price, image) {
61
  const popup = document.getElementById("custom-popup");
62
  const overlay = document.getElementById("overlay");
63
+ popup.innerHTML = `
64
+ <button onclick="closePopup()" style="position: absolute; top: 10px; right: 10px; background: none; border: none; font-size: 20px; cursor: pointer;">&times;</button>
65
+ <img src="${image}" alt="${name}" style="width: 100%; height: 200px; object-fit: cover; border-radius: 10px; margin-bottom: 10px;">
66
+ <h3>${name}</h3>
67
  <p>${description}</p>
68
  <p style="font-weight: bold;">Price: ${price}</p>
69
+ <button id="add-to-cart-button" style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">
70
+ Add to Cart
71
+ </button>
72
+ `;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  popup.style.display = "block";
74
  overlay.style.display = "block";
75
+
76
+ document.getElementById("add-to-cart-button").onclick = async function () {
77
+ try {
78
+ const response = await fetch("/add_to_cart", {
79
+ method: "POST",
80
+ headers: { "Content-Type": "application/json" },
81
+ body: JSON.stringify({ item_name: name })
82
+ });
83
+ const result = await response.json();
84
+
85
+ if (result.status === "success") {
86
+ alert(result.message); // Show success message
87
+ } else {
88
+ alert("Error: " + result.message); // Show error message
89
+ }
90
+ } catch (error) {
91
+ console.error("Error:", error);
92
+ alert("Something went wrong!");
93
+ }
94
+
95
+ closePopup();
96
+ };
97
  }
98
 
99
  function closePopup() {
 
105
  </script>
106
  """
107
 
108
+ # HTML for the Popup Container
109
  popup_html = """
110
  <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>
111
  <div id="custom-popup"
112
+ 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; position: relative;">
113
  </div>
114
  """
115
 
116
+ # Main Gradio app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  with gr.Blocks() as demo:
118
+ gr.HTML("<h1 style='text-align: center;'>🍛 Welcome to the Biryani Hub 🍛</h1>")
119
+ gr.HTML(popup_html) # Add HTML for the popup
120
+ gr.HTML(popup_js) # Add JavaScript for handling interactions
121
+
122
+ # Tabs for Menu and Cart
123
+ with gr.Tabs():
124
+ # Menu Tab
125
+ with gr.Tab("Menu"):
126
+ with gr.Row():
127
+ btn_all = gr.Button("ALL")
128
+ btn_vegan = gr.Button("VEGAN")
129
+ btn_halal = gr.Button("HALAL")
130
+
131
+ dish_display = gr.HTML(value=display_dishes("ALL"))
132
+
133
+ btn_all.click(
134
+ lambda: display_dishes("ALL"),
135
+ outputs=dish_display
136
+ )
137
+ btn_vegan.click(
138
+ lambda: display_dishes("VEGAN"),
139
+ outputs=dish_display
140
+ )
141
+ btn_halal.click(
142
+ lambda: display_dishes("HALAL"),
143
+ outputs=dish_display
144
+ )
145
+
146
+ # Cart Tab
147
+ with gr.Tab("Cart"):
148
+ cart_display = gr.HTML(value=display_cart())
149
+ refresh_cart_btn = gr.Button("Refresh Cart")
150
+ refresh_cart_btn.click(
151
+ lambda: display_cart(),
152
+ outputs=cart_display
153
+ )
154
+
155
+ # Launch Gradio app
156
+ demo.launch()