Rammohan0504 commited on
Commit
0a4cf1a
·
verified ·
1 Parent(s): 85f7c95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -40
app.py CHANGED
@@ -126,50 +126,53 @@ with gr.Blocks() as demo:
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([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]) + """
140
- </div>
141
-
142
- <h4 style=\"text-align: left; margin-top: 20px;\">Choose Extras</h4>
143
- <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\">
144
- """ + """".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]) + """
145
- </div>
146
 
147
- <button onclick=\"addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)\"
148
- style=\"margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
149
- border-radius: 5px; cursor: pointer;\">Add to Cart</button>
150
- <button onclick=\"closePopup()\" style=\"margin-top: 20px; padding: 10px 20px; background-color: #28a745;
151
- color: white; border: none; border-radius: 5px; cursor: pointer;\">Close</button>
152
  </div>
153
- <script>
154
- function showPopup(image, title, description, price) {
155
- document.getElementById('popup-image').src = image;
156
- document.getElementById('popup-title').textContent = title;
157
- document.getElementById('popup-description').textContent = description;
158
- document.getElementById('popup-price').textContent = "Price: " + price;
159
 
160
- // Display the popup
161
- document.getElementById('popup').style.display = 'block';
162
- }
163
- function closePopup() {
164
- document.getElementById('popup').style.display = 'none';
165
- }
166
- function addToCart(dishName, spiceLevel) {
167
- const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
168
- alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
169
- }
170
- </script>
171
- """)
172
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  # Button click events
174
  btn_all.click(
175
  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
  # Button click events
177
  btn_all.click(
178
  lambda: gr.update(value=display_dishes("ALL")),