Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234514 unmodified lines202122222324242526272850 unmodified lines7980818182838485858687888952 unmodified lines142143144144145146145import gradio as grimport json
# Global variables for cart and menu datacart = []14 unmodified lines]
# Function to add an item to the cartdef add_to_cart(item_name):def add_to_cart(item_name: str): cart.append({"item_name": item_name}) return {"data": f"{item_name} added to cart!"} return f"'{item_name}' has been added to your cart!"
# Function to display the current cartdef display_cart():50 unmodified lines document.getElementById("add-to-cart-button").onclick = async function() { const response = await fetch("/run/add_to_cart", { method: "POST", body: JSON.stringify({ name }), body: JSON.stringify({ data: name }), headers: { "Content-Type": "application/json" } }); const result = await response.json(); alert(result.data); // Show success message alert(result.message); // Show success message closePopup(); // Automatically close popup }; }52 unmodified lines outputs=cart_display )
# Register the add_to_cart functiondemo.add_to_cart = add_to_cart
demo.launch()app.py+5-7