Wanswan commited on
Commit
8feb9fb
·
verified ·
1 Parent(s): 1534924

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -116
app.py CHANGED
@@ -5,131 +5,36 @@ from datetime import datetime
5
  import os
6
  import pandas as pd
7
 
8
- # ====== 菜单数据结构(英文 + 编号 + 描述) ======
9
  MENU_DATA = {
10
  "Appetizers": [
11
- {"id": "A1", "name": "Spring Rolls", "ingredients": "Cabbage, carrot, glass noodles", "desc": "Crispy rolls with vegetables. Light and crunchy.", "price": 4.5},
12
- {"id": "A2", "name": "Dumplings", "ingredients": "Pork, chives, soy sauce", "desc": "Steamed dumplings with savory filling.", "price": 5.0},
13
- {"id": "A3", "name": "Salad", "ingredients": "Lettuce, tomato, cucumber", "desc": "Fresh garden salad with vinaigrette.", "price": 3.5},
14
- {"id": "A4", "name": "Tofu Skewers", "ingredients": "Tofu, sesame, chili", "desc": "Grilled tofu with sweet soy glaze.", "price": 4.0},
15
- {"id": "A5", "name": "Edamame", "ingredients": "Soybeans, salt", "desc": "Boiled soybeans. A healthy starter.", "price": 3.0}
16
- ],
17
- "Main Dishes": [
18
- {"id": "B1", "name": "Beef Pho", "ingredients": "Beef, rice noodles, herbs", "desc": "Vietnamese soup with rich broth.", "price": 9.5},
19
- {"id": "B2", "name": "Chicken Curry", "ingredients": "Chicken, coconut milk, vegetables", "desc": "Spicy curry with rice.", "price": 10.0},
20
- {"id": "B3", "name": "Fried Rice", "ingredients": "Rice, egg, peas, carrots", "desc": "Classic fried rice in soy sauce.", "price": 8.0},
21
- {"id": "B4", "name": "Grilled Fish", "ingredients": "White fish, lemongrass, garlic", "desc": "Smoky and herbed fillet.", "price": 11.0},
22
- {"id": "B5", "name": "Veggie Stir Fry", "ingredients": "Broccoli, bell pepper, mushroom", "desc": "Mixed vegetables in garlic sauce.", "price": 8.5}
23
- ],
24
- "Desserts": [
25
- {"id": "C1", "name": "Mango Sticky Rice", "ingredients": "Mango, coconut milk, sticky rice", "desc": "Sweet tropical Thai dessert.", "price": 5.0},
26
- {"id": "C2", "name": "Taro Cake", "ingredients": "Taro, rice flour, sugar", "desc": "Soft steamed purple taro cake.", "price": 4.5},
27
- {"id": "C3", "name": "Coconut Jelly", "ingredients": "Coconut milk, gelatin, sugar", "desc": "Chilled and silky treat.", "price": 4.0},
28
- {"id": "C4", "name": "Sweet Bean Soup", "ingredients": "Red beans, citrus zest", "desc": "Warm dessert soup with a twist.", "price": 3.5},
29
- {"id": "C5", "name": "Sesame Balls", "ingredients": "Glutinous rice, sesame paste", "desc": "Fried golden and gooey.", "price": 3.5}
30
- ],
31
- "Drinks": [
32
- {"id": "D1", "name": "Lime Soda", "ingredients": "Soda, lime juice", "desc": "Zesty and refreshing cooler.", "price": 2.5},
33
- {"id": "D2", "name": "Iced Tea", "ingredients": "Black tea, lemon, sugar", "desc": "Cold brew with a citrus hint.", "price": 2.0},
34
- {"id": "D3", "name": "Coconut Water", "ingredients": "Young coconut", "desc": "Natural and hydrating.", "price": 3.0},
35
- {"id": "D4", "name": "Soy Milk", "ingredients": "Soybeans, sugar", "desc": "Sweetened and smooth.", "price": 2.0},
36
- {"id": "D5", "name": "Bottled Water", "ingredients": "Mineral water", "desc": "Sealed and clean.", "price": 1.5}
37
- ]
38
- },
39
  {"id": "A2", "name": "Dumplings", "desc": "(Pork, chives, soy sauce) – Steamed dumplings with savory filling.", "price": 5.0},
40
- {"id": "A3", "name": "Salad", "desc": "(Lettuce, tomato, cucumber) – Fresh garden salad with vinaigrette.", "price": 3.5},
41
- {"id": "A4", "name": "Tofu Skewers", "desc": "(Tofu, sesame, chili) – Grilled tofu with sweet soy glaze.", "price": 4.0},
42
- {"id": "A5", "name": "Edamame", "desc": "(Soybeans, salt) – Boiled soybeans. A healthy starter.", "price": 3.0}
43
- ],
44
- "Main Dishes": [
45
- {"id": "B1", "name": "Beef Pho", "desc": "(Beef, rice noodles, herbs) – Vietnamese soup with rich broth.", "price": 9.5},
46
- {"id": "B2", "name": "Chicken Curry", "desc": "(Chicken, coconut milk, vegetables) – Spicy curry with rice.", "price": 10.0},
47
- {"id": "B3", "name": "Fried Rice", "desc": "(Rice, egg, peas, carrots) – Classic fried rice in soy sauce.", "price": 8.0},
48
- {"id": "B4", "name": "Grilled Fish", "desc": "(White fish, lemongrass, garlic) – Smoky and herbed fillet.", "price": 11.0},
49
- {"id": "B5", "name": "Veggie Stir Fry", "desc": "(Broccoli, bell pepper, mushroom) – Mixed vegetables in garlic sauce.", "price": 8.5}
50
- ],
51
- "Desserts": [
52
- {"id": "C1", "name": "Mango Sticky Rice", "desc": "(Mango, coconut milk, sticky rice) – Sweet tropical Thai dessert.", "price": 5.0},
53
- {"id": "C2", "name": "Taro Cake", "desc": "(Taro, rice flour, sugar) – Soft steamed purple taro cake.", "price": 4.5},
54
- {"id": "C3", "name": "Coconut Jelly", "desc": "(Coconut milk, gelatin, sugar) – Chilled and silky treat.", "price": 4.0},
55
- {"id": "C4", "name": "Sweet Bean Soup", "desc": "(Red beans, citrus zest) – Warm dessert soup with a twist.", "price": 3.5},
56
- {"id": "C5", "name": "Sesame Balls", "desc": "(Glutinous rice, sesame paste) – Fried golden and gooey.", "price": 3.5}
57
- ],
58
- "Drinks": [
59
- {"id": "D1", "name": "Lime Soda", "desc": "(Soda, lime juice) – Zesty and refreshing cooler.", "price": 2.5},
60
- {"id": "D2", "name": "Iced Tea", "desc": "(Black tea, lemon, sugar) – Cold brew with a citrus hint.", "price": 2.0},
61
- {"id": "D3", "name": "Coconut Water", "desc": "(Young coconut) – Natural and hydrating.", "price": 3.0},
62
- {"id": "D4", "name": "Soy Milk", "desc": "(Soybeans, sugar) – Sweetened and smooth.", "price": 2.0},
63
- {"id": "D5", "name": "Bottled Water", "desc": "(Mineral water) – Sealed and clean.", "price": 1.5}
64
- ]
65
- },
66
- {"id": "A2", "name": "Dumplings", "desc": "Steamed dumplings filled with seasoned pork and chives. Juicy and savory.", "price": 5.0},
67
- {"id": "A3", "name": "Salad", "desc": "Fresh garden salad with lettuce, tomatoes, and vinaigrette dressing.", "price": 3.5},
68
- {"id": "A4", "name": "Tofu Skewers", "desc": "Grilled tofu skewers marinated with sesame and soy sauce.", "price": 4.0},
69
- {"id": "A5", "name": "Edamame", "desc": "Boiled soybeans lightly salted. A healthy starter.", "price": 3.0}
70
  ],
71
  "Main Dishes": [
72
- {"id": "B1", "name": "Beef Pho", "desc": "Vietnamese noodle soup with tender beef slices, herbs, and rice noodles.", "price": 9.5},
73
- {"id": "B2", "name": "Chicken Curry", "desc": "Spicy chicken curry with coconut milk and steamed rice.", "price": 10.0},
74
- {"id": "B3", "name": "Fried Rice", "desc": "Classic fried rice with egg, vegetables, and soy sauce.", "price": 8.0},
75
- {"id": "B4", "name": "Grilled Fish", "desc": "Whole fish grilled with lemongrass and garlic.", "price": 11.0},
76
- {"id": "B5", "name": "Veggie Stir Fry", "desc": "Seasonal vegetables stir-fried in a savory sauce.", "price": 8.5}
77
  ],
78
  "Desserts": [
79
- {"id": "C1", "name": "Mango Sticky Rice", "desc": "Sweet coconut sticky rice served with ripe mango.", "price": 5.0},
80
- {"id": "C2", "name": "Taro Cake", "desc": "Soft steamed taro cake made with real taro and rice flour.", "price": 4.5},
81
- {"id": "C3", "name": "Coconut Jelly", "desc": "Refreshing coconut jelly cubes served chilled.", "price": 4.0},
82
- {"id": "C4", "name": "Sweet Bean Soup", "desc": "Warm red bean soup with tapioca pearls.", "price": 3.5},
83
- {"id": "C5", "name": "Sesame Balls", "desc": "Fried glutinous rice balls with sweet sesame filling.", "price": 3.5}
84
  ],
85
  "Drinks": [
86
- {"id": "D1", "name": "Lime Soda", "desc": "Chilled soda with a splash of lime juice.", "price": 2.5},
87
- {"id": "D2", "name": "Iced Tea", "desc": "Black tea with lemon served over ice.", "price": 2.0},
88
- {"id": "D3", "name": "Coconut Water", "desc": "Natural and hydrating coconut water.", "price": 3.0},
89
- {"id": "D4", "name": "Soy Milk", "desc": "Lightly sweetened soy milk, served cold.", "price": 2.0},
90
- {"id": "D5", "name": "Bottled Water", "desc": "Still mineral water in a sealed bottle.", "price": 1.5}
91
  ]
92
  }
93
 
94
- # 图片统一使用上传的用户头像
95
- def get_image():
96
- return "user_avatar.jpg"
97
-
98
- # ========== 功能函数 ==========
99
- def record_time(start_time):
100
- duration = round(time.time() - start_time, 2)
101
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
102
- with open("decision_times.csv", "a", newline="", encoding="utf-8") as f:
103
- writer = csv.writer(f)
104
- writer.writerow([timestamp, duration])
105
- return f"✅ Thank you! Your decision time was {duration} seconds.\nPlease proceed to the next page and enter your selected item IDs."
106
-
107
- # ========== Gradio 主界面 ==========
108
- with gr.Blocks() as demo:
109
- start_time = time.time()
110
- gr.Markdown("# 📋 Digital Menu\nPlease browse the menu and decide what you'd like to order. When ready, click the button at the bottom.")
111
-
112
- with gr.Tabs():
113
- for category, items in MENU_DATA.items():
114
- with gr.Tab(label=category):
115
- for item in items:
116
- with gr.Row():
117
- gr.Image(value=get_image(), width=100, height=100, show_label=False, container=False)
118
- gr.Markdown(f"**{item['id']} - {item['name']}**
119
-
120
- 🥬 _Ingredients: {item['ingredients']}_
121
- {item['desc']}
122
-
123
- 💰 €{item['price']:.2f}")
124
-
125
- submit_btn = gr.Button("✅ I have made my selection")
126
- output_box = gr.Textbox(visible=False)
127
- submit_btn.click(fn=record_time, inputs=[gr.State(value=start_time)], outputs=output_box)
128
-
129
- # 仅开发者可见的 CSV 下载链接(非 iframe 内显示)
130
- if os.path.exists("decision_times.csv"):
131
- gr.Markdown("🔽 [Download decision_times.csv](file/decision_times.csv)")
132
-
133
- # 启动
134
- if __name__ == "__main__":
135
- demo.launch(show_api=False)
 
5
  import os
6
  import pandas as pd
7
 
8
+ # ====== 菜单数据结构(英文 + 编号) ======
9
  MENU_DATA = {
10
  "Appetizers": [
11
+ {"id": "A1", "name": "Spring Rolls", "desc": "(Cabbage, carrot, vermicelli) Crispy rolls with light soy flavor.", "price": 4.5},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  {"id": "A2", "name": "Dumplings", "desc": "(Pork, chives, soy sauce) – Steamed dumplings with savory filling.", "price": 5.0},
13
+ {"id": "A3", "name": "Salad", "desc": "(Lettuce, cucumber, tomato) – Fresh and crunchy with light dressing.", "price": 3.5},
14
+ {"id": "A4", "name": "Tofu Skewers", "desc": "(Tofu, bell pepper, teriyaki sauce) – Grilled and savory.", "price": 4.0},
15
+ {"id": "A5", "name": "Edamame", "desc": "(Soybeans, sea salt) – Simple and healthy snack.", "price": 3.0}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  ],
17
  "Main Dishes": [
18
+ {"id": "B1", "name": "Beef Pho", "desc": "(Beef, rice noodles, herbs) Classic Vietnamese soup.", "price": 9.5},
19
+ {"id": "B2", "name": "Chicken Curry", "desc": "(Chicken, curry, coconut milk) Spicy and creamy.", "price": 10.0},
20
+ {"id": "B3", "name": "Fried Rice", "desc": "(Rice, egg, vegetables) Flavorful and filling.", "price": 8.0},
21
+ {"id": "B4", "name": "Grilled Fish", "desc": "(White fish, herbs, lemon) Fresh and light.", "price": 11.0},
22
+ {"id": "B5", "name": "Veggie Stir Fry", "desc": "(Mixed vegetables, soy sauce) Colorful and healthy.", "price": 8.5}
23
  ],
24
  "Desserts": [
25
+ {"id": "C1", "name": "Mango Sticky Rice", "desc": "(Mango, coconut milk, glutinous rice) Sweet and creamy.", "price": 5.0},
26
+ {"id": "C2", "name": "Taro Cake", "desc": "(Taro, rice flour, coconut) Soft and subtly sweet.", "price": 4.5},
27
+ {"id": "C3", "name": "Coconut Jelly", "desc": "(Coconut milk, agar) Cool and refreshing.", "price": 4.0},
28
+ {"id": "C4", "name": "Sweet Bean Soup", "desc": "(Red beans, sugar, water) Warm and comforting.", "price": 3.5},
29
+ {"id": "C5", "name": "Sesame Balls", "desc": "(Rice flour, red bean paste, sesame) – Crispy and chewy.", "price": 3.5}
30
  ],
31
  "Drinks": [
32
+ {"id": "D1", "name": "Lime Soda", "desc": "(Soda, lime juice, sugar) Sparkling and citrusy.", "price": 2.5},
33
+ {"id": "D2", "name": "Iced Tea", "desc": "(Black tea, lemon) Chilled and refreshing.", "price": 2.0},
34
+ {"id": "D3", "name": "Coconut Water", "desc": "(Coconut juice) Naturally hydrating.", "price": 3.0},
35
+ {"id": "D4", "name": "Soy Milk", "desc": "(Soybeans, sugar) Smooth and slightly sweet.", "price": 2.0},
36
+ {"id": "D5", "name": "Bottled Water", "desc": "(Mineral water) Pure and simple.", "price": 1.5}
37
  ]
38
  }
39
 
40
+ # 后续将基于此数据构建展示界面,计时开始于页面加载,点击“我已选择好”时结束