Rammohan0504 commited on
Commit
c2fcd4a
·
verified ·
1 Parent(s): 5da3073

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -90,7 +90,7 @@ with gr.Blocks() as demo:
90
  dish_display = gr.HTML(value=display_dishes("ALL"))
91
 
92
  with gr.Tab("Cart"):
93
- cart_display = gr.HTML(value="<p>Your cart is empty.</p>")
94
 
95
  # JavaScript for managing the pop-up
96
  gr.HTML(f"""
@@ -143,10 +143,7 @@ with gr.Blocks() as demo:
143
  selected_extras: selectedExtras
144
  })
145
  }).then(response => response.text()).then(data => {
146
- const cartDisplay = document.querySelector('#cart-display');
147
- if (cartDisplay) {
148
- cartDisplay.innerHTML = data;
149
- }
150
  document.getElementById('popup').style.display = 'none';
151
  tabs.set_active("Cart");
152
  });
@@ -168,5 +165,12 @@ def add_to_cart_backend(dish_name, spice_level, selected_extras):
168
  })
169
  return update_cart()
170
 
171
- # Remove standalone cart interface
 
 
 
 
 
 
 
172
  demo.launch()
 
90
  dish_display = gr.HTML(value=display_dishes("ALL"))
91
 
92
  with gr.Tab("Cart"):
93
+ cart_display = gr.HTML(value="<p>Your cart is empty.</p>", elem_id="cart-display")
94
 
95
  # JavaScript for managing the pop-up
96
  gr.HTML(f"""
 
143
  selected_extras: selectedExtras
144
  })
145
  }).then(response => response.text()).then(data => {
146
+ document.getElementById('cart-display').innerHTML = data;
 
 
 
147
  document.getElementById('popup').style.display = 'none';
148
  tabs.set_active("Cart");
149
  });
 
165
  })
166
  return update_cart()
167
 
168
+ # Correctly integrate cart updates with Gradio
169
+ @app.post("/add_to_cart")
170
+ def add_to_cart_api(data: dict):
171
+ dish_name = data.get("dish_name", "")
172
+ spice_level = data.get("spice_level", "")
173
+ selected_extras = data.get("selected_extras", [])
174
+ return add_to_cart(dish_name, spice_level, selected_extras)
175
+
176
  demo.launch()