Rammohan0504 commited on
Commit
d2d895b
·
verified ·
1 Parent(s): 7faa7d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -80,6 +80,7 @@ menu_data = [
80
  "price": "$7.99"}
81
  ]
82
 
 
83
  # Spice levels and extras
84
  spice_levels = ["American Mild", "American Medium", "American Spicy",
85
  "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
@@ -140,7 +141,7 @@ with gr.Blocks() as demo:
140
 
141
  # JavaScript for managing the pop-up
142
  gr.HTML(f"""
143
- <div id="popup" style="display: none; position: fixed; left: 50%; transform: translate(-50%, -50%);
144
  background-color: white; padding: 20px; border-radius: 10px;
145
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
146
  <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
@@ -149,43 +150,37 @@ with gr.Blocks() as demo:
149
  <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
150
 
151
  <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
152
- <div id="spice-levels-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
153
  """ + "".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]) + """
154
  </div>
155
 
156
  <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
157
- <div id="extras-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
158
  """ + "".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]) + """
159
  </div>
160
 
161
- <button onclick="addToCart()"
162
  style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
163
  border-radius: 5px; cursor: pointer;">Add to Cart</button>
164
  <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
165
  color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
166
  </div>
167
  <script>
168
- let selectedSpice = null;
169
- let selectedExtras = [];
170
-
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
  document.getElementById('popup').style.display = 'block';
178
  }
179
-
180
  function closePopup() {
181
  document.getElementById('popup').style.display = 'none';
182
  }
183
-
184
- function addToCart() {
185
- const spice = document.querySelector('input[name=spice]:checked')?.value || "No spice selected";
186
- const extras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(input => input.value);
187
- alert(Added with spice level: ${spice}, and extras: ${extras.join(", ")});
188
- closePopup();
189
  }
190
  </script>
191
  """)
 
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"]
 
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;">
 
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
  """)