Wanswan commited on
Commit
8687cc9
ยท
verified ยท
1 Parent(s): f3ebb28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -43
app.py CHANGED
@@ -5,42 +5,38 @@ 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": "(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
- # ๅ›พ็‰‡็ปŸไธ€ไฝฟ็”จไธŠไผ ็š„็”จๆˆทๅคดๅƒ
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,33 +46,21 @@ def record_time(start_time):
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
-
 
5
  import os
6
  import pandas as pd
7
 
8
+ # ========== ่œๅ•ๆ•ฐๆฎ็ป“ๆž„ ==========
9
  MENU_DATA = {
10
  "Appetizers": [
11
+ {"id": "A1", "name": "Spring Rolls", "desc": "(Cabbage, carrots, wrapper) โ€“ Crispy fried rolls with vegetables.", "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 vegetable salad with light dressing.", "price": 3.5},
14
+ {"id": "A4", "name": "Tofu Skewers", "desc": "(Tofu, peppers, glaze) โ€“ Grilled tofu skewers with sweet sauce.", "price": 4.0},
15
+ {"id": "A5", "name": "Edamame", "desc": "(Soybeans, salt) โ€“ Lightly boiled and salted green soybeans.", "price": 3.0},
16
  ],
17
  "Main Dishes": [
18
+ {"id": "B1", "name": "Beef Pho", "desc": "(Beef, rice noodles, herbs) โ€“ Traditional Vietnamese noodle soup.", "price": 9.5},
19
+ {"id": "B2", "name": "Chicken Curry", "desc": "(Chicken, coconut milk, curry) โ€“ Mild spicy curry with rice.", "price": 10.0},
20
+ {"id": "B3", "name": "Fried Rice", "desc": "(Rice, egg, veggies) โ€“ Wok-fried rice with soy sauce and greens.", "price": 8.0},
21
+ {"id": "B4", "name": "Grilled Fish", "desc": "(Fish, lime, herbs) โ€“ Grilled fillet with citrus-herb flavor.", "price": 11.0},
22
+ {"id": "B5", "name": "Veggie Stir Fry", "desc": "(Broccoli, carrots, tofu) โ€“ Mixed vegetables stir-fried in sauce.", "price": 8.5},
23
  ],
24
  "Desserts": [
25
+ {"id": "C1", "name": "Mango Sticky Rice", "desc": "(Mango, sticky rice, coconut) โ€“ Thai-style sweet dessert.", "price": 5.0},
26
+ {"id": "C2", "name": "Taro Cake", "desc": "(Taro, rice flour, sugar) โ€“ Soft steamed traditional treat.", "price": 4.5},
27
+ {"id": "C3", "name": "Coconut Jelly", "desc": "(Coconut milk, agar) โ€“ Light and refreshing cold dessert.", "price": 4.0},
28
+ {"id": "C4", "name": "Sweet Bean Soup", "desc": "(Red beans, sugar, tapioca) โ€“ Warm comforting dessert soup.", "price": 3.5},
29
+ {"id": "C5", "name": "Sesame Balls", "desc": "(Glutinous rice, sesame, red bean) โ€“ Crispy chewy snack.", "price": 3.5},
30
  ],
31
  "Drinks": [
32
+ {"id": "D1", "name": "Lime Soda", "desc": "(Lime, soda water, sugar) โ€“ Refreshing fizzy lime drink.", "price": 2.5},
33
+ {"id": "D2", "name": "Iced Tea", "desc": "(Black tea, lemon, ice) โ€“ Chilled lemon tea beverage.", "price": 2.0},
34
+ {"id": "D3", "name": "Coconut Water", "desc": "(Coconut juice) โ€“ Natural hydrating drink.", "price": 3.0},
35
+ {"id": "D4", "name": "Soy Milk", "desc": "(Soybeans, water, sugar) โ€“ Sweet and smooth traditional drink.", "price": 2.0},
36
+ {"id": "D5", "name": "Bottled Water", "desc": "(Mineral water) โ€“ Still bottled water.", "price": 1.5},
37
+ ],
38
  }
39
 
 
 
 
 
40
  # ========== ๅŠŸ่ƒฝๅ‡ฝๆ•ฐ ==========
41
  def record_time(start_time):
42
  duration = round(time.time() - start_time, 2)
 
46
  writer.writerow([timestamp, duration])
47
  return f"โœ… Thank you! Your decision time was {duration} seconds.\nPlease proceed to the next page and enter your selected item IDs."
48
 
49
+ # ========== Gradio ็•Œ้ข ==========
50
+ with gr.Blocks(css=".footer, .prose a {display: none !important}") as demo:
51
  start_time = time.time()
52
+ gr.Markdown("# ๐Ÿ“‹ Digital Menu\nPlease browse the menu and decide what you'd like to order.")
53
 
54
  with gr.Tabs():
55
  for category, items in MENU_DATA.items():
56
  with gr.Tab(label=category):
57
  for item in items:
58
  with gr.Row():
59
+ gr.Image(value="user_avatar.png", width=100, height=100)
60
+ gr.Markdown(f"**{item['id']} โ€“ {item['name']}** \n{item['desc']} \n๐Ÿ’ฐ โ‚ฌ{item['price']:.2f}")
 
 
 
 
 
61
 
62
  submit_btn = gr.Button("โœ… I have made my selection")
63
  output_box = gr.Textbox(visible=False)
64
  submit_btn.click(fn=record_time, inputs=[gr.State(value=start_time)], outputs=output_box)
65
 
66
+ demo.launch()