Rammohan0504 commited on
Commit
159efe9
·
verified ·
1 Parent(s): ae9f3bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -40
app.py CHANGED
@@ -119,50 +119,57 @@ with gr.Blocks() as demo:
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(
 
119
  dish_display = gr.HTML(value=display_dishes("ALL"))
120
 
121
  # JavaScript for managing the pop-up
122
+ gr.HTML("""
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(
134
+ [f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>'
135
+ for spice in spice_levels]
136
+ ) + """
137
+ </div>
138
 
139
+ <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
140
+ <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
141
+ """ + "".join(
142
+ [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>'
143
+ for extra in extras]
144
+ ) + """
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
 
174
  # Button click events
175
  btn_all.click(