Rammohan0504 commited on
Commit
a1522b2
·
verified ·
1 Parent(s): 887eff2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -63
app.py CHANGED
@@ -14,10 +14,22 @@ menu_data = [
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": "Mushroom Soup", "category": "VEGAN",
18
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mushroom_soup.jpg",
19
  "description": "Creamy mushroom soup with fresh herbs.",
20
  "price": "$7.99"},
 
 
 
 
 
 
 
 
21
  {"name": "Butter Naan", "category": "VEGAN",
22
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/butter_naan.jpg",
23
  "description": "Soft and buttery flatbread, perfect to pair with any curry.",
@@ -26,10 +38,14 @@ menu_data = [
26
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/fish_curry.jpg",
27
  "description": "Fresh fish cooked in a spicy and tangy curry.",
28
  "price": "$13.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": "Chicken Kebab", "category": "HALAL",
34
  "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_kebab.jpg",
35
  "description": "Juicy chicken kebabs grilled to perfection with a mix of spices.",
@@ -64,19 +80,18 @@ menu_data = [
64
  "price": "$7.99"}
65
  ]
66
 
 
67
  # Spice levels and extras
68
  spice_levels = ["American Mild", "American Medium", "American Spicy",
69
  "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
70
  extras = [
71
  {"name": "Extra Raitha 4oz", "price": "$1.00"},
 
 
 
72
  {"name": "Extra Onion", "price": "$1.00"},
 
73
  {"name": "Extra Fried Onion 4oz", "price": "$2.00"},
74
- {"name": "Coke", "price": "$1.50"},
75
- {"name": "Pepsi", "price": "$1.50"},
76
- {"name": "Lemonade", "price": "$2.00"},
77
- {"name": "Spring Rolls", "price": "$4.99"},
78
- {"name": "Veg Samosa", "price": "$3.99"},
79
- {"name": "Masala Papad", "price": "$2.99"}
80
  ]
81
 
82
  # Filter dishes by category
@@ -89,9 +104,9 @@ def filter_dishes(category):
89
  def display_dishes(category):
90
  filtered_dishes = filter_dishes(category)
91
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"
92
- for idx, dish in enumerate(filtered_dishes):
93
  html_content += f"""
94
- <div id='dish-{idx}' style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
95
  width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
96
  background-color: #f9f9f9;'>
97
  <div style='flex: 1; margin-right: 20px; text-align: left;'>
@@ -102,9 +117,9 @@ def display_dishes(category):
102
  <div style='text-align: center;'>
103
  <img src='{dish['image']}' alt='{dish['name']}'
104
  style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
105
- <button onclick=\"showPopup('{idx}', '{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')\"
106
- style=\"margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
107
- border-radius: 5px; cursor: pointer;\">Add</button>
108
  </div>
109
  </div>
110
  """
@@ -113,7 +128,7 @@ def display_dishes(category):
113
 
114
  # Main Gradio App
115
  with gr.Blocks() as demo:
116
- gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Dynamic Menu with Pop-up 🍛</h1>")
117
 
118
  # Buttons for category selection
119
  with gr.Row():
@@ -125,55 +140,50 @@ with gr.Blocks() as demo:
125
  dish_display = gr.HTML(value=display_dishes("ALL"))
126
 
127
  # JavaScript for managing the pop-up
128
- gr.HTML("""
129
- <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
130
- background-color: white; padding: 20px; border-radius: 10px;
131
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
132
- <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
133
- <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
134
- <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
135
- <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
136
-
137
- <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
138
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
139
- """ + "".join([
140
- f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>'
141
- for spice in spice_levels]) + """
142
- </div>
143
-
144
- <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
145
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
146
- """ + "".join([
147
- 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>'
148
- for extra in extras]) + """
149
- </div>
150
 
151
- <button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
152
- style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
153
- border-radius: 5px; cursor: pointer;">Add to Cart</button>
154
- <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
155
- color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
156
- </div>
157
- <script>
158
- function showPopup(image, title, description, price) {
159
- document.getElementById('popup-image').src = image;
160
- document.getElementById('popup-title').textContent = title;
161
- document.getElementById('popup-description').textContent = description;
162
- document.getElementById('popup-price').textContent = "Price: " + price;
163
 
164
- // Display the popup
165
- document.getElementById('popup').style.display = 'block';
166
- }
167
- function closePopup() {
168
- document.getElementById('popup').style.display = 'none';
169
- }
170
- function addToCart(dishName, spiceLevel) {
171
- const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
172
- alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
173
- }
174
- </script>
175
- """)
176
 
 
 
 
 
 
 
 
 
 
 
 
 
177
 
178
  # Button click events
179
  btn_all.click(
@@ -189,4 +199,4 @@ with gr.Blocks() as demo:
189
  outputs=dish_display
190
  )
191
 
192
- demo.launch()
 
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.",
 
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.",
 
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
 
104
  def display_dishes(category):
105
  filtered_dishes = filter_dishes(category)
106
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"
107
+ for dish in filtered_dishes:
108
  html_content += f"""
109
+ <div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
110
  width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
111
  background-color: #f9f9f9;'>
112
  <div style='flex: 1; margin-right: 20px; text-align: left;'>
 
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>
124
  </div>
125
  """
 
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():
 
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(
 
199
  outputs=dish_display
200
  )
201
 
202
+ demo.launch()