|
import gradio as gr |
|
|
|
|
|
menu = { |
|
'Burger': 5.99, |
|
'Pizza': 7.99, |
|
'Fries': 2.99, |
|
'Soda': 1.99, |
|
'Salad': 4.99 |
|
} |
|
|
|
order = {} |
|
total_cost = 0 |
|
|
|
def take_order(choice, quantity): |
|
global total_cost |
|
if choice in menu: |
|
order[choice] = order.get(choice, 0) + quantity |
|
total_cost += menu[choice] * quantity |
|
return f"{quantity} {choice}(s) added to your order." |
|
else: |
|
return "Item not available, please choose again." |
|
|
|
def display_order(): |
|
order_summary = "Your Order:\n" |
|
for item, quantity in order.items(): |
|
order_summary += f"{item} x {quantity} = ${menu[item] * quantity:.2f}\n" |
|
order_summary += f"\nTotal Cost: rupees{total_cost:.2f}" |
|
return order_summary |
|
|
|
|
|
def place_order(item, qty): |
|
message = take_order(item, qty) |
|
order_summary = display_order() |
|
return f"{message}\n\n{order_summary}" |
|
|
|
menu_items = list(menu.keys()) |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Menu Ordering System") |
|
|
|
with gr.Row(): |
|
item_dropdown = gr.Dropdown(choices=menu_items, label="Select Item") |
|
quantity_slider = gr.Slider(minimum=1, maximum=10, step=1, label="Quantity") |
|
|
|
order_button = gr.Button("Add to Order") |
|
output = gr.Textbox(label="Order Summary") |
|
|
|
order_button.click(fn=place_order, inputs=[item_dropdown, quantity_slider], outputs=output) |
|
|
|
demo.launch(share=True) |
|
|