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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -1
app.py CHANGED
@@ -37,4 +37,46 @@ MENU_DATA = {
37
  ]
38
  }
39
 
40
- # 后续将基于此数据构建展示界面,计时开始于页面加载,点击“我已选择好”时结束
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
47
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
48
+ with open("decision_times.csv", "a", newline="", encoding="utf-8") as f:
49
+ writer = csv.writer(f)
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()
56
+ gr.Markdown("# 📋 Digital Menu\nPlease browse the menu and decide what you'd like to order. When ready, click the button at the bottom.")
57
+
58
+ with gr.Tabs():
59
+ for category, items in MENU_DATA.items():
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, show_label=False, container=False)
64
+ gr.Markdown(f"**{item['id']} - {item['name']}**
65
+
66
+ 🥬 _Ingredients: {item['ingredients']}_
67
+ {item['desc']}
68
+
69
+ 💰 €{item['price']:.2f}")
70
+
71
+ submit_btn = gr.Button("✅ I have made my selection")
72
+ output_box = gr.Textbox(visible=False)
73
+ submit_btn.click(fn=record_time, inputs=[gr.State(value=start_time)], outputs=output_box)
74
+
75
+ # 仅开发者可见的 CSV 下载链接(非 iframe 内显示)
76
+ if os.path.exists("decision_times.csv"):
77
+ gr.Markdown("🔽 [Download decision_times.csv](file/decision_times.csv)")
78
+
79
+ # 启动
80
+ if __name__ == "__main__":
81
+ demo.launch(show_api=False)
82
+