import gradio as gr # In-memory cart to store added items cart = [] # Menu data menu_data = [ {"name": "Vegetable Biryani", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg", "description": "An Indian dish made to be thoroughly enjoyed by anyone who eats it. Made with the best basmati rice and a perfect blend of spices, cooked in original dum style.", "price": "$13.99"}, ] # Function to add an item to the cart def add_to_cart(name, price): cart.append({"name": name, "price": price}) return f"{name} has been added to the cart!", display_cart() # Function to display the cart def display_cart(): if not cart: return "Cart is empty" html_content = "
" for item in cart: html_content += f"""

{item['name']} - {item['price']}

""" html_content += "
" return html_content # Function to display the menu def display_menu(): html_content = "
" for dish in menu_data: html_content += f"""

{dish['name']}

{dish['description']}

Price: {dish['price']}

{dish[
""" html_content += "
" return html_content # Gradio App with gr.Blocks() as demo: gr.HTML("

🍛 Biryani Hub Menu 🍛

") # Display menu menu_section = gr.HTML(value=display_menu()) # Add to Cart functionality name_input = gr.Textbox(label="Dish Name", visible=False) price_input = gr.Textbox(label="Dish Price", visible=False) add_to_cart_button = gr.Button("Add to Cart", visible=False) message_output = gr.Textbox(label="Message", interactive=False) cart_display = gr.HTML(value=display_cart()) # Add to cart interaction add_to_cart_button.click( add_to_cart, inputs=[name_input, price_input], outputs=[message_output, cart_display] ) # Menu Section with dynamic cart updates demo += menu_section demo += message_output demo += cart_display demo.launch()