Wanswan commited on
Commit
f683bfd
·
verified ·
1 Parent(s): 23359c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -158
app.py CHANGED
@@ -5,146 +5,42 @@ 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", "desc": "Crispy rice paper rolls filled with mixed vegetables and glass noodles. Light and crunchy.", "price": 4.5},
12
  {"id": "A2", "name": "Dumplings", "desc": "Steamed dumplings filled with seasoned pork and chives. Juicy and savory.", "price": 5.0},
13
- {"id": "A3", "name": "Salad", "desc": "Fresh greens with cucumber, tomato, and sesame dressing. Light and refreshing.", "price": 3.5},
14
- {"id": "A4", "name": "Tofu Skewers", "desc": "Grilled tofu skewers with sweet chili glaze. Crispy outside, tender inside.", "price": 4.0},
15
- {"id": "A5", "name": "Edamame", "desc": "Boiled young soybeans with sea salt. Simple, healthy, and satisfying.", "price": 3.0}
16
  ],
17
  "Main Dishes": [
18
- {"id": "B1", "name": "Beef Pho", "desc": "Vietnamese noodle soup with thin-sliced beef, herbs, and rich bone broth.", "price": 9.5},
19
- {"id": "B2", "name": "Chicken Curry", "desc": "Spicy yellow curry with tender chicken, coconut milk, and vegetables. Served with rice.", "price": 10.0},
20
- {"id": "B3", "name": "Fried Rice", "desc": "Wok-fried jasmine rice with egg, carrots, and peas. Comforting and aromatic.", "price": 8.0},
21
- {"id": "B4", "name": "Grilled Fish", "desc": "Fillet of fish grilled with lemongrass and lime. Smoky and flavorful.", "price": 11.0},
22
- {"id": "B5", "name": "Veggie Stir Fry", "desc": "Mixed vegetables sautéed in garlic soy sauce. Colorful and crunchy.", "price": 8.5}
23
  ],
24
  "Desserts": [
25
- {"id": "C1", "name": "Mango Sticky Rice", "desc": "Sweet sticky rice with fresh mango and coconut cream. Thai classic dessert.", "price": 5.0},
26
- {"id": "C2", "name": "Taro Cake", "desc": "Steamed taro root cake with a soft, chewy texture. Mildly sweet.", "price": 4.5},
27
- {"id": "C3", "name": "Coconut Jelly", "desc": "Chilled coconut milk jelly, smooth and refreshing.", "price": 4.0},
28
- {"id": "C4", "name": "Sweet Bean Soup", "desc": "Warm red bean soup with a hint of citrus zest. Sweet and comforting.", "price": 3.5},
29
- {"id": "C5", "name": "Sesame Balls", "desc": "Glutinous rice balls filled with sweet bean paste, deep-fried until golden.", "price": 3.5}
30
  ],
31
  "Drinks": [
32
- {"id": "D1", "name": "Lime Soda", "desc": "Sparkling soda with fresh lime juice. Zesty and refreshing.", "price": 2.5},
33
- {"id": "D2", "name": "Iced Tea", "desc": "Chilled black tea with a splash of lemon. Lightly sweetened.", "price": 2.0},
34
- {"id": "D3", "name": "Coconut Water", "desc": "Natural young coconut juice. Pure and hydrating.", "price": 3.0},
35
- {"id": "D4", "name": "Soy Milk", "desc": "Sweetened soy milk, served cold. Nutty and smooth.", "price": 2.0},
36
- {"id": "D5", "name": "Bottled Water", "desc": "Still mineral water in a glass bottle. Clean and classic.", "price": 1.5}
37
  ]
38
- },
39
- {"id": "A2", "name": "Dumplings", "desc": "Steamed dumplings filled with seasoned pork and chives. Juicy and savory.", "price": 5.0},
40
- {"id": "A3", "name": "Salad", "desc": "Fresh greens with cucumber, tomato, and sesame dressing. Light and refreshing.", "price": 3.5},
41
- {"id": "A4", "name": "Tofu Skewers", "desc": "Grilled tofu skewers with sweet chili glaze. Crispy outside, tender inside.", "price": 4.0},
42
- {"id": "A5", "name": "Edamame", "desc": "Boiled young soybeans with sea salt. Simple, healthy, and satisfying.", "price": 3.0}
43
- ],
44
- "Main Dishes": [
45
- {"id": "B1", "name": "Beef Pho", "desc": "Vietnamese noodle soup with thin-sliced beef, herbs, and rich bone broth.", "price": 9.5},
46
- {"id": "B2", "name": "Chicken Curry", "desc": "Spicy yellow curry with tender chicken, coconut milk, and vegetables. Served with rice.", "price": 10.0},
47
- {"id": "B3", "name": "Fried Rice", "desc": "Wok-fried jasmine rice with egg, carrots, and peas. Comforting and aromatic.", "price": 8.0},
48
- {"id": "B4", "name": "Grilled Fish", "desc": "Fillet of fish grilled with lemongrass and lime. Smoky and flavorful.", "price": 11.0},
49
- {"id": "B5", "name": "Veggie Stir Fry", "desc": "Mixed vegetables sautéed in garlic soy sauce. Colorful and crunchy.", "price": 8.5}
50
- ],
51
- "Desserts": [
52
- {"id": "C1", "name": "Mango Sticky Rice", "desc": "Sweet sticky rice with fresh mango and coconut cream. Thai classic dessert.", "price": 5.0},
53
- {"id": "C2", "name": "Taro Cake", "desc": "Steamed taro root cake with a soft, chewy texture. Mildly sweet.", "price": 4.5},
54
- {"id": "C3", "name": "Coconut Jelly", "desc": "Chilled coconut milk jelly, smooth and refreshing.", "price": 4.0},
55
- {"id": "C4", "name": "Sweet Bean Soup", "desc": "Warm red bean soup with a hint of citrus zest. Sweet and comforting.", "price": 3.5},
56
- {"id": "C5", "name": "Sesame Balls", "desc": "Glutinous rice balls filled with sweet bean paste, deep-fried until golden.", "price": 3.5}
57
- ],
58
- "Drinks": [
59
- {"id": "D1", "name": "Lime Soda", "desc": "Sparkling soda with fresh lime juice. Zesty and refreshing.", "price": 2.5},
60
- {"id": "D2", "name": "Iced Tea", "desc": "Chilled black tea with a splash of lemon. Lightly sweetened.", "price": 2.0},
61
- {"id": "D3", "name": "Coconut Water", "desc": "Natural young coconut juice. Pure and hydrating.", "price": 3.0},
62
- {"id": "D4", "name": "Soy Milk", "desc": "Sweetened soy milk, served cold. Nutty and smooth.", "price": 2.0},
63
- {"id": "D5", "name": "Bottled Water", "desc": "Still mineral water in a glass bottle. Clean and classic.", "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 greens with cucumber, tomato, and sesame dressing. Light and refreshing.", "price": 3.5},
68
- {"id": "A4", "name": "Tofu Skewers", "desc": "Grilled tofu skewers with sweet chili glaze. Crispy outside, tender inside.", "price": 4.0},
69
- {"id": "A5", "name": "Edamame", "desc": "Boiled young soybeans with sea salt. Simple, healthy, and satisfying.", "price": 3.0},
70
- ],
71
- "Main Dishes": [
72
- {"id": "B1", "name": "Beef Pho", "desc": "Vietnamese noodle soup with thin-sliced beef, herbs, and rich bone broth.", "price": 9.5},
73
- {"id": "B2", "name": "Chicken Curry", "desc": "Spicy yellow curry with tender chicken, coconut milk, and vegetables. Served with rice.", "price": 10.0},
74
- {"id": "B3", "name": "Fried Rice", "desc": "Wok-fried jasmine rice with egg, carrots, and peas. Comforting and aromatic.", "price": 8.0},
75
- {"id": "B4", "name": "Grilled Fish", "desc": "Fillet of fish grilled with lemongrass and lime. Smoky and flavorful.", "price": 11.0},
76
- {"id": "B5", "name": "Veggie Stir Fry", "desc": "Mixed vegetables sautéed in garlic soy sauce. Colorful and crunchy.", "price": 8.5},
77
- ],
78
- "Desserts": [
79
- {"id": "C1", "name": "Mango Sticky Rice", "desc": "Sweet sticky rice with fresh mango and coconut cream. Thai classic dessert.", "price": 5.0},
80
- {"id": "C2", "name": "Taro Cake", "desc": "Steamed taro root cake with a soft, chewy texture. Mildly sweet.", "price": 4.5},
81
- {"id": "C3", "name": "Coconut Jelly", "desc": "Chilled coconut milk jelly, smooth and refreshing.", "price": 4.0},
82
- {"id": "C4", "name": "Sweet Bean Soup", "desc": "Warm red bean soup with a hint of citrus zest. Sweet and comforting.", "price": 3.5},
83
- {"id": "C5", "name": "Sesame Balls", "desc": "Glutinous rice balls filled with sweet bean paste, deep-fried until golden.", "price": 3.5},
84
- ],
85
- "Drinks": [
86
- {"id": "D1", "name": "Lime Soda", "desc": "Sparkling soda with fresh lime juice. Zesty and refreshing.", "price": 2.5},
87
- {"id": "D2", "name": "Iced Tea", "desc": "Chilled black tea with a splash of lemon. Lightly sweetened.", "price": 2.0},
88
- {"id": "D3", "name": "Coconut Water", "desc": "Natural young coconut juice. Pure and hydrating.", "price": 3.0},
89
- {"id": "D4", "name": "Soy Milk", "desc": "Sweetened soy milk, served cold. Nutty and smooth.", "price": 2.0},
90
- {"id": "D5", "name": "Bottled Water", "desc": "Still mineral water in a glass bottle. Clean and classic.", "price": 1.5},
91
- ],
92
- },
93
- {"id": "A2", "name": "Dumplings", "desc": "Steamed dumplings filled with seasoned pork and chives. Juicy and savory.", "price": 5.0},
94
- {"id": "A3", "name": "Salad", "desc": "Fresh greens with cucumber, tomato, and sesame dressing. Light and refreshing.", "price": 3.5},
95
- {"id": "A4", "name": "Tofu Skewers", "desc": "Grilled tofu skewers with sweet chili glaze. Crispy outside, tender inside.", "price": 4.0},
96
- {"id": "A5", "name": "Edamame", "desc": "Boiled young soybeans with sea salt. Simple, healthy, and satisfying.", "price": 3.0},
97
- ],
98
- "Main Dishes": [
99
- {"id": "B1", "name": "Beef Pho", "desc": "Vietnamese noodle soup with thin-sliced beef, herbs, and rich bone broth.", "price": 9.5},
100
- {"id": "B2", "name": "Chicken Curry", "desc": "Spicy yellow curry with tender chicken, coconut milk, and vegetables. Served with rice.", "price": 10.0},
101
- {"id": "B3", "name": "Fried Rice", "desc": "Wok-fried jasmine rice with egg, carrots, and peas. Comforting and aromatic.", "price": 8.0},
102
- {"id": "B4", "name": "Grilled Fish", "desc": "Fillet of fish grilled with lemongrass and lime. Smoky and flavorful.", "price": 11.0},
103
- {"id": "B5", "name": "Veggie Stir Fry", "desc": "Mixed vegetables sautéed in garlic soy sauce. Colorful and crunchy.", "price": 8.5},
104
- ],
105
- "Desserts": [
106
- {"id": "C1", "name": "Mango Sticky Rice", "desc": "Sweet sticky rice with fresh mango and coconut cream. Thai classic dessert.", "price": 5.0},
107
- {"id": "C2", "name": "Taro Cake", "desc": "Steamed taro root cake with a soft, chewy texture. Mildly sweet.", "price": 4.5},
108
- {"id": "C3", "name": "Coconut Jelly", "desc": "Chilled coconut milk jelly, smooth and refreshing.", "price": 4.0},
109
- {"id": "C4", "name": "Sweet Bean Soup", "desc": "Warm red bean soup with a hint of citrus zest. Sweet and comforting.", "price": 3.5},
110
- {"id": "C5", "name": "Sesame Balls", "desc": "Glutinous rice balls filled with sweet bean paste, deep-fried until golden.", "price": 3.5},
111
- ],
112
- "Drinks": [
113
- {"id": "D1", "name": "Lime Soda", "desc": "Sparkling soda with fresh lime juice. Zesty and refreshing.", "price": 2.5},
114
- {"id": "D2", "name": "Iced Tea", "desc": "Chilled black tea with a splash of lemon. Lightly sweetened.", "price": 2.0},
115
- {"id": "D3", "name": "Coconut Water", "desc": "Natural young coconut juice. Pure and hydrating.", "price": 3.0},
116
- {"id": "D4", "name": "Soy Milk", "desc": "Sweetened soy milk, served cold. Nutty and smooth.", "price": 2.0},
117
- {"id": "D5", "name": "Bottled Water", "desc": "Still mineral water in a glass bottle. Clean and classic.", "price": 1.5},
118
- ],
119
- },
120
- {"id": "A2", "name": "Dumplings", "desc": "Steamed pork dumplings", "price": 5.0},
121
- {"id": "A3", "name": "Salad", "desc": "Fresh vegetable salad", "price": 3.5},
122
- {"id": "A4", "name": "Tofu Skewers", "desc": "Grilled tofu with sauce", "price": 4.0},
123
- {"id": "A5", "name": "Edamame", "desc": "Boiled soybeans with salt", "price": 3.0},
124
- ],
125
- "Main Dishes": [
126
- {"id": "B1", "name": "Beef Pho", "desc": "Traditional Vietnamese noodle soup", "price": 9.5},
127
- {"id": "B2", "name": "Chicken Curry", "desc": "Spicy chicken curry with rice", "price": 10.0},
128
- {"id": "B3", "name": "Fried Rice", "desc": "Fried rice with egg and vegetables", "price": 8.0},
129
- {"id": "B4", "name": "Grilled Fish", "desc": "Grilled fish with herbs", "price": 11.0},
130
- {"id": "B5", "name": "Veggie Stir Fry", "desc": "Mixed vegetables stir-fried with sauce", "price": 8.5},
131
- ],
132
- "Desserts": [
133
- {"id": "C1", "name": "Mango Sticky Rice", "desc": "Sweet coconut rice with mango", "price": 5.0},
134
- {"id": "C2", "name": "Taro Cake", "desc": "Steamed taro cake", "price": 4.5},
135
- {"id": "C3", "name": "Coconut Jelly", "desc": "Chilled coconut milk jelly", "price": 4.0},
136
- {"id": "C4", "name": "Sweet Bean Soup", "desc": "Warm red bean dessert soup", "price": 3.5},
137
- {"id": "C5", "name": "Sesame Balls", "desc": "Fried sesame rice balls", "price": 3.5},
138
- ],
139
- "Drinks": [
140
- {"id": "D1", "name": "Lime Soda", "desc": "Refreshing soda with lime", "price": 2.5},
141
- {"id": "D2", "name": "Iced Tea", "desc": "Chilled black tea with lemon", "price": 2.0},
142
- {"id": "D3", "name": "Coconut Water", "desc": "Natural coconut juice", "price": 3.0},
143
- {"id": "D4", "name": "Soy Milk", "desc": "Sweetened soy milk", "price": 2.0},
144
- {"id": "D5", "name": "Bottled Water", "desc": "Still mineral water", "price": 1.5},
145
- ],
146
  }
147
 
 
 
 
 
148
  # ========== 功能函数 ==========
149
  def record_time(start_time):
150
  duration = round(time.time() - start_time, 2)
@@ -154,17 +50,6 @@ def record_time(start_time):
154
  writer.writerow([timestamp, duration])
155
  return f"✅ Thank you! Your decision time was {duration} seconds.\nPlease proceed to the next page and enter your selected item IDs."
156
 
157
- def show_csv():
158
- if not os.path.exists("decision_times.csv"):
159
- return "No data recorded yet."
160
- df = pd.read_csv("decision_times.csv", header=None, names=["Timestamp", "Duration (s)"])
161
- return df.to_markdown(index=False)
162
-
163
- def clear_csv():
164
- if os.path.exists("decision_times.csv"):
165
- os.remove("decision_times.csv")
166
- return "🧹 decision_times.csv has been cleared."
167
-
168
  # ========== Gradio 主界面 ==========
169
  with gr.Blocks() as demo:
170
  start_time = time.time()
@@ -175,27 +60,17 @@ with gr.Blocks() as demo:
175
  with gr.Tab(label=category):
176
  for item in items:
177
  with gr.Row():
178
- with gr.Column(scale=1):
179
- gr.Image(value="user_avatar.jpg", width=80, height=80, show_label=False, interactive=False)
180
- with gr.Column(scale=5):
181
- gr.Markdown(f"**{item['id']} - {item['name']}**
182
-
183
- *{item['desc']}*
184
 
185
- 💰 €{item['price']:.2f}")
186
- submit_btn = gr.Button("✅ I have made my selection")
187
- output_box = gr.Textbox(label="", lines=3, interactive=False)
188
  submit_btn.click(fn=record_time, inputs=[gr.State(value=start_time)], outputs=output_box)
189
 
190
- with gr.Accordion("📊 Admin Tools (optional)", open=False, visible=False):
191
- gr.Markdown("### View or Clear Recorded CSV Data")
192
- show_btn = gr.Button("📥 Show CSV Data")
193
- show_output = gr.Textbox(label="decision_times.csv content", lines=10)
194
- show_btn.click(fn=show_csv, outputs=show_output)
195
-
196
- clear_btn = gr.Button("🧹 Clear CSV File")
197
- clear_btn.click(fn=clear_csv, outputs=show_output)
198
 
199
- gr.Markdown("🔽 [Download decision_times.csv](file/decision_times.csv)")
 
200
  demo.launch()
201
-
 
5
  import os
6
  import pandas as pd
7
 
8
+ # ====== 菜单数据结构(英文 + 编号 + 描述) ======
9
  MENU_DATA = {
10
  "Appetizers": [
11
+ {"id": "A1", "name": "Spring Rolls", "desc": "Crispy rolls with vegetables and glass noodles. Light and crunchy.", "price": 4.5},
12
  {"id": "A2", "name": "Dumplings", "desc": "Steamed dumplings filled with seasoned pork and chives. Juicy and savory.", "price": 5.0},
13
+ {"id": "A3", "name": "Salad", "desc": "Fresh garden salad with lettuce, tomatoes, and vinaigrette dressing.", "price": 3.5},
14
+ {"id": "A4", "name": "Tofu Skewers", "desc": "Grilled tofu skewers marinated with sesame and soy sauce.", "price": 4.0},
15
+ {"id": "A5", "name": "Edamame", "desc": "Boiled soybeans lightly salted. A healthy starter.", "price": 3.0}
16
  ],
17
  "Main Dishes": [
18
+ {"id": "B1", "name": "Beef Pho", "desc": "Vietnamese noodle soup with tender beef slices, herbs, and rice noodles.", "price": 9.5},
19
+ {"id": "B2", "name": "Chicken Curry", "desc": "Spicy chicken curry with coconut milk and steamed rice.", "price": 10.0},
20
+ {"id": "B3", "name": "Fried Rice", "desc": "Classic fried rice with egg, vegetables, and soy sauce.", "price": 8.0},
21
+ {"id": "B4", "name": "Grilled Fish", "desc": "Whole fish grilled with lemongrass and garlic.", "price": 11.0},
22
+ {"id": "B5", "name": "Veggie Stir Fry", "desc": "Seasonal vegetables stir-fried in a savory sauce.", "price": 8.5}
23
  ],
24
  "Desserts": [
25
+ {"id": "C1", "name": "Mango Sticky Rice", "desc": "Sweet coconut sticky rice served with ripe mango.", "price": 5.0},
26
+ {"id": "C2", "name": "Taro Cake", "desc": "Soft steamed taro cake made with real taro and rice flour.", "price": 4.5},
27
+ {"id": "C3", "name": "Coconut Jelly", "desc": "Refreshing coconut jelly cubes served chilled.", "price": 4.0},
28
+ {"id": "C4", "name": "Sweet Bean Soup", "desc": "Warm red bean soup with tapioca pearls.", "price": 3.5},
29
+ {"id": "C5", "name": "Sesame Balls", "desc": "Fried glutinous rice balls with sweet sesame filling.", "price": 3.5}
30
  ],
31
  "Drinks": [
32
+ {"id": "D1", "name": "Lime Soda", "desc": "Chilled soda with a splash of lime juice.", "price": 2.5},
33
+ {"id": "D2", "name": "Iced Tea", "desc": "Black tea with lemon served over ice.", "price": 2.0},
34
+ {"id": "D3", "name": "Coconut Water", "desc": "Natural and hydrating coconut water.", "price": 3.0},
35
+ {"id": "D4", "name": "Soy Milk", "desc": "Lightly sweetened soy milk, served cold.", "price": 2.0},
36
+ {"id": "D5", "name": "Bottled Water", "desc": "Still mineral water in a sealed bottle.", "price": 1.5}
37
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
 
40
+ # 图片统一使用上传的用户头像
41
+ def get_image():
42
+ return "user_avatar.jpg"
43
+
44
  # ========== 功能函数 ==========
45
  def record_time(start_time):
46
  duration = round(time.time() - start_time, 2)
 
50
  writer.writerow([timestamp, duration])
51
  return f"✅ Thank you! Your decision time was {duration} seconds.\nPlease proceed to the next page and enter your selected item IDs."
52
 
 
 
 
 
 
 
 
 
 
 
 
53
  # ========== Gradio 主界面 ==========
54
  with gr.Blocks() as demo:
55
  start_time = time.time()
 
60
  with gr.Tab(label=category):
61
  for item in items:
62
  with gr.Row():
63
+ gr.Image(value=get_image(), width=100, height=100)
64
+ gr.Markdown(f"**{item['id']} - {item['name']}**\n\n{item['desc']}\n\n💰 €{item['price']:.2f}")
 
 
 
 
65
 
66
+ submit_btn = gr.Button("✅ I have made my selection")
67
+ output_box = gr.Textbox(visible=False)
 
68
  submit_btn.click(fn=record_time, inputs=[gr.State(value=start_time)], outputs=output_box)
69
 
70
+ # 仅开发者可见的 CSV 下载链接(非 iframe 内显示)
71
+ if os.path.exists("decision_times.csv"):
72
+ gr.Markdown("🔽 [Download decision_times.csv](file/decision_times.csv)")
 
 
 
 
 
73
 
74
+ # 启动
75
+ if __name__ == "__main__":
76
  demo.launch()