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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -42
app.py CHANGED
@@ -126,54 +126,55 @@ with gr.Blocks() as demo:
126
 
127
  # JavaScript for managing the pop-up
128
  gr.HTML("""
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
- <p id=\"popup-image\" style=\"font-size: 14px; word-break: break-all; color: #444; margin-top: 10px;\"></p>
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').textContent = 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';
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
  # Button click events
178
  btn_all.click(
179
  lambda: gr.update(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(
180
  lambda: gr.update(value=display_dishes("ALL")),