Rammohan0504 commited on
Commit
ba02d64
Β·
verified Β·
1 Parent(s): ecf809d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -88
app.py CHANGED
@@ -1,71 +1,12 @@
1
-
2
  import gradio as gr
3
 
4
  # Menu data
5
  menu_data = [
6
- {"name": "Veg Burger", "category": "VEGAN",
7
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
8
- "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
9
- "price": "$8.99"},
10
- {"name": "Chicken Biryani", "category": "HALAL",
11
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg",
12
- "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
13
- "price": "$12.99"},
14
- {"name": "Margherita Pizza", "category": "VEGAN",
15
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/margherita_pizza.jpg",
16
- "description": "Classic pizza topped with fresh tomatoes, basil, and vegan mozzarella.",
17
- "price": "$9.99"},
18
- {"name": "Lamb Kebabs", "category": "HALAL",
19
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/lamb_kebabs.jpg",
20
- "description": "Succulent lamb kebabs grilled to perfection, served with mint yogurt dip.",
21
- "price": "$14.99"},
22
- {"name": "Quinoa Salad", "category": "GUILT-FREE",
23
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/quinoa_salad.jpg",
24
- "description": "Healthy quinoa salad with fresh vegetables, olive oil, and a lemon dressing.",
25
- "price": "$7.99"},
26
- {"name": "Paneer Butter Masala", "category": "VEGETARIAN",
27
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg",
28
- "description": "Rich and creamy paneer butter masala served with naan or rice.",
29
- "price": "$11.99"},
30
- {"name": "Classic Caesar Salad", "category": "GUILT-FREE",
31
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/caesar_salad.jpg",
32
- "description": "Fresh romaine lettuce, croutons, and Parmesan cheese with Caesar dressing.",
33
- "price": "$6.99"},
34
- {"name": "Beef Steak", "category": "HALAL",
35
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/beef_steak.jpg",
36
- "description": "Juicy grilled beef steak with herb butter and garlic mashed potatoes.",
37
- "price": "$19.99"},
38
- {"name": "Tofu Stir Fry", "category": "VEGAN",
39
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/tofu_stir_fry.jpg",
40
- "description": "Flavorful tofu stir fry with mixed vegetables and soy-ginger sauce.",
41
- "price": "$10.99"},
42
- {"name": "Butter Chicken", "category": "HALAL",
43
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/butter_chicken.jpg",
44
- "description": "Classic butter chicken in a rich tomato and cream gravy, served with naan.",
45
- "price": "$13.99"},
46
- {"name": "Grilled Salmon", "category": "GUILT-FREE",
47
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/grilled_salmon.jpg",
48
- "description": "Perfectly grilled salmon with lemon and herbs, served with steamed veggies.",
49
- "price": "$16.99"},
50
- {"name": "Chocolate Lava Cake", "category": "DESSERT",
51
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chocolate_lava_cake.jpg",
52
- "description": "Warm chocolate cake with a gooey molten chocolate center.",
53
- "price": "$5.99"},
54
- {"name": "Ice Cream Sundae", "category": "DESSERT",
55
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/ice_cream_sundae.jpg",
56
- "description": "Creamy vanilla ice cream topped with chocolate sauce, nuts, and a cherry.",
57
- "price": "$4.99"},
58
- {"name": "Pasta Primavera", "category": "VEGETARIAN",
59
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/pasta_primavera.jpg",
60
- "description": "Fresh pasta with seasonal vegetables in a light garlic sauce.",
61
- "price": "$9.99"},
62
- {"name": "Shawarma Wrap", "category": "HALAL",
63
- "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/shawarma_wrap.jpg",
64
- "description": "Savory chicken shawarma wrap with tahini sauce and fresh veggies.",
65
- "price": "$8.99"}
66
  ]
67
 
68
-
69
  # Cart data (persistent across sessions)
70
  cart_items = []
71
 
@@ -77,13 +18,36 @@ extras = [
77
  {"name": "Extra Salan 8oz", "price": "$2.00"},
78
  ]
79
 
80
- # Filter dishes by category
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  def filter_dishes(category):
82
  if category == "ALL":
83
  return menu_data
84
  return [dish for dish in menu_data if dish["category"] == category]
85
 
86
- # Generate dish cards with "Add" button
87
  def display_dishes(category):
88
  filtered_dishes = filter_dishes(category)
89
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%; overflow-y: auto;'>"
@@ -109,29 +73,6 @@ def display_dishes(category):
109
  html_content += "</div>"
110
  return html_content
111
 
112
- # Function to handle adding items to the cart
113
- def add_to_cart(dish_name, selected_extras, quantity, custom_description):
114
- cart_items.append({
115
- "name": dish_name,
116
- "extras": selected_extras,
117
- "quantity": quantity,
118
- "custom_description": custom_description
119
- })
120
- return update_cart()
121
-
122
- # Update cart display
123
- def update_cart():
124
- if not cart_items:
125
- return "<p>Your cart is empty.</p>"
126
- html_content = "<h3>Cart Items</h3><ul style='list-style-type: none; padding: 0;'>"
127
- for item in cart_items:
128
- extras = ", ".join(item["extras"])
129
- html_content += f"<li style='margin-bottom: 10px;'><strong>{item['name']}</strong> (x{item['quantity']})<br>"
130
- html_content += f"Extras: {extras if extras else 'None'}<br>"
131
- html_content += f"Note: {item['custom_description']}</li>"
132
- html_content += "</ul>"
133
- return html_content
134
-
135
  # Main Gradio App
136
  with gr.Blocks() as demo:
137
  gr.HTML("<h1 style='text-align: center; color: #333;'>πŸ› Dynamic Menu with Cart πŸ›</h1>")
@@ -230,4 +171,4 @@ with gr.Blocks() as demo:
230
  </script>
231
  """)
232
 
233
- demo.launch()
 
 
1
  import gradio as gr
2
 
3
  # Menu data
4
  menu_data = [
5
+ {"name": "Veg Burger", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg", "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.", "price": "$8.99"},
6
+ {"name": "Chicken Biryani", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg", "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.", "price": "$12.99"},
7
+ # Add other items as needed...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  ]
9
 
 
10
  # Cart data (persistent across sessions)
11
  cart_items = []
12
 
 
18
  {"name": "Extra Salan 8oz", "price": "$2.00"},
19
  ]
20
 
21
+ # Function to handle adding items to the cart
22
+ def add_to_cart(dish_name, selected_extras, quantity, custom_description):
23
+ cart_items.append({
24
+ "name": dish_name,
25
+ "extras": selected_extras,
26
+ "quantity": quantity,
27
+ "custom_description": custom_description
28
+ })
29
+ return update_cart()
30
+
31
+ # Update cart display
32
+ def update_cart():
33
+ if not cart_items:
34
+ return "<p>Your cart is empty.</p>"
35
+ html_content = "<h3>Cart Items</h3><ul style='list-style-type: none; padding: 0;'>"
36
+ for item in cart_items:
37
+ extras = ", ".join(item["extras"])
38
+ html_content += f"<li style='margin-bottom: 10px;'><strong>{item['name']}</strong> (x{item['quantity']})<br>"
39
+ html_content += f"Extras: {extras if extras else 'None'}<br>"
40
+ html_content += f"Note: {item['custom_description']}</li>"
41
+ html_content += "</ul>"
42
+ return html_content
43
+
44
+ # Function to filter dishes by category
45
  def filter_dishes(category):
46
  if category == "ALL":
47
  return menu_data
48
  return [dish for dish in menu_data if dish["category"] == category]
49
 
50
+ # Function to display dishes
51
  def display_dishes(category):
52
  filtered_dishes = filter_dishes(category)
53
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%; overflow-y: auto;'>"
 
73
  html_content += "</div>"
74
  return html_content
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  # Main Gradio App
77
  with gr.Blocks() as demo:
78
  gr.HTML("<h1 style='text-align: center; color: #333;'>πŸ› Dynamic Menu with Cart πŸ›</h1>")
 
171
  </script>
172
  """)
173
 
174
+ demo.launch()