Rammohan0504 commited on
Commit
c865f59
·
verified ·
1 Parent(s): e6da0b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +170 -88
app.py CHANGED
@@ -1,8 +1,5 @@
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",
8
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
@@ -15,107 +12,192 @@ menu_data = [
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="addItemToCart('{dish['name']}')" 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
- async function addItemToCart(itemName) {
61
- try {
62
- const response = await fetch("/add_to_cart", {
63
- method: "POST",
64
- headers: { "Content-Type": "application/json" },
65
- body: JSON.stringify({ item_name: itemName })
66
- });
67
- const result = await response.json();
68
-
69
- if (result.status === "success") {
70
- alert(result.message); // Show success message
71
- } else {
72
- alert("Error: " + result.message); // Show error message
73
- }
74
- } catch (error) {
75
- console.error("Error:", error);
76
- alert("Something went wrong!");
77
- }
78
- }
79
- </script>
80
- """
81
-
82
- # Main Gradio app
83
  with gr.Blocks() as demo:
84
- gr.HTML("<h1 style='text-align: center;'>🍛 Welcome to the Biryani Hub 🍛</h1>")
85
- gr.HTML(popup_js) # Add JavaScript for handling interactions
86
 
87
- # Tabs for Menu and Cart
88
- with gr.Tabs():
89
- # Menu Tab
90
- with gr.Tab("Menu"):
91
- with gr.Row():
92
- btn_all = gr.Button("ALL")
93
- btn_vegan = gr.Button("VEGAN")
94
- btn_halal = gr.Button("HALAL")
95
 
96
- dish_display = gr.HTML(value=display_dishes("ALL"))
 
 
 
 
97
 
98
- btn_all.click(
99
- lambda: display_dishes("ALL"),
100
- outputs=dish_display
101
- )
102
- btn_vegan.click(
103
- lambda: display_dishes("VEGAN"),
104
- outputs=dish_display
105
- )
106
- btn_halal.click(
107
- lambda: display_dishes("HALAL"),
108
- outputs=dish_display
109
- )
110
 
111
- # Cart Tab
112
- with gr.Tab("Cart"):
113
- cart_display = gr.HTML(value=display_cart())
114
- refresh_cart_btn = gr.Button("Refresh Cart")
115
- refresh_cart_btn.click(
116
- lambda: display_cart(),
117
- outputs=cart_display
118
- )
 
 
 
 
 
119
 
120
- # Launch Gradio app
121
- demo.launch()
 
1
  import gradio as gr
2
 
 
 
 
3
  menu_data = [
4
  {"name": "Veg Burger", "category": "VEGAN",
5
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
 
12
  {"name": "Paneer Butter Masala", "category": "VEGAN",
13
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg",
14
  "description": "Paneer cooked in a rich and creamy tomato-based gravy.",
15
+ "price": "$10.99"},
16
+ {"name": "Beef Steak", "category": "HALAL",
17
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/beef_steak.jpg",
18
+ "description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
19
+ "price": "$15.99"},
20
+ {"name": "Mushroom Soup", "category": "VEGAN",
21
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mushroom_soup.jpg",
22
+ "description": "Creamy mushroom soup with fresh herbs.",
23
+ "price": "$7.99"},
24
+ {"name": "Tandoori Chicken", "category": "HALAL",
25
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/tandoori_chicken.jpg",
26
+ "description": "Grilled chicken marinated in yogurt and spices, cooked in a tandoor.",
27
+ "price": "$11.99"},
28
+ {"name": "Grilled Veggies", "category": "VEGAN",
29
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/grilled_veggies.jpg",
30
+ "description": "A healthy mix of grilled seasonal vegetables with olive oil.",
31
+ "price": "$9.99"},
32
+ {"name": "Butter Naan", "category": "VEGAN",
33
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/butter_naan.jpg",
34
+ "description": "Soft and buttery flatbread, perfect to pair with any curry.",
35
+ "price": "$2.99"},
36
+ {"name": "Fish Curry", "category": "HALAL",
37
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/fish_curry.jpg",
38
+ "description": "Fresh fish cooked in a spicy and tangy curry.",
39
+ "price": "$13.99"},
40
+ {"name": "Vegetable Salad", "category": "VEGAN",
41
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/vegetable_salad.jpg",
42
+ "description": "A mix of fresh greens, tomatoes, cucumbers, and a light dressing.",
43
+ "price": "$6.99"},
44
+ {"name": "Veg Spring Rolls", "category": "VEGAN",
45
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_spring_rolls.jpg",
46
+ "description": "Crispy spring rolls filled with fresh vegetables.",
47
+ "price": "$5.99"},
48
+ {"name": "Chicken Kebab", "category": "HALAL",
49
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_kebab.jpg",
50
+ "description": "Juicy chicken kebabs grilled to perfection with a mix of spices.",
51
+ "price": "$9.99"},
52
+ {"name": "Dal Makhani", "category": "VEGAN",
53
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/dal_makhani.jpg",
54
+ "description": "Rich and creamy black lentils slow-cooked with spices.",
55
+ "price": "$8.99"},
56
+ {"name": "Lamb Curry", "category": "HALAL",
57
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/lamb_curry.jpg",
58
+ "description": "Tender lamb pieces cooked in a flavorful curry sauce.",
59
+ "price": "$14.99"},
60
+ {"name": "Mixed Veg Curry", "category": "VEGAN",
61
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mixed_veg_curry.jpg",
62
+ "description": "A medley of fresh vegetables cooked in a lightly spiced curry.",
63
+ "price": "$9.99"},
64
+ {"name": "Chicken Wings", "category": "HALAL",
65
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_wings.jpg",
66
+ "description": "Crispy chicken wings tossed in a tangy sauce.",
67
+ "price": "$12.99"},
68
+ {"name": "Aloo Paratha", "category": "VEGAN",
69
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/aloo_paratha.jpg",
70
+ "description": "Indian flatbread stuffed with spiced mashed potatoes.",
71
+ "price": "$3.99"},
72
+ {"name": "Egg Curry", "category": "HALAL",
73
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/egg_curry.jpg",
74
+ "description": "Boiled eggs cooked in a spiced tomato gravy.",
75
+ "price": "$9.99"},
76
+ {"name": "Chickpea Salad", "category": "VEGAN",
77
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chickpea_salad.jpg",
78
+ "description": "A refreshing salad made with chickpeas, fresh vegetables, and herbs.",
79
+ "price": "$7.99"}
80
  ]
81
 
 
 
 
 
82
 
 
 
 
 
 
 
 
 
 
83
 
84
+
85
+ # Spice levels and extras
86
+ spice_levels = ["American Mild", "American Medium", "American Spicy",
87
+ "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
88
+ extras = [
89
+ {"name": "Extra Raitha 4oz", "price": "$1.00"},
90
+ {"name": "Extra Raitha 8oz", "price": "$2.00"},
91
+ {"name": "Extra Onion", "price": "$1.00"},
92
+ {"name": "Extra Onion & Lemon", "price": "$2.00"}
93
+ ]
94
+
95
+ # JavaScript for popup modal
96
+ popup_js = """
97
+ <script>
98
+ function showPopup(name, description, price, image) {
99
+ const popup = document.getElementById("custom-popup");
100
+ const overlay = document.getElementById("overlay");
101
+ popup.innerHTML =
102
+ <img src="${image}" alt="${name}" style="width: 100%; height: 250px; border-radius: 10px; margin-bottom: 10px;">
103
+ <h3 style="margin-top: 10px;">${name}</h3>
104
+ <p>${description}</p>
105
+ <p style="font-weight: bold;">Price: ${price}</p>
106
+
107
+ <h4 style="margin-top: 20px;">Choose a Spice Level</h4>
108
+ <div style="display: flex; flex-wrap: wrap; gap: 10px;">
109
+ ${["American Mild", "American Medium", "American Spicy", "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"].map(spice =>
110
+ <label style="margin-right: 10px;">
111
+ <input type="radio" name="spice" value="${spice}"> ${spice}
112
+ </label>
113
+ ).join("")}
114
+ </div>
115
+
116
+ <h4 style="margin-top: 20px;">Choose Extras</h4>
117
+ <div style="display: flex; flex-wrap: wrap; gap: 10px;">
118
+ ${["Extra Raitha 4oz + $1.00", "Extra Raitha 8oz + $2.00", "Extra Onion + $1.00", "Extra Onion & Lemon + $2.00"].map(extra =>
119
+ <label style="margin-right: 10px;">
120
+ <input type="checkbox" name="extras" value="${extra}"> ${extra}
121
+ </label>
122
+ ).join("")}
123
+ </div>
124
+
125
+ <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>
126
+ <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>
127
+ ;
128
+ popup.style.display = "block";
129
+ overlay.style.display = "block";
130
+ }
131
+
132
+ function closePopup() {
133
+ const popup = document.getElementById("custom-popup");
134
+ const overlay = document.getElementById("overlay");
135
+ popup.style.display = "none";
136
+ overlay.style.display = "none";
137
+ }
138
+ </script>
139
+ """
140
+
141
+ # HTML for popup modal
142
+ popup_html = """
143
+ <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>
144
+ <div id="custom-popup"
145
+ 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;">
146
+ </div>
147
+ """
148
+
149
+ # Generate dish cards
150
  def display_dishes(category):
151
+ html_content = "<div style='display: flex; flex-direction: column; gap: 20px; width: 80%; margin: 0 auto;'>"
152
  for dish in menu_data:
153
  if category == "ALL" or dish["category"] == category:
154
  html_content += f"""
155
+ <div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'>
156
+ <div style='flex: 3; text-align: left;'>
157
+ <h3 style='margin: 0; font-size: 20px;'>{dish['name']}</h3>
158
+ <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
159
+ <p style='margin: 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
160
+ </div>
161
+ <div style='flex: 1; text-align: center;'>
162
+ <img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'>
163
+ <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"
164
+ style='margin-top: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>
165
+ Add
166
+ </button>
167
+ </div>
168
  </div>
169
  """
170
  html_content += "</div>"
171
  return html_content
172
 
173
+ # Main Gradio App
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  with gr.Blocks() as demo:
175
+ gr.HTML(popup_html) # Add the popup container and overlay
176
+ gr.HTML(popup_js) # Add the JavaScript
177
 
178
+ gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")
 
 
 
 
 
 
 
179
 
180
+ # Buttons for filtering categories
181
+ with gr.Row():
182
+ btn_all = gr.Button("ALL")
183
+ btn_vegan = gr.Button("VEGAN")
184
+ btn_halal = gr.Button("HALAL")
185
 
186
+ # Dish display
187
+ dish_display = gr.HTML(value=display_dishes("ALL"))
 
 
 
 
 
 
 
 
 
 
188
 
189
+ # Button click events
190
+ btn_all.click(
191
+ lambda: gr.update(value=display_dishes("ALL")),
192
+ outputs=dish_display
193
+ )
194
+ btn_vegan.click(
195
+ lambda: gr.update(value=display_dishes("VEGAN")),
196
+ outputs=dish_display
197
+ )
198
+ btn_halal.click(
199
+ lambda: gr.update(value=display_dishes("HALAL")),
200
+ outputs=dish_display
201
+ )
202
 
203
+ demo.launch()