Rammohan0504 commited on
Commit
c362922
·
verified ·
1 Parent(s): 48c87bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -83,6 +83,7 @@ menu_data = [
83
  # The rest of the code remains unchanged
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"]
@@ -152,37 +153,52 @@ with gr.Blocks() as demo:
152
  <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
153
 
154
  <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
155
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
156
  """ + "".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]) + """
157
  </div>
158
 
159
  <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
160
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
161
  """ + "".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]) + """
162
  </div>
163
 
164
- <button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
165
  style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
166
  border-radius: 5px; cursor: pointer;">Add to Cart</button>
167
  <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
168
  color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
169
  </div>
170
  <script>
 
 
 
171
  function showPopup(image, title, description, price) {
172
  document.getElementById('popup-image').src = image;
173
  document.getElementById('popup-title').textContent = title;
174
  document.getElementById('popup-description').textContent = description;
175
  document.getElementById('popup-price').textContent = "Price: " + price;
176
 
 
 
 
 
 
 
 
 
177
  // Display the popup
178
  document.getElementById('popup').style.display = 'block';
179
  }
 
180
  function closePopup() {
181
  document.getElementById('popup').style.display = 'none';
182
  }
183
- function addToCart(dishName, spiceLevel) {
184
- const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
185
- alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
 
 
 
186
  }
187
  </script>
188
  """)
@@ -201,4 +217,4 @@ with gr.Blocks() as demo:
201
  outputs=dish_display
202
  )
203
 
204
- demo.launch()
 
83
  # The rest of the code remains unchanged
84
 
85
 
86
+
87
  # Spice levels and extras
88
  spice_levels = ["American Mild", "American Medium", "American Spicy",
89
  "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
 
153
  <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
154
 
155
  <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
156
+ <div id="spice-levels-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
157
  """ + "".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]) + """
158
  </div>
159
 
160
  <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
161
+ <div id="extras-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
162
  """ + "".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]) + """
163
  </div>
164
 
165
+ <button onclick="addToCart()"
166
  style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
167
  border-radius: 5px; cursor: pointer;">Add to Cart</button>
168
  <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
169
  color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
170
  </div>
171
  <script>
172
+ let selectedSpice = null;
173
+ let selectedExtras = [];
174
+
175
  function showPopup(image, title, description, price) {
176
  document.getElementById('popup-image').src = image;
177
  document.getElementById('popup-title').textContent = title;
178
  document.getElementById('popup-description').textContent = description;
179
  document.getElementById('popup-price').textContent = "Price: " + price;
180
 
181
+ // Reset selections
182
+ selectedSpice = null;
183
+ selectedExtras = [];
184
+ const spiceInputs = document.querySelectorAll('input[name=spice]');
185
+ spiceInputs.forEach(input => input.checked = false);
186
+ const extraInputs = document.querySelectorAll('input[name=extras]');
187
+ extraInputs.forEach(input => input.checked = false);
188
+
189
  // Display the popup
190
  document.getElementById('popup').style.display = 'block';
191
  }
192
+
193
  function closePopup() {
194
  document.getElementById('popup').style.display = 'none';
195
  }
196
+
197
+ function addToCart() {
198
+ selectedSpice = document.querySelector('input[name=spice]:checked')?.value || "No spice selected";
199
+ selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(input => input.value);
200
+ alert(`Dish added with spice: ${selectedSpice} and extras: ${selectedExtras.join(", ")}`);
201
+ closePopup();
202
  }
203
  </script>
204
  """)
 
217
  outputs=dish_display
218
  )
219
 
220
+ demo.launch()