Spaces:
Sleeping
Sleeping
Update app.py
Browse files123414 unmodified lines19202122232425262750 unmodified lines787980818283848586878852 unmodified lines141142143144145146147import gradio as gr# Global variables for cart and menu datacart = []14 unmodified lines]# Function to add an item to the cartdef add_to_cart(item_name):cart.append({"item_name": item_name})return {"data": f"{item_name} added to cart!"}# Function to display the current cartdef display_cart():50 unmodified linesdocument.getElementById("add-to-cart-button").onclick = async function() {const response = await fetch("/run/add_to_cart", {method: "POST",body: JSON.stringify({ name }),headers: { "Content-Type": "application/json" }});const result = await response.json();alert(result.data); // Show success messageclosePopup(); // Automatically close popup};}52 unmodified linesoutputs=cart_display)# Register the add_to_cart functiondemo.add_to_cart = add_to_cartdemo.launch()1234514 unmodified lines20212223242526272850 unmodified lines798081828384858687888952 unmodified lines142143144145import 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: str):cart.append({"item_name": item_name})return f"'{item_name}' has been added to your cart!"# Function to display the current cartdef display_cart():50 unmodified linesdocument.getElementById("add-to-cart-button").onclick = async function() {const response = await fetch("/run/add_to_cart", {method: "POST",body: JSON.stringify({ data: name }),headers: { "Content-Type": "application/json" }});const result = await response.json();alert(result.message); // Show success messageclosePopup(); // Automatically close popup};}52 unmodified linesoutputs=cart_display)demo.launch()
app.py+5-7