Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -285,26 +285,6 @@ button {
|
|
| 285 |
}
|
| 286 |
</script>
|
| 287 |
"""
|
| 288 |
-
# Authentication and Navigation Logic
|
| 289 |
-
def authenticate_user(email, password):
|
| 290 |
-
if check_credentials(email, password):
|
| 291 |
-
return gr.update(visible=False), gr.update(visible=True), ""
|
| 292 |
-
else:
|
| 293 |
-
return gr.update(visible=True), gr.update(visible=False), "Invalid email or password. Try again."
|
| 294 |
-
|
| 295 |
-
def navigate_to_signup():
|
| 296 |
-
return gr.update(visible=False), gr.update(visible=True)
|
| 297 |
-
|
| 298 |
-
def create_account(name, phone, email, password):
|
| 299 |
-
if save_user(name, phone, email, password):
|
| 300 |
-
return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
|
| 301 |
-
else:
|
| 302 |
-
return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)
|
| 303 |
-
|
| 304 |
-
def navigate_to_login():
|
| 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
|
|
@@ -337,16 +317,12 @@ def app():
|
|
| 337 |
value="All",
|
| 338 |
label="Choose a Preference",
|
| 339 |
)
|
| 340 |
-
empty_div = gr.HTML('<div style="height: 20px;"></div>')
|
| 341 |
-
|
| 342 |
-
# Output area for menu items
|
| 343 |
menu_output = gr.HTML(value=filter_menu("All"))
|
| 344 |
|
| 345 |
-
# Button to
|
| 346 |
view_cart_button = gr.Button("View Cart")
|
| 347 |
-
empty_div = gr.HTML('<div style="height: 300px;"></div>')
|
| 348 |
|
| 349 |
-
# Modal window
|
| 350 |
modal_window = gr.HTML("""
|
| 351 |
<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
|
| 352 |
<div style="text-align: right;">
|
|
@@ -377,16 +353,53 @@ def app():
|
|
| 377 |
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
|
| 378 |
</div>
|
| 379 |
""")
|
| 380 |
-
# Update menu dynamically based on preference
|
| 381 |
-
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 382 |
|
| 383 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
gr.Row([selected_preference])
|
| 385 |
gr.Row(menu_output)
|
|
|
|
| 386 |
gr.Row(modal_window)
|
| 387 |
-
gr.
|
|
|
|
| 388 |
|
| 389 |
-
|
| 390 |
with gr.Column(visible=False) as cart_section:
|
| 391 |
gr.Markdown("### Cart & Final Order Page")
|
| 392 |
|
|
@@ -403,34 +416,33 @@ def app():
|
|
| 403 |
gr.Row(final_order_output)
|
| 404 |
|
| 405 |
# Button Bindings
|
| 406 |
-
# Login Button
|
| 407 |
login_button.click(
|
| 408 |
lambda email, password: (gr.update(visible=False), gr.update(visible=True), "") if check_credentials(email, password) else (gr.update(), gr.update(), "Invalid email or password."),
|
| 409 |
inputs=[login_email, login_password],
|
| 410 |
outputs=[login_section, menu_section, login_error],
|
| 411 |
)
|
| 412 |
-
|
| 413 |
signup_button.click(
|
| 414 |
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)),
|
| 415 |
inputs=[signup_name, signup_phone, signup_email, signup_password],
|
| 416 |
outputs=[signup_message, login_section, signup_section],
|
| 417 |
)
|
| 418 |
-
|
| 419 |
go_to_signup.click(
|
| 420 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 421 |
outputs=[login_section, signup_section],
|
| 422 |
)
|
| 423 |
-
|
| 424 |
go_to_login.click(
|
| 425 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 426 |
outputs=[login_section, signup_section],
|
| 427 |
)
|
| 428 |
-
|
| 429 |
view_cart_button.click(
|
| 430 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 431 |
outputs=[menu_section, cart_section],
|
| 432 |
)
|
| 433 |
-
|
| 434 |
back_to_menu_button.click(
|
| 435 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 436 |
outputs=[menu_section, cart_section],
|
|
|
|
| 285 |
}
|
| 286 |
</script>
|
| 287 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
def app():
|
| 289 |
with gr.Blocks() as demo:
|
| 290 |
# Login Page
|
|
|
|
| 317 |
value="All",
|
| 318 |
label="Choose a Preference",
|
| 319 |
)
|
|
|
|
|
|
|
|
|
|
| 320 |
menu_output = gr.HTML(value=filter_menu("All"))
|
| 321 |
|
| 322 |
+
# Button to open cart modal
|
| 323 |
view_cart_button = gr.Button("View Cart")
|
|
|
|
| 324 |
|
| 325 |
+
# Original Modal window for items
|
| 326 |
modal_window = gr.HTML("""
|
| 327 |
<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
|
| 328 |
<div style="text-align: right;">
|
|
|
|
| 353 |
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
|
| 354 |
</div>
|
| 355 |
""")
|
|
|
|
|
|
|
| 356 |
|
| 357 |
+
# Modal window for cart
|
| 358 |
+
modal_cart = gr.HTML(
|
| 359 |
+
"""
|
| 360 |
+
<div id="cart-modal" style="display: none; position: fixed; bottom: 0; left: 0; width: 100%; background: white; z-index: 1000; border-top: 2px solid #ccc; box-shadow: 0 -2px 5px rgba(0,0,0,0.1); transition: height 0.3s ease;">
|
| 361 |
+
<div style="padding: 10px; display: flex; justify-content: space-between; align-items: center;">
|
| 362 |
+
<span style="font-size: 18px; font-weight: bold;">Your Cart</span>
|
| 363 |
+
<button id="close-cart" onclick="toggleCartModal(false)" style="background: none; border: none; font-size: 20px; cursor: pointer;">×</button>
|
| 364 |
+
</div>
|
| 365 |
+
<div id="cart-details" style="padding: 10px; max-height: 300px; overflow-y: auto;">
|
| 366 |
+
<div id="cart-content">Your cart is empty.</div>
|
| 367 |
+
<div id="final-order" style="margin-top: 20px;"></div>
|
| 368 |
+
</div>
|
| 369 |
+
</div>
|
| 370 |
+
""",
|
| 371 |
+
visible=True,
|
| 372 |
+
)
|
| 373 |
+
|
| 374 |
+
# JavaScript for toggling the modal window
|
| 375 |
+
modal_js = gr.HTML(
|
| 376 |
+
"""
|
| 377 |
+
<script>
|
| 378 |
+
function toggleCartModal(show) {
|
| 379 |
+
const cartModal = document.getElementById('cart-modal');
|
| 380 |
+
cartModal.style.display = show ? 'block' : 'none';
|
| 381 |
+
cartModal.style.height = show ? '70%' : '50px';
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
document.getElementById('view-cart-button').onclick = function() {
|
| 385 |
+
toggleCartModal(true);
|
| 386 |
+
};
|
| 387 |
+
|
| 388 |
+
document.getElementById('close-cart').onclick = function() {
|
| 389 |
+
toggleCartModal(false);
|
| 390 |
+
};
|
| 391 |
+
</script>
|
| 392 |
+
"""
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
gr.Row([selected_preference])
|
| 396 |
gr.Row(menu_output)
|
| 397 |
+
gr.Row(view_cart_button)
|
| 398 |
gr.Row(modal_window)
|
| 399 |
+
gr.Row(modal_cart)
|
| 400 |
+
gr.Row(modal_js)
|
| 401 |
|
| 402 |
+
# Cart & Final Order Page (Still accessible through navigation but modal preferred)
|
| 403 |
with gr.Column(visible=False) as cart_section:
|
| 404 |
gr.Markdown("### Cart & Final Order Page")
|
| 405 |
|
|
|
|
| 416 |
gr.Row(final_order_output)
|
| 417 |
|
| 418 |
# Button Bindings
|
|
|
|
| 419 |
login_button.click(
|
| 420 |
lambda email, password: (gr.update(visible=False), gr.update(visible=True), "") if check_credentials(email, password) else (gr.update(), gr.update(), "Invalid email or password."),
|
| 421 |
inputs=[login_email, login_password],
|
| 422 |
outputs=[login_section, menu_section, login_error],
|
| 423 |
)
|
| 424 |
+
|
| 425 |
signup_button.click(
|
| 426 |
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)),
|
| 427 |
inputs=[signup_name, signup_phone, signup_email, signup_password],
|
| 428 |
outputs=[signup_message, login_section, signup_section],
|
| 429 |
)
|
| 430 |
+
|
| 431 |
go_to_signup.click(
|
| 432 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 433 |
outputs=[login_section, signup_section],
|
| 434 |
)
|
| 435 |
+
|
| 436 |
go_to_login.click(
|
| 437 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 438 |
outputs=[login_section, signup_section],
|
| 439 |
)
|
| 440 |
+
|
| 441 |
view_cart_button.click(
|
| 442 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 443 |
outputs=[menu_section, cart_section],
|
| 444 |
)
|
| 445 |
+
|
| 446 |
back_to_menu_button.click(
|
| 447 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 448 |
outputs=[menu_section, cart_section],
|