Rammohan0504 commited on
Commit
3df077f
·
verified ·
1 Parent(s): 045c20e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -39
app.py CHANGED
@@ -137,45 +137,63 @@ with gr.Blocks() as demo:
137
  <button onclick="addItemToCart()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px;">Add to Cart</button>
138
  </div>
139
  <script>
140
- let selectedDish = "";
141
- let selectedExtras = [];
142
-
143
- function showPopup(title, description, price) {
144
- selectedDish = title;
145
- document.getElementById('popup-title').textContent = title;
146
- document.getElementById('popup-description').textContent = description;
147
- document.getElementById('popup-price').textContent = price;
148
- document.getElementById('popup').style.display = 'block';
149
- }
150
- function closePopup() {
151
- document.getElementById('popup').style.display = 'none';
152
- }
153
- function increaseQuantity() {
154
- const quantityInput = document.getElementById('quantity');
155
- quantityInput.value = parseInt(quantityInput.value) + 1;
156
- }
157
- function decreaseQuantity() {
158
- const quantityInput = document.getElementById('quantity');
159
- if (parseInt(quantityInput.value) > 1) {
160
- quantityInput.value = parseInt(quantityInput.value) - 1;
161
- }
162
- }
163
- function addItemToCart() {
164
- const extrasInputs = document.querySelectorAll('input[name="extras"]:checked');
165
- selectedExtras = Array.from(extrasInputs).map(input => input.value);
166
- const quantity = document.getElementById('quantity').value || 1;
167
- const customDescription = document.getElementById('custom-description').value || "None";
168
-
169
- // Pass to Gradio backend
170
- gradioApp().querySelector("#component-0 input").value = selectedDish;
171
- gradioApp().querySelector("#component-1 input").value = JSON.stringify(selectedExtras);
172
- gradioApp().querySelector("#component-2 input").value = quantity;
173
- gradioApp().querySelector("#component-3 input").value = customDescription;
174
- gradioApp().querySelector("#component-4 button").click();
175
- closePopup();
176
- }
177
- </script>
178
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  demo.launch()
181
 
 
137
  <button onclick="addItemToCart()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px;">Add to Cart</button>
138
  </div>
139
  <script>
140
+ let selectedDish = "";
141
+ let selectedExtras = [];
142
+
143
+ function showPopup(title, description, price) {
144
+ selectedDish = title;
145
+ document.getElementById('popup-title').textContent = title;
146
+ document.getElementById('popup-description').textContent = description;
147
+ document.getElementById('popup-price').textContent = price;
148
+ document.getElementById('popup').style.display = 'block';
149
+ }
150
+
151
+ function closePopup() {
152
+ document.getElementById('popup').style.display = 'none';
153
+ }
154
+
155
+ function increaseQuantity() {
156
+ const quantityInput = document.getElementById('quantity');
157
+ quantityInput.value = parseInt(quantityInput.value) + 1;
158
+ }
159
+
160
+ function decreaseQuantity() {
161
+ const quantityInput = document.getElementById('quantity');
162
+ if (parseInt(quantityInput.value) > 1) {
163
+ quantityInput.value = parseInt(quantityInput.value) - 1;
164
+ }
165
+ }
166
+
167
+ function addItemToCart() {
168
+ const extrasInputs = document.querySelectorAll('input[name="extras"]:checked');
169
+ selectedExtras = Array.from(extrasInputs).map(input => input.value);
170
+ const quantity = document.getElementById('quantity').value || 1;
171
+ const customDescription = document.getElementById('custom-description').value || "None";
172
+
173
+ // Pass data to Gradio backend
174
+ const gradioApp = document.querySelector("gradio-app").shadowRoot;
175
+ const dishNameInput = gradioApp.querySelector("textarea[aria-label='Dish Name']");
176
+ const extrasInput = gradioApp.querySelector("textarea[aria-label='Selected Extras']");
177
+ const quantityInput = gradioApp.querySelector("input[aria-label='Quantity']");
178
+ const customDescriptionInput = gradioApp.querySelector("textarea[aria-label='Custom Description']");
179
+ const addToCartButton = gradioApp.querySelector("button[aria-label='Add to Cart']");
180
+
181
+ if (dishNameInput && extrasInput && quantityInput && customDescriptionInput && addToCartButton) {
182
+ dishNameInput.value = selectedDish;
183
+ extrasInput.value = JSON.stringify(selectedExtras);
184
+ quantityInput.value = quantity;
185
+ customDescriptionInput.value = customDescription;
186
+
187
+ // Trigger Gradio's add-to-cart function
188
+ addToCartButton.click();
189
+ closePopup();
190
+ } else {
191
+ console.error("Failed to locate Gradio inputs or button.");
192
+ }
193
+ }
194
+ </script>
195
+
196
+ """)
197
 
198
  demo.launch()
199