Rammohan0504 commited on
Commit
fa75506
·
verified ·
1 Parent(s): 3ac1af1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
 
3
  # Global variables for cart and menu data
4
  cart = []
@@ -19,9 +20,9 @@ menu_data = [
19
  ]
20
 
21
  # Function to add an item to the cart
22
- def add_to_cart(item_name):
23
  cart.append({"item_name": item_name})
24
- return {"data": f"{item_name} added to cart!"}
25
 
26
  # Function to display the current cart
27
  def display_cart():
@@ -78,11 +79,11 @@ popup_js = """
78
  document.getElementById("add-to-cart-button").onclick = async function() {
79
  const response = await fetch("/run/add_to_cart", {
80
  method: "POST",
81
- body: JSON.stringify({ name }),
82
  headers: { "Content-Type": "application/json" }
83
  });
84
  const result = await response.json();
85
- alert(result.data); // Show success message
86
  closePopup(); // Automatically close popup
87
  };
88
  }
@@ -141,7 +142,4 @@ with gr.Blocks() as demo:
141
  outputs=cart_display
142
  )
143
 
144
- # Register the add_to_cart function
145
- demo.add_to_cart = add_to_cart
146
-
147
  demo.launch()
 
1
  import gradio as gr
2
+ import json
3
 
4
  # Global variables for cart and menu data
5
  cart = []
 
20
  ]
21
 
22
  # Function to add an item to the cart
23
+ def add_to_cart(item_name: str):
24
  cart.append({"item_name": item_name})
25
+ return f"'{item_name}' has been added to your cart!"
26
 
27
  # Function to display the current cart
28
  def display_cart():
 
79
  document.getElementById("add-to-cart-button").onclick = async function() {
80
  const response = await fetch("/run/add_to_cart", {
81
  method: "POST",
82
+ body: JSON.stringify({ data: name }),
83
  headers: { "Content-Type": "application/json" }
84
  });
85
  const result = await response.json();
86
+ alert(result.message); // Show success message
87
  closePopup(); // Automatically close popup
88
  };
89
  }
 
142
  outputs=cart_display
143
  )
144
 
 
 
 
145
  demo.launch()