Spaces:
Sleeping
Sleeping
import gradio as gr | |
import random | |
# Restaurant Info | |
RESTAURANT_NAME = "Taste of Paradise" | |
THEME_COLOR = "#FF6B6B" | |
CONTACT = "π 020 7123 4567 | π 45 Foodie Lane, London | π 10AM-10PM Daily" | |
# Menu Items with Images and Prices | |
menu_items = [ | |
{ | |
"category": "π Starters", | |
"items": [ | |
{"name": "Garlic Bread", "price": 4.99, "image": "images/garlic_bread.jpg"}, | |
{"name": "Bruschetta", "price": 5.99, "image": "images/bruschetta.jpg"} | |
] | |
}, | |
{ | |
"category": "π Main Courses", | |
"items": [ | |
{"name": "Cheese Burger", "price": 12.99, "image": "images/burger.jpg"}, | |
{"name": "Margherita Pizza", "price": 10.99, "image": "images/pizza.jpg"} | |
] | |
}, | |
{ | |
"category": "π° Desserts", | |
"items": [ | |
{"name": "Chocolate Cake", "price": 6.99, "image": "images/cake.jpg"}, | |
{"name": "Ice Cream", "price": 4.99, "image": "images/ice_cream.jpg"} | |
] | |
} | |
] | |
def create_menu_item(item): | |
with gr.Column(scale=1, variant="panel"): | |
gr.Image(item["image"], show_label=False, height=200, width=300) | |
gr.Markdown(f"### {item['name']}\n" | |
f"**Price:** <span style='color: green;'>Β£{item['price']}</span>") | |
return gr.Number(0, label="Quantity", minimum=0, step=1) | |
def calculate_order(*quantities): | |
total = 0 | |
prices = [item["price"] for category in menu_items for item in category["items"]] | |
order_details = "<h2>π Your Order:</h2>" | |
for qty, price, category in zip(quantities, prices, [item for category in menu_items for item in category["items"]]): | |
if qty > 0: | |
total += qty * price | |
order_details += f"β’ {category['name']} x{qty} = Β£{qty*price:.2f}<br>" | |
order_details += f"<h3 style='color: {THEME_COLOR};'>Total: Β£{total:.2f}</h3>" | |
return order_details | |
with gr.Blocks(title=RESTAURANT_NAME, theme=gr.themes.Default(primary_hue="red")) as app: | |
# Header Section | |
gr.Markdown(f"<h1 style='text-align: center; color: {THEME_COLOR};'>π½οΈ {RESTAURANT_NAME}</h1>") | |
gr.Markdown(f"<div style='text-align: center;'>{CONTACT}</div>") | |
# Menu Display | |
with gr.Row(): | |
# Menu Items Column | |
with gr.Column(scale=3): | |
quantity_inputs = [] | |
for category in menu_items: | |
gr.Markdown(f"## {category['category']}") | |
with gr.Row(): | |
for item in category["items"]: | |
qty_input = create_menu_item(item) | |
quantity_inputs.append(qty_input) | |
# Order Summary Column | |
with gr.Column(scale=1, variant="panel"): | |
order_display = gr.HTML() | |
calculate_btn = gr.Button("Update Order", variant="primary") | |
calculate_btn.click(calculate_order, inputs=quantity_inputs, outputs=order_display) | |
# Order Confirmation | |
with gr.Accordion("Place Order", open=False): | |
name = gr.Textbox(label="Name") | |
table = gr.Number(label="Table Number", minimum=1) | |
notes = gr.Textbox(label="Special Requests") | |
confirm_btn = gr.Button("Confirm Order", variant="stop") | |
confirmation = gr.Markdown() | |
def confirm_order(name, table, notes): | |
if not name or not table: | |
return "β Please fill in all required fields" | |
return f"β Order placed successfully! Your food will be prepared for table {int(table)}" | |
confirm_btn.click(confirm_order, [name, table, notes], confirmation) | |
# Footer | |
gr.Markdown("---") | |
gr.Markdown("**Follow us:** [Instagram](https://instagram.com) | [Facebook](https://facebook.com) | [Twitter](https://twitter.com)") | |
if __name__ == "__main__": | |
app.launch() |