Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234510 unmodified lines1617181920212232 unmodified lines555657585960616263646566676869707151 unmodified lines123124125126import gradio as grfrom cart_tab import add_to_cart, display_cart # Import shared cart functionsmenu_data = [{"name": "Veg Burger", "category": "VEGAN",10 unmodified lines"price": "$10.99"}]# Function to generate dish cardsdef display_dishes(category):32 unmodified lines<button id="add-to-cart-button" style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button><button onclick="closePopup()" style="padding: 10px 20px; background-color: #dc3545; color: white; border: none; border-radius: 5px; cursor: pointer; margin-left: 10px;">Close</button>`;popup.style.display = "block";overlay.style.display = "block";document.getElementById("add-to-cart-button").onclick = async function() {const response = await google.colab.kernel.invokeFunction('add_to_cart', [name], {});alert(response.data);closePopup();};}51 unmodified linesoutputs=cart_display)demo.launch()123456710 unmodified lines181920212223242526272829303132333435363732 unmodified lines7071727374757677787980818283848586878851 unmodified lines140141142143144145146import gradio as gr# Global variables for cart and menu datacart = []menu_data = [{"name": "Veg Burger", "category": "VEGAN",10 unmodified lines"price": "$10.99"}]# Function to add an item to the cartdef add_to_cart(item_name):cart.append({"item_name": item_name})return f"{item_name} added to cart!"# Function to display the current cartdef display_cart():if not cart:return "Your cart is empty."cart_content = "<h3>Your Cart:</h3><ul>"for item in cart:cart_content += f"<li>{item['item_name']}</li>"cart_content += "</ul>"return cart_content# Function to generate dish cardsdef display_dishes(category):32 unmodified lines<button id="add-to-cart-button" style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>`;popup.style.display = "block";overlay.style.display = "block";document.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};}51 unmodified linesoutputs=cart_display)# Register the add_to_cart functiondemo.api("/add_to_cart", add_to_cart)demo.launch()
app.py+27-7