Spaces:
Running
Running
DSatishchandra
commited on
Commit
•
93d40ac
1
Parent(s):
4d8885f
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import uuid
|
3 |
|
4 |
-
# Sample menu items
|
5 |
menu_items = [
|
6 |
{"id": 1, "name": "Burger", "price": 5.99},
|
7 |
{"id": 2, "name": "Pizza", "price": 8.99},
|
@@ -51,7 +51,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,13 +87,15 @@ 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 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
97 |
|
98 |
# Gradio Interface for Signup
|
99 |
signup_interface = gr.Interface(fn=signup, inputs=["text", "text"], outputs="text", title="Signup")
|
@@ -101,16 +103,6 @@ signup_interface = gr.Interface(fn=signup, inputs=["text", "text"], outputs="tex
|
|
101 |
# Gradio Interface for Login
|
102 |
login_interface = gr.Interface(fn=login, inputs="text", outputs="text", title="Login")
|
103 |
|
104 |
-
# Gradio Interface for Menu with Add Buttons
|
105 |
-
menu_buttons = generate_menu()
|
106 |
-
menu_interface = gr.Blocks()
|
107 |
-
|
108 |
-
with menu_interface:
|
109 |
-
with gr.Row():
|
110 |
-
gr.Markdown("# Menu")
|
111 |
-
for button, function in menu_buttons:
|
112 |
-
button.click(fn=function, outputs="text")
|
113 |
-
|
114 |
# Gradio Interface for Cart
|
115 |
cart_interface = gr.Interface(fn=view_cart, inputs=None, outputs="text", title="Cart")
|
116 |
|
@@ -122,6 +114,9 @@ order_interface = gr.Interface(
|
|
122 |
title="Proceed to Order"
|
123 |
)
|
124 |
|
|
|
|
|
|
|
125 |
# Launch Gradio app with multiple tabs
|
126 |
demo = gr.TabbedInterface(
|
127 |
[signup_interface, login_interface, menu_interface, cart_interface, order_interface],
|
|
|
1 |
import gradio as gr
|
2 |
import uuid
|
3 |
|
4 |
+
# Sample menu items
|
5 |
menu_items = [
|
6 |
{"id": 1, "name": "Burger", "price": 5.99},
|
7 |
{"id": 2, "name": "Pizza", "price": 8.99},
|
|
|
51 |
session_data['cart'] = cart
|
52 |
return f"Added 1 x {selected_item['name']} to the cart."
|
53 |
|
54 |
+
# Function to view the cart
|
55 |
def view_cart():
|
56 |
if 'customer_id' not in session_data:
|
57 |
return "Please log in first to view your cart."
|
|
|
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 |
+
# Create dynamic menu buttons
|
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 |
+
button = gr.Button(f"Add {item['name']} (${item['price']:.2f})")
|
97 |
+
button.click(fn=add_to_cart, inputs=gr.Textbox(value=item["name"], visible=False), outputs=output)
|
98 |
+
return menu_interface
|
99 |
|
100 |
# Gradio Interface for Signup
|
101 |
signup_interface = gr.Interface(fn=signup, inputs=["text", "text"], outputs="text", title="Signup")
|
|
|
103 |
# Gradio Interface for Login
|
104 |
login_interface = gr.Interface(fn=login, inputs="text", outputs="text", title="Login")
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
# Gradio Interface for Cart
|
107 |
cart_interface = gr.Interface(fn=view_cart, inputs=None, outputs="text", title="Cart")
|
108 |
|
|
|
114 |
title="Proceed to Order"
|
115 |
)
|
116 |
|
117 |
+
# Generate the menu interface
|
118 |
+
menu_interface = generate_menu()
|
119 |
+
|
120 |
# Launch Gradio app with multiple tabs
|
121 |
demo = gr.TabbedInterface(
|
122 |
[signup_interface, login_interface, menu_interface, cart_interface, order_interface],
|