Rammohan0504 commited on
Commit
e58e9c4
·
verified ·
1 Parent(s): f916939

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -52
app.py CHANGED
@@ -14,22 +14,10 @@ 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": "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,14 +26,10 @@ menu_data = [
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,18 +64,19 @@ menu_data = [
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,9 +89,9 @@ def filter_dishes(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,9 +102,9 @@ 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>
124
  </div>
125
  """
@@ -128,7 +113,7 @@ def display_dishes(category):
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():
@@ -141,39 +126,43 @@ with gr.Blocks() as demo:
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';
 
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
  "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
  "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
  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
  <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
 
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():
 
126
 
127
  # JavaScript for managing the pop-up
128
  gr.HTML(f"""
129
+ <div id=\"popup\" style=\"display: none; position: absolute; background-color: white; padding: 20px; border-radius: 10px;
130
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;\">
131
+ <img id=\"popup-image\" src=\"\" alt=\"\" style=\"width: 100%; height: auto; border-radius: 10px;\">
132
+ <h2 id=\"popup-title\" style=\"margin-top: 20px; color: #444;\"></h2>
133
+ <p id=\"popup-description\" style=\"margin-top: 10px; font-size: 16px; color: #666;\"></p>
134
+ <p id=\"popup-price\" style=\"margin-top: 10px; font-size: 16px; color: #444;\"></p>
 
135
 
136
+ <h4 style=\"text-align: left; margin-top: 20px;\">Choose a spice level</h4>
137
+ <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\">
138
+ """ + """".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]) + """
139
  </div>
140
 
141
+ <h4 style=\"text-align: left; margin-top: 20px;\">Choose Extras</h4>
142
+ <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\">
143
+ """ + """".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]) + """
144
  </div>
145
 
146
+ <button onclick=\"addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)\"
147
+ style=\"margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
148
+ border-radius: 5px; cursor: pointer;\">Add to Cart</button>
149
+ <button onclick=\"closePopup()\" style=\"margin-top: 20px; padding: 10px 20px; background-color: #28a745;
150
+ color: white; border: none; border-radius: 5px; cursor: pointer;\">Close</button>
151
  </div>
152
  <script>
153
+ function showPopup(dishId, image, title, description, price) {
154
+ const dishElement = document.getElementById(`dish-${dishId}`);
155
+ const rect = dishElement.getBoundingClientRect();
156
+ const popup = document.getElementById('popup');
157
+
158
  document.getElementById('popup-image').src = image;
159
  document.getElementById('popup-title').textContent = title;
160
  document.getElementById('popup-description').textContent = description;
161
  document.getElementById('popup-price').textContent = "Price: " + price;
162
 
163
+ popup.style.top = `${rect.bottom + window.scrollY}px`;
164
+ popup.style.left = `${rect.left + window.scrollX}px`;
165
+ popup.style.display = 'block';
166
  }
167
  function closePopup() {
168
  document.getElementById('popup').style.display = 'none';