Digitalmenu / app.py
Wanswan's picture
Update app.py
756372e verified
Raw
History Blame Contribute Delete
4.22 kB
import gradio as gr
import time
import csv
from datetime import datetime
import os
import pandas as pd
# ========== ่œๅ•ๆ•ฐๆฎ็ป“ๆž„ ==========
MENU_DATA = {
"Appetizers": [
{"id": "A1", "name": "Spring Rolls", "desc": "(Cabbage, carrots, wrapper) โ€“ Crispy fried rolls with vegetables.", "price": 4.5},
{"id": "A2", "name": "Dumplings", "desc": "(Pork, chives, soy sauce) โ€“ Steamed dumplings with savory filling.", "price": 5.0},
{"id": "A3", "name": "Salad", "desc": "(Lettuce, cucumber, tomato) โ€“ Fresh vegetable salad with light dressing.", "price": 3.5},
{"id": "A4", "name": "Tofu Skewers", "desc": "(Tofu, peppers, glaze) โ€“ Grilled tofu skewers with sweet sauce.", "price": 4.0},
{"id": "A5", "name": "Edamame", "desc": "(Soybeans, salt) โ€“ Lightly boiled and salted green soybeans.", "price": 3.0},
],
"Main Dishes": [
{"id": "B1", "name": "Beef Pho", "desc": "(Beef, rice noodles, herbs) โ€“ Traditional Vietnamese noodle soup.", "price": 9.5},
{"id": "B2", "name": "Chicken Curry", "desc": "(Chicken, coconut milk, curry) โ€“ Mild spicy curry with rice.", "price": 10.0},
{"id": "B3", "name": "Fried Rice", "desc": "(Rice, egg, veggies) โ€“ Wok-fried rice with soy sauce and greens.", "price": 8.0},
{"id": "B4", "name": "Grilled Fish", "desc": "(Fish, lime, herbs) โ€“ Grilled fillet with citrus-herb flavor.", "price": 11.0},
{"id": "B5", "name": "Veggie Stir Fry", "desc": "(Broccoli, carrots, tofu) โ€“ Mixed vegetables stir-fried in sauce.", "price": 8.5},
],
"Desserts": [
{"id": "C1", "name": "Mango Sticky Rice", "desc": "(Mango, sticky rice, coconut) โ€“ Thai-style sweet dessert.", "price": 5.0},
{"id": "C2", "name": "Taro Cake", "desc": "(Taro, rice flour, sugar) โ€“ Soft steamed traditional treat.", "price": 4.5},
{"id": "C3", "name": "Coconut Jelly", "desc": "(Coconut milk, agar) โ€“ Light and refreshing cold dessert.", "price": 4.0},
{"id": "C4", "name": "Sweet Bean Soup", "desc": "(Red beans, sugar, tapioca) โ€“ Warm comforting dessert soup.", "price": 3.5},
{"id": "C5", "name": "Sesame Balls", "desc": "(Glutinous rice, sesame, red bean) โ€“ Crispy chewy snack.", "price": 3.5},
],
"Drinks": [
{"id": "D1", "name": "Lime Soda", "desc": "(Lime, soda water, sugar) โ€“ Refreshing fizzy lime drink.", "price": 2.5},
{"id": "D2", "name": "Iced Tea", "desc": "(Black tea, lemon, ice) โ€“ Chilled lemon tea beverage.", "price": 2.0},
{"id": "D3", "name": "Coconut Water", "desc": "(Coconut juice) โ€“ Natural hydrating drink.", "price": 3.0},
{"id": "D4", "name": "Soy Milk", "desc": "(Soybeans, water, sugar) โ€“ Sweet and smooth traditional drink.", "price": 2.0},
{"id": "D5", "name": "Bottled Water", "desc": "(Mineral water) โ€“ Still bottled water.", "price": 1.5},
],
}
# ========== ๅŠŸ่ƒฝๅ‡ฝๆ•ฐ ==========
def record_time(start_time):
duration = round(time.time() - start_time, 2)
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open("decision_times.csv", "a", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow([timestamp, duration])
return f"โœ… Thank you! Your decision time was {duration} seconds.\nPlease proceed to the next page and enter your selected item IDs."
# ========== Gradio ็•Œ้ข ==========
with gr.Blocks(css=".footer, .prose a {display: none !important}") as demo:
start_time = time.time()
gr.Markdown("# ๐Ÿ“‹ Digital Menu\nPlease browse the menu and decide what you'd like to order.")
with gr.Tabs():
for category, items in MENU_DATA.items():
with gr.Tab(label=category):
for item in items:
with gr.Row():
gr.Image(value="user_avatar.jpg", width=100, height=100)
gr.Markdown(f"**{item['id']} โ€“ {item['name']}** \n{item['desc']} \n๐Ÿ’ฐ โ‚ฌ{item['price']:.2f}")
submit_btn = gr.Button("โœ… I have made my selection")
output_box = gr.Textbox(visible=False)
submit_btn.click(fn=record_time, inputs=[gr.State(value=start_time)], outputs=output_box)
demo.launch()