Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -72,7 +72,7 @@ def filter_menu(preference):
|
|
72 |
</div>
|
73 |
<div style="flex-shrink: 0; text-align: center;">
|
74 |
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
|
75 |
-
<button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}')">Add</button>
|
76 |
</div>
|
77 |
</div>
|
78 |
"""
|
@@ -87,7 +87,6 @@ modal_and_cart_js = """
|
|
87 |
flex-direction: column;
|
88 |
gap: 10px; /* Add space between cart items */
|
89 |
}
|
90 |
-
|
91 |
.cart-item {
|
92 |
display: flex;
|
93 |
flex-wrap: wrap; /* Wrap content to the next line if needed */
|
@@ -99,19 +98,16 @@ modal_and_cart_js = """
|
|
99 |
border-radius: 5px;
|
100 |
background-color: #f9f9f9;
|
101 |
}
|
102 |
-
|
103 |
.cart-item span {
|
104 |
margin-right: 10px;
|
105 |
flex: 1; /* Allow text to take available space */
|
106 |
min-width: 50px; /* Prevent collapsing */
|
107 |
}
|
108 |
-
|
109 |
.cart-item .quantity-container {
|
110 |
display: flex;
|
111 |
align-items: center;
|
112 |
gap: 5px;
|
113 |
}
|
114 |
-
|
115 |
.cart-item button {
|
116 |
background-color: red;
|
117 |
color: white;
|
@@ -121,13 +117,11 @@ modal_and_cart_js = """
|
|
121 |
border-radius: 5px;
|
122 |
flex-shrink: 0; /* Prevent the button from shrinking */
|
123 |
}
|
124 |
-
|
125 |
.cart-total {
|
126 |
font-size: 1.2em;
|
127 |
font-weight: bold;
|
128 |
text-align: center;
|
129 |
}
|
130 |
-
|
131 |
button {
|
132 |
margin-top: 10px;
|
133 |
background-color: #007bff;
|
@@ -138,7 +132,6 @@ button {
|
|
138 |
width: 100%;
|
139 |
cursor: pointer;
|
140 |
}
|
141 |
-
|
142 |
@media (max-width: 768px) {
|
143 |
.cart-item {
|
144 |
flex-direction: column; /* Stack items on mobile */
|
@@ -149,7 +142,6 @@ button {
|
|
149 |
margin-top: 5px; /* Add some space on top */
|
150 |
}
|
151 |
}
|
152 |
-
|
153 |
</style>
|
154 |
<script>
|
155 |
let cart = [];
|
@@ -159,11 +151,11 @@ button {
|
|
159 |
"Extra Raitha": 1,
|
160 |
"Extra Salan": 2,
|
161 |
"Extra Onion & Lemon": 2,
|
162 |
-
"
|
163 |
"Veg Manchurian": 12
|
164 |
};
|
165 |
let finalized = false;
|
166 |
-
function openModal(name,
|
167 |
if (finalized) {
|
168 |
alert("You cannot add more items after finalizing your order.");
|
169 |
return;
|
@@ -180,7 +172,7 @@ button {
|
|
180 |
}
|
181 |
modal.style.left = '50%';
|
182 |
modal.style.transform = 'translate(-50%, -50%)';
|
183 |
-
document.getElementById('modal-image').src =
|
184 |
document.getElementById('modal-name').innerText = name;
|
185 |
document.getElementById('modal-description').innerText = description;
|
186 |
document.getElementById('modal-price').innerText = price;
|
@@ -313,7 +305,6 @@ def navigate_to_login():
|
|
313 |
return gr.update(visible=True), gr.update(visible=False)
|
314 |
|
315 |
# Gradio App
|
316 |
-
|
317 |
def app():
|
318 |
with gr.Blocks() as demo:
|
319 |
# Login Page
|
@@ -338,22 +329,24 @@ def app():
|
|
338 |
|
339 |
# Menu Page
|
340 |
with gr.Column(visible=False) as menu_section:
|
341 |
-
gr.Markdown("### Menu Page")
|
|
|
|
|
342 |
selected_preference = gr.Radio(
|
343 |
-
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt
|
344 |
value="All",
|
345 |
label="Choose a Preference",
|
346 |
)
|
347 |
-
|
348 |
-
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
349 |
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
final_order_output = gr.HTML(value="", elem_id="final-order")
|
356 |
-
|
|
|
357 |
|
358 |
|
359 |
|
@@ -395,9 +388,15 @@ def app():
|
|
395 |
gr.Row([selected_preference])
|
396 |
gr.Row(menu_output)
|
397 |
gr.Row(cart_output)
|
|
|
398 |
gr.Row(modal_window)
|
399 |
gr.Row(final_order_output)
|
400 |
gr.HTML(modal_and_cart_js)
|
|
|
|
|
|
|
|
|
|
|
401 |
|
402 |
# Button Bindings
|
403 |
# Button Logic
|
@@ -406,39 +405,26 @@ def app():
|
|
406 |
inputs=[login_email, login_password],
|
407 |
outputs=[login_section, menu_section, login_error],
|
408 |
)
|
409 |
-
|
410 |
go_to_signup.click(
|
411 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
412 |
outputs=[login_section, signup_section],
|
413 |
)
|
414 |
-
|
415 |
signup_button.click(
|
416 |
lambda name, phone, email, password: ("Signup successful! Please login.", gr.update(visible=True), gr.update(visible=False)) if save_user(name, phone, email, password) else ("Email already exists.", gr.update(visible=False), gr.update(visible=True)),
|
417 |
inputs=[signup_name, signup_phone, signup_email, signup_password],
|
418 |
outputs=[signup_message, login_section, signup_section],
|
419 |
)
|
420 |
-
|
421 |
go_to_login.click(
|
422 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
423 |
outputs=[login_section, signup_section],
|
424 |
)
|
425 |
-
|
426 |
-
# Navigation to Cart Page
|
427 |
view_cart_button.click(
|
428 |
-
lambda: (gr.update(visible=False), gr.update(visible=True)
|
429 |
-
outputs=[menu_section, cart_section
|
430 |
-
)
|
431 |
-
|
432 |
-
# Submit Order Logic
|
433 |
-
submit_order_button.click(
|
434 |
-
lambda: generate_final_order([
|
435 |
-
{"name": "Biryani", "quantity": 2, "total_price": 20.00},
|
436 |
-
{"name": "Veg Manchurian", "quantity": 1, "total_price": 12.00},
|
437 |
-
]),
|
438 |
-
outputs=[final_order_output],
|
439 |
)
|
440 |
|
441 |
-
# Back to Menu
|
442 |
back_to_menu_button.click(
|
443 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
444 |
outputs=[menu_section, cart_section],
|
|
|
72 |
</div>
|
73 |
<div style="flex-shrink: 0; text-align: center;">
|
74 |
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
|
75 |
+
<button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="openModal('{item['Dish Name']}', '{item['Image 2 URL']}', '{item['Description']}', '{item['Price ($)']}')">Add</button>
|
76 |
</div>
|
77 |
</div>
|
78 |
"""
|
|
|
87 |
flex-direction: column;
|
88 |
gap: 10px; /* Add space between cart items */
|
89 |
}
|
|
|
90 |
.cart-item {
|
91 |
display: flex;
|
92 |
flex-wrap: wrap; /* Wrap content to the next line if needed */
|
|
|
98 |
border-radius: 5px;
|
99 |
background-color: #f9f9f9;
|
100 |
}
|
|
|
101 |
.cart-item span {
|
102 |
margin-right: 10px;
|
103 |
flex: 1; /* Allow text to take available space */
|
104 |
min-width: 50px; /* Prevent collapsing */
|
105 |
}
|
|
|
106 |
.cart-item .quantity-container {
|
107 |
display: flex;
|
108 |
align-items: center;
|
109 |
gap: 5px;
|
110 |
}
|
|
|
111 |
.cart-item button {
|
112 |
background-color: red;
|
113 |
color: white;
|
|
|
117 |
border-radius: 5px;
|
118 |
flex-shrink: 0; /* Prevent the button from shrinking */
|
119 |
}
|
|
|
120 |
.cart-total {
|
121 |
font-size: 1.2em;
|
122 |
font-weight: bold;
|
123 |
text-align: center;
|
124 |
}
|
|
|
125 |
button {
|
126 |
margin-top: 10px;
|
127 |
background-color: #007bff;
|
|
|
132 |
width: 100%;
|
133 |
cursor: pointer;
|
134 |
}
|
|
|
135 |
@media (max-width: 768px) {
|
136 |
.cart-item {
|
137 |
flex-direction: column; /* Stack items on mobile */
|
|
|
142 |
margin-top: 5px; /* Add some space on top */
|
143 |
}
|
144 |
}
|
|
|
145 |
</style>
|
146 |
<script>
|
147 |
let cart = [];
|
|
|
151 |
"Extra Raitha": 1,
|
152 |
"Extra Salan": 2,
|
153 |
"Extra Onion & Lemon": 2,
|
154 |
+
"Chilli Chicken": 14,
|
155 |
"Veg Manchurian": 12
|
156 |
};
|
157 |
let finalized = false;
|
158 |
+
function openModal(name, image2, description, price) {
|
159 |
if (finalized) {
|
160 |
alert("You cannot add more items after finalizing your order.");
|
161 |
return;
|
|
|
172 |
}
|
173 |
modal.style.left = '50%';
|
174 |
modal.style.transform = 'translate(-50%, -50%)';
|
175 |
+
document.getElementById('modal-image').src = image2;
|
176 |
document.getElementById('modal-name').innerText = name;
|
177 |
document.getElementById('modal-description').innerText = description;
|
178 |
document.getElementById('modal-price').innerText = price;
|
|
|
305 |
return gr.update(visible=True), gr.update(visible=False)
|
306 |
|
307 |
# Gradio App
|
|
|
308 |
def app():
|
309 |
with gr.Blocks() as demo:
|
310 |
# Login Page
|
|
|
329 |
|
330 |
# Menu Page
|
331 |
with gr.Column(visible=False) as menu_section:
|
332 |
+
gr.Markdown("### Menu Page (Accessible Only After Login)")
|
333 |
+
|
334 |
+
# Radio button for selecting preference
|
335 |
selected_preference = gr.Radio(
|
336 |
+
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt Free"],
|
337 |
value="All",
|
338 |
label="Choose a Preference",
|
339 |
)
|
340 |
+
|
|
|
341 |
|
342 |
+
|
343 |
+
# Output area for menu items
|
344 |
+
menu_output = gr.HTML(value=filter_menu("All"))
|
345 |
+
# Floating cart display
|
346 |
+
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
347 |
final_order_output = gr.HTML(value="", elem_id="final-order")
|
348 |
+
|
349 |
+
view_cart_button = gr.Button("View Cart")
|
350 |
|
351 |
|
352 |
|
|
|
388 |
gr.Row([selected_preference])
|
389 |
gr.Row(menu_output)
|
390 |
gr.Row(cart_output)
|
391 |
+
gr.Row(view_cart_button)
|
392 |
gr.Row(modal_window)
|
393 |
gr.Row(final_order_output)
|
394 |
gr.HTML(modal_and_cart_js)
|
395 |
+
with gr.Column(visible=False) as cart_section:
|
396 |
+
gr.Markdown("### Your Cart")
|
397 |
+
gr.Row(cart_output) # Displays the cart contents
|
398 |
+
gr.Row(final_order_output) # Displays the final order summary
|
399 |
+
back_to_menu_button = gr.Button("Back to Menu")
|
400 |
|
401 |
# Button Bindings
|
402 |
# Button Logic
|
|
|
405 |
inputs=[login_email, login_password],
|
406 |
outputs=[login_section, menu_section, login_error],
|
407 |
)
|
|
|
408 |
go_to_signup.click(
|
409 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
410 |
outputs=[login_section, signup_section],
|
411 |
)
|
|
|
412 |
signup_button.click(
|
413 |
lambda name, phone, email, password: ("Signup successful! Please login.", gr.update(visible=True), gr.update(visible=False)) if save_user(name, phone, email, password) else ("Email already exists.", gr.update(visible=False), gr.update(visible=True)),
|
414 |
inputs=[signup_name, signup_phone, signup_email, signup_password],
|
415 |
outputs=[signup_message, login_section, signup_section],
|
416 |
)
|
|
|
417 |
go_to_login.click(
|
418 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
419 |
outputs=[login_section, signup_section],
|
420 |
)
|
421 |
+
# Logic for View Cart Button
|
|
|
422 |
view_cart_button.click(
|
423 |
+
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
424 |
+
outputs=[menu_section, cart_section],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
)
|
426 |
|
427 |
+
# Logic for Back to Menu Button
|
428 |
back_to_menu_button.click(
|
429 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
430 |
outputs=[menu_section, cart_section],
|