Rammohan0504 commited on
Commit
95c386c
·
verified ·
1 Parent(s): 96df211

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -156,15 +156,21 @@ with gr.Blocks() as demo:
156
  const quantity = document.getElementById('quantity').value || 1;
157
  const customDescription = document.getElementById('custom-description').value || "None";
158
 
159
- // Trigger Gradio function via input updates
160
- gradioApp().querySelector("#component-1 textarea").value = selectedDish;
161
- gradioApp().querySelector("#component-2 textarea").value = spiceLevel;
162
- gradioApp().querySelector("#component-3 textarea").value = JSON.stringify(selectedExtras);
163
- gradioApp().querySelector("#component-4 input").value = quantity;
164
- gradioApp().querySelector("#component-5 textarea").value = customDescription;
165
- gradioApp().querySelector("#component-6 button").click();
166
-
167
- closePopup();
 
 
 
 
 
 
168
  }
169
  </script>
170
  """)
@@ -174,11 +180,5 @@ with gr.Blocks() as demo:
174
  btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
175
  btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
176
 
177
- # Link Add to Cart functionality
178
- gr.Button("Add", visible=False).click(
179
- add_to_cart,
180
- inputs=[gr.Textbox(), gr.Textbox(), gr.Textbox(), gr.Number(), gr.Textbox()],
181
- outputs=cart_display
182
- )
183
 
184
  demo.launch()
 
156
  const quantity = document.getElementById('quantity').value || 1;
157
  const customDescription = document.getElementById('custom-description').value || "None";
158
 
159
+ // Pass to Gradio backend
160
+ fetch("/run/add_to_cart", {
161
+ method: "POST",
162
+ headers: {"Content-Type": "application/json"},
163
+ body: JSON.stringify({
164
+ dish_name: selectedDish,
165
+ spice_level: spiceLevel,
166
+ selected_extras: selectedExtras,
167
+ quantity: quantity,
168
+ custom_description: customDescription
169
+ })
170
+ }).then(response => response.json()).then(data => {
171
+ document.querySelector("#cart-display").innerHTML = data.html;
172
+ closePopup();
173
+ });
174
  }
175
  </script>
176
  """)
 
180
  btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
181
  btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
182
 
 
 
 
 
 
 
183
 
184
  demo.launch()