Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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,
|
| 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
|
| 14 |
-
{"id": "A4", "name": "Tofu Skewers", "desc": "(Tofu,
|
| 15 |
-
{"id": "A5", "name": "Edamame", "desc": "(Soybeans,
|
| 16 |
],
|
| 17 |
"Main Dishes": [
|
| 18 |
-
{"id": "B1", "name": "Beef Pho", "desc": "(Beef, rice noodles, herbs) โ
|
| 19 |
-
{"id": "B2", "name": "Chicken Curry", "desc": "(Chicken,
|
| 20 |
-
{"id": "B3", "name": "Fried Rice", "desc": "(Rice, egg,
|
| 21 |
-
{"id": "B4", "name": "Grilled Fish", "desc": "(
|
| 22 |
-
{"id": "B5", "name": "Veggie Stir Fry", "desc": "(
|
| 23 |
],
|
| 24 |
"Desserts": [
|
| 25 |
-
{"id": "C1", "name": "Mango Sticky Rice", "desc": "(Mango,
|
| 26 |
-
{"id": "C2", "name": "Taro Cake", "desc": "(Taro, rice flour,
|
| 27 |
-
{"id": "C3", "name": "Coconut Jelly", "desc": "(Coconut milk, agar) โ
|
| 28 |
-
{"id": "C4", "name": "Sweet Bean Soup", "desc": "(Red beans, sugar,
|
| 29 |
-
{"id": "C5", "name": "Sesame Balls", "desc": "(
|
| 30 |
],
|
| 31 |
"Drinks": [
|
| 32 |
-
{"id": "D1", "name": "Lime Soda", "desc": "(
|
| 33 |
-
{"id": "D2", "name": "Iced Tea", "desc": "(Black tea, lemon) โ Chilled
|
| 34 |
-
{"id": "D3", "name": "Coconut Water", "desc": "(Coconut juice) โ
|
| 35 |
-
{"id": "D4", "name": "Soy Milk", "desc": "(Soybeans, sugar) โ
|
| 36 |
-
{"id": "D5", "name": "Bottled Water", "desc": "(Mineral water) โ
|
| 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.
|
| 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=
|
| 64 |
-
gr.Markdown(f"**{item['id']}
|
| 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 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|