DSatishchandra commited on
Commit
bc774c2
·
verified ·
1 Parent(s): e005b0b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import uuid
4
+
5
+ # Sample menu items
6
+ menu_items = [
7
+ {"id": 1, "name": "Burger", "price": 5.99},
8
+ {"id": 2, "name": "Pizza", "price": 8.99},
9
+ {"id": 3, "name": "Pasta", "price": 7.99},
10
+ {"id": 4, "name": "Salad", "price": 4.99},
11
+ {"id": 5, "name": "Soda", "price": 1.99}
12
+ ]
13
+
14
+ # Sample customer data for login (in a real system, use a database)
15
+ customers = {
16
+ "user1": {"name": "John Doe", "phone": "1234567890", "customer_id": "CUST001"},
17
+ "user2": {"name": "Jane Smith", "phone": "9876543210", "customer_id": "CUST002"}
18
+ }
19
+
20
+ # Initialize session data
21
+ session_data = {}
22
+
23
+ def login(phone):
24
+ for customer_id, details in customers.items():
25
+ if details['phone'] == phone:
26
+ session_data['customer_id'] = details['customer_id']
27
+ session_data['customer_name'] = details['name']
28
+ return f"Welcome {details['name']}!"
29
+ return "Customer not found. Please register."
30
+
31
+ def display_menu():
32
+ return "\n".join([f"{item['id']}. {item['name']} - ${item['price']}" for item in menu_items])
33
+
34
+ def add_to_cart(item_id, quantity):
35
+ cart = session_data.get('cart', [])
36
+ cart.append({"item_id": item_id, "quantity": quantity})
37
+ session_data['cart'] = cart
38
+ return f"Item added to cart. Cart has {len(cart)} item(s)."
39
+
40
+ def view_cart():
41
+ cart = session_data.get('cart', [])
42
+ cart_items = []
43
+ total_price = 0
44
+ for item in cart:
45
+ item_details = next((menu_item for menu_item in menu_items if menu_item['id'] == item['item_id']), None)
46
+ if item_details:
47
+ cart_items.append(f"{item_details['name']} x {item['quantity']} - ${item_details['price'] * item['quantity']}")
48
+ total_price += item_details['price'] * item['quantity']
49
+ return "\n".join(cart_items) + f"\nTotal Price: ${total_price}"
50
+
51
+ def proceed_to_order(table_number):
52
+ order_id = str(uuid.uuid4()) # Generate unique order ID
53
+ cart = session_data.get('cart', [])
54
+ order_details = {
55
+ "order_id": order_id,
56
+ "customer_id": session_data['customer_id'],
57
+ "customer_name": session_data['customer_name'],
58
+ "table_number": table_number,
59
+ "items": cart
60
+ }
61
+ session_data['cart'] = [] # Clear cart after order
62
+ return f"Order ID: {order_id}\nTable Number: {table_number}\nOrder Details: {order_details}"
63
+
64
+ # Gradio Interface
65
+ login_interface = gr.Interface(fn=login, inputs="text", outputs="text", title="Customer Login")
66
+ menu_interface = gr.Interface(fn=display_menu, inputs=None, outputs="text", title="Menu")
67
+ cart_interface = gr.Interface(fn=view_cart, inputs=None, outputs="text", title="Cart")
68
+ order_interface = gr.Interface(fn=proceed_to_order, inputs="text", outputs="text", title="Proceed to Order")
69
+
70
+ # Launch Gradio app
71
+ demo = gr.TabbedInterface([login_interface, menu_interface, cart_interface, order_interface], ["Login", "Menu", "Cart", "Order"])
72
+ demo.launch()
73
+