Rammohan0504 commited on
Commit
ae9f3bb
·
verified ·
1 Parent(s): 3b11719

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -47
app.py CHANGED
@@ -13,7 +13,55 @@ 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
  ]
18
 
19
  # Spice levels and extras
@@ -71,56 +119,51 @@ with gr.Blocks() as demo:
71
  dish_display = gr.HTML(value=display_dishes("ALL"))
72
 
73
  # JavaScript for managing the pop-up
74
- gr.HTML("""
75
- <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
76
- background-color: white; padding: 20px; border-radius: 10px;
77
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
78
- <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
79
- <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
80
- <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
81
- <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
 
 
 
 
 
82
 
83
- <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
84
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
85
- """ + "".join(
86
- [f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>'
87
- for spice in spice_levels]
88
- ) + """
89
- </div>
90
 
91
- <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
92
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
93
- """ + "".join(
94
- [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>'
95
- for extra in extras]
96
- ) + """
97
  </div>
 
 
 
 
 
 
98
 
99
- <button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
100
- style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
101
- border-radius: 5px; cursor: pointer;">Add to Cart</button>
102
- <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
103
- color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
104
- </div>
105
- <script>
106
- function showPopup(image, title, description, price) {
107
- document.getElementById('popup-image').src = image;
108
- document.getElementById('popup-title').textContent = title;
109
- document.getElementById('popup-description').textContent = description;
110
- document.getElementById('popup-price').textContent = "Price: " + price;
111
 
112
- // Display the popup
113
- document.getElementById('popup').style.display = 'block';
114
- }
115
- function closePopup() {
116
- document.getElementById('popup').style.display = 'none';
117
- }
118
- function addToCart(dishName, spiceLevel) {
119
- const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
120
- alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
121
- }
122
- </script>
123
- """)
124
  # Button click events
125
  btn_all.click(
126
  lambda: gr.update(value=display_dishes("ALL")),
@@ -135,4 +178,4 @@ with gr.Blocks() as demo:
135
  outputs=dish_display
136
  )
137
 
138
- demo.launch()
 
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": "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.",
24
+ "price": "$2.99"},
25
+ {"name": "Fish Curry", "category": "HALAL",
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.",
36
+ "price": "$9.99"},
37
+ {"name": "Dal Makhani", "category": "VEGAN",
38
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/dal_makhani.jpg",
39
+ "description": "Rich and creamy black lentils slow-cooked with spices.",
40
+ "price": "$8.99"},
41
+ {"name": "Lamb Curry", "category": "HALAL",
42
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/lamb_curry.jpg",
43
+ "description": "Tender lamb pieces cooked in a flavorful curry sauce.",
44
+ "price": "$14.99"},
45
+ {"name": "Mixed Veg Curry", "category": "VEGAN",
46
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mixed_veg_curry.jpg",
47
+ "description": "A medley of fresh vegetables cooked in a lightly spiced curry.",
48
+ "price": "$9.99"},
49
+ {"name": "Chicken Wings", "category": "HALAL",
50
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_wings.jpg",
51
+ "description": "Crispy chicken wings tossed in a tangy sauce.",
52
+ "price": "$12.99"},
53
+ {"name": "Aloo Paratha", "category": "VEGAN",
54
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/aloo_paratha.jpg",
55
+ "description": "Indian flatbread stuffed with spiced mashed potatoes.",
56
+ "price": "$3.99"},
57
+ {"name": "Egg Curry", "category": "HALAL",
58
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/egg_curry.jpg",
59
+ "description": "Boiled eggs cooked in a spiced tomato gravy.",
60
+ "price": "$9.99"},
61
+ {"name": "Chickpea Salad", "category": "VEGAN",
62
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chickpea_salad.jpg",
63
+ "description": "A refreshing salad made with chickpeas, fresh vegetables, and herbs.",
64
+ "price": "$7.99"}
65
  ]
66
 
67
  # Spice levels and extras
 
119
  dish_display = gr.HTML(value=display_dishes("ALL"))
120
 
121
  # JavaScript for managing the pop-up
122
+ gr.HTML(f"""
123
+ <div id=\"popup\" style=\"display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
124
+ background-color: white; padding: 20px; border-radius: 10px;
125
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;\">
126
+ <img id=\"popup-image\" src=\"\" alt=\"\" style=\"width: 100%; height: auto; border-radius: 10px;\">
127
+ <h2 id=\"popup-title\" style=\"margin-top: 20px; color: #444;\"></h2>
128
+ <p id=\"popup-description\" style=\"margin-top: 10px; font-size: 16px; color: #666;\"></p>
129
+ <p id=\"popup-price\" style=\"margin-top: 10px; font-size: 16px; color: #444;\"></p>
130
+
131
+ <h4 style=\"text-align: left; margin-top: 20px;\">Choose a spice level</h4>
132
+ <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\">
133
+ """ + """".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]) + """
134
+ </div>
135
 
136
+ <h4 style=\"text-align: left; margin-top: 20px;\">Choose Extras</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=\"checkbox\" name=\"extras\" value=\"{extra["name"]}\" style=\"margin-right: 5px;\">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
139
+ </div>
 
 
 
140
 
141
+ <button onclick=\"addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)\"
142
+ style=\"margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
143
+ border-radius: 5px; cursor: pointer;\">Add to Cart</button>
144
+ <button onclick=\"closePopup()\" style=\"margin-top: 20px; padding: 10px 20px; background-color: #28a745;
145
+ color: white; border: none; border-radius: 5px; cursor: pointer;\">Close</button>
 
146
  </div>
147
+ <script>
148
+ function showPopup(image, title, description, price) {
149
+ document.getElementById('popup-image').src = image;
150
+ document.getElementById('popup-title').textContent = title;
151
+ document.getElementById('popup-description').textContent = description;
152
+ document.getElementById('popup-price').textContent = "Price: " + price;
153
 
154
+ // Display the popup
155
+ document.getElementById('popup').style.display = 'block';
156
+ }
157
+ function closePopup() {
158
+ document.getElementById('popup').style.display = 'none';
159
+ }
160
+ function addToCart(dishName, spiceLevel) {
161
+ const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
162
+ alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
163
+ }
164
+ </script>
165
+ """)
166
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  # Button click events
168
  btn_all.click(
169
  lambda: gr.update(value=display_dishes("ALL")),
 
178
  outputs=dish_display
179
  )
180
 
181
+ demo.launch()