Spaces:
Running
Running
DSatishchandra
commited on
Commit
•
e424940
1
Parent(s):
93d40ac
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
import uuid
|
|
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
customers =
|
15 |
session_data = {}
|
16 |
|
17 |
# Function for user signup
|
@@ -23,6 +31,8 @@ def signup(name, phone):
|
|
23 |
customer_id = f"CUST{str(uuid.uuid4().int)[:6]}"
|
24 |
customers[phone] = {"name": name, "phone": phone, "customer_id": customer_id}
|
25 |
|
|
|
|
|
26 |
return f"Signup successful! Welcome {name}. Your customer ID is {customer_id}."
|
27 |
|
28 |
# Function for user login
|
@@ -51,7 +61,7 @@ def add_to_cart(item_name):
|
|
51 |
session_data['cart'] = cart
|
52 |
return f"Added 1 x {selected_item['name']} to the cart."
|
53 |
|
54 |
-
# Function to
|
55 |
def view_cart():
|
56 |
if 'customer_id' not in session_data:
|
57 |
return "Please log in first to view your cart."
|
@@ -87,14 +97,29 @@ def proceed_to_order(table_number):
|
|
87 |
session_data['cart'] = [] # Clear cart after order
|
88 |
return f"Order placed successfully!\n\nOrder ID: {order_id}\nTable Number: {table_number}\n\nOrder Details:\n" + "\n".join([f"{item['name']} x {item['quantity']} - ${item['price']:.2f}" for item in cart])
|
89 |
|
90 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
def generate_menu():
|
92 |
with gr.Blocks() as menu_interface:
|
93 |
gr.Markdown("# Menu")
|
94 |
output = gr.Textbox(label="Status")
|
95 |
for item in menu_items:
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
return menu_interface
|
99 |
|
100 |
# Gradio Interface for Signup
|
|
|
1 |
import gradio as gr
|
2 |
import uuid
|
3 |
+
import json
|
4 |
+
import os
|
5 |
|
6 |
+
# File to store registered user data
|
7 |
+
USER_DATA_FILE = "users.json"
|
8 |
+
|
9 |
+
# Load user data from the file
|
10 |
+
def load_user_data():
|
11 |
+
if os.path.exists(USER_DATA_FILE):
|
12 |
+
with open(USER_DATA_FILE, "r") as file:
|
13 |
+
return json.load(file)
|
14 |
+
return {}
|
15 |
+
|
16 |
+
# Save user data to the file
|
17 |
+
def save_user_data(data):
|
18 |
+
with open(USER_DATA_FILE, "w") as file:
|
19 |
+
json.dump(data, file, indent=4)
|
20 |
|
21 |
+
# Initialize user database
|
22 |
+
customers = load_user_data()
|
23 |
session_data = {}
|
24 |
|
25 |
# Function for user signup
|
|
|
31 |
customer_id = f"CUST{str(uuid.uuid4().int)[:6]}"
|
32 |
customers[phone] = {"name": name, "phone": phone, "customer_id": customer_id}
|
33 |
|
34 |
+
# Save the updated user data
|
35 |
+
save_user_data(customers)
|
36 |
return f"Signup successful! Welcome {name}. Your customer ID is {customer_id}."
|
37 |
|
38 |
# Function for user login
|
|
|
61 |
session_data['cart'] = cart
|
62 |
return f"Added 1 x {selected_item['name']} to the cart."
|
63 |
|
64 |
+
# Function to display the cart
|
65 |
def view_cart():
|
66 |
if 'customer_id' not in session_data:
|
67 |
return "Please log in first to view your cart."
|
|
|
97 |
session_data['cart'] = [] # Clear cart after order
|
98 |
return f"Order placed successfully!\n\nOrder ID: {order_id}\nTable Number: {table_number}\n\nOrder Details:\n" + "\n".join([f"{item['name']} x {item['quantity']} - ${item['price']:.2f}" for item in cart])
|
99 |
|
100 |
+
# Sample menu items
|
101 |
+
menu_items = [
|
102 |
+
{"id": 1, "name": "Burger", "price": 5.99, "description": "Juicy grilled burger with fresh veggies."},
|
103 |
+
{"id": 2, "name": "Pizza", "price": 8.99, "description": "Cheesy pizza with a choice of toppings."},
|
104 |
+
{"id": 3, "name": "Pasta", "price": 7.99, "description": "Creamy Italian pasta with garlic bread."},
|
105 |
+
{"id": 4, "name": "Salad", "price": 4.99, "description": "Fresh garden salad with vinaigrette dressing."},
|
106 |
+
{"id": 5, "name": "Soda", "price": 1.99, "description": "Refreshing chilled soda of your choice."}
|
107 |
+
]
|
108 |
+
|
109 |
+
# Function to generate the styled menu
|
110 |
def generate_menu():
|
111 |
with gr.Blocks() as menu_interface:
|
112 |
gr.Markdown("# Menu")
|
113 |
output = gr.Textbox(label="Status")
|
114 |
for item in menu_items:
|
115 |
+
with gr.Row():
|
116 |
+
with gr.Column(scale=4):
|
117 |
+
gr.Markdown(f"### {item['name']}\n{item['description']}\n**Price:** ${item['price']:.2f}")
|
118 |
+
with gr.Column(scale=1):
|
119 |
+
button = gr.Button("Add")
|
120 |
+
button.click(fn=add_to_cart, inputs=gr.Textbox(value=item["name"], visible=False), outputs=output)
|
121 |
+
gr.Markdown("### Status")
|
122 |
+
output.render()
|
123 |
return menu_interface
|
124 |
|
125 |
# Gradio Interface for Signup
|