Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -284,23 +284,6 @@ button {
|
|
| 284 |
alert("Your final order has been submitted!");
|
| 285 |
}
|
| 286 |
</script>
|
| 287 |
-
|
| 288 |
-
<script>
|
| 289 |
-
document.addEventListener("DOMContentLoaded", function () {
|
| 290 |
-
// Attach a global listener to all button clicks
|
| 291 |
-
document.body.addEventListener("click", function (event) {
|
| 292 |
-
const clickedButton = event.target;
|
| 293 |
-
if (clickedButton.innerText === "View Cart") {
|
| 294 |
-
// Wait a short delay to allow Gradio transition, then scroll to top
|
| 295 |
-
setTimeout(() => {
|
| 296 |
-
window.scrollTo({ top: 0, behavior: "smooth" });
|
| 297 |
-
}, 100);
|
| 298 |
-
}
|
| 299 |
-
});
|
| 300 |
-
});
|
| 301 |
-
</script>
|
| 302 |
-
|
| 303 |
-
|
| 304 |
"""
|
| 305 |
# Authentication and Navigation Logic
|
| 306 |
def authenticate_user(email, password):
|
|
@@ -323,7 +306,6 @@ def navigate_to_login():
|
|
| 323 |
|
| 324 |
# Gradio App
|
| 325 |
def app():
|
| 326 |
-
|
| 327 |
with gr.Blocks() as demo:
|
| 328 |
# Login Page
|
| 329 |
with gr.Column(visible=True) as login_section:
|
|
@@ -357,10 +339,10 @@ def app():
|
|
| 357 |
)
|
| 358 |
|
| 359 |
# Output area for menu items
|
| 360 |
-
menu_output = gr.HTML(value="
|
| 361 |
|
| 362 |
# Button to navigate to Cart Page
|
| 363 |
-
view_cart_button = gr.Button("View Cart"
|
| 364 |
|
| 365 |
# Modal window
|
| 366 |
modal_window = gr.HTML("""
|
|
@@ -401,7 +383,8 @@ def app():
|
|
| 401 |
gr.Row(menu_output)
|
| 402 |
gr.Row(modal_window)
|
| 403 |
gr.HTML(modal_and_cart_js)
|
| 404 |
-
|
|
|
|
| 405 |
with gr.Column(visible=False) as cart_section:
|
| 406 |
gr.Markdown("### Cart & Final Order Page")
|
| 407 |
|
|
@@ -420,59 +403,37 @@ def app():
|
|
| 420 |
# Button Bindings
|
| 421 |
# Login Button
|
| 422 |
login_button.click(
|
| 423 |
-
lambda email, password: (gr.update(visible=False), gr.update(visible=True), "")
|
| 424 |
-
if email == "test@example.com" and password == "password"
|
| 425 |
-
else (gr.update(), gr.update(), "Invalid email or password."),
|
| 426 |
inputs=[login_email, login_password],
|
| 427 |
outputs=[login_section, menu_section, login_error],
|
| 428 |
)
|
| 429 |
-
|
| 430 |
# Signup Button
|
| 431 |
signup_button.click(
|
| 432 |
-
lambda name, phone, email, password: ("Signup successful! Please login.", gr.update(visible=True), gr.update(visible=False)),
|
| 433 |
inputs=[signup_name, signup_phone, signup_email, signup_password],
|
| 434 |
outputs=[signup_message, login_section, signup_section],
|
| 435 |
)
|
| 436 |
-
|
| 437 |
# Navigate to Signup Page
|
| 438 |
go_to_signup.click(
|
| 439 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 440 |
outputs=[login_section, signup_section],
|
| 441 |
)
|
| 442 |
-
|
| 443 |
# Navigate Back to Login Page
|
| 444 |
go_to_login.click(
|
| 445 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 446 |
outputs=[login_section, signup_section],
|
| 447 |
)
|
| 448 |
-
|
| 449 |
# Navigate to Cart Page
|
| 450 |
view_cart_button.click(
|
| 451 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 452 |
outputs=[menu_section, cart_section],
|
| 453 |
)
|
| 454 |
-
|
| 455 |
# Navigate Back to Menu Page
|
| 456 |
back_to_menu_button.click(
|
| 457 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 458 |
outputs=[menu_section, cart_section],
|
| 459 |
)
|
| 460 |
|
| 461 |
-
# Inject JavaScript for Scrolling to Top
|
| 462 |
-
demo.add_component(gr.HTML("""
|
| 463 |
-
<script>
|
| 464 |
-
document.addEventListener("DOMContentLoaded", function () {
|
| 465 |
-
const viewCartButton = document.querySelector("#view-cart-button");
|
| 466 |
-
if (viewCartButton) {
|
| 467 |
-
viewCartButton.addEventListener("click", function () {
|
| 468 |
-
setTimeout(() => {
|
| 469 |
-
window.scrollTo({ top: 0, behavior: "smooth" });
|
| 470 |
-
}, 200);
|
| 471 |
-
});
|
| 472 |
-
}
|
| 473 |
-
});
|
| 474 |
-
</script>
|
| 475 |
-
"""))
|
| 476 |
return demo
|
| 477 |
|
| 478 |
if __name__ == "__main__":
|
|
|
|
| 284 |
alert("Your final order has been submitted!");
|
| 285 |
}
|
| 286 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
"""
|
| 288 |
# Authentication and Navigation Logic
|
| 289 |
def authenticate_user(email, password):
|
|
|
|
| 306 |
|
| 307 |
# Gradio App
|
| 308 |
def app():
|
|
|
|
| 309 |
with gr.Blocks() as demo:
|
| 310 |
# Login Page
|
| 311 |
with gr.Column(visible=True) as login_section:
|
|
|
|
| 339 |
)
|
| 340 |
|
| 341 |
# Output area for menu items
|
| 342 |
+
menu_output = gr.HTML(value=filter_menu("All"))
|
| 343 |
|
| 344 |
# Button to navigate to Cart Page
|
| 345 |
+
view_cart_button = gr.Button("View Cart")
|
| 346 |
|
| 347 |
# Modal window
|
| 348 |
modal_window = gr.HTML("""
|
|
|
|
| 383 |
gr.Row(menu_output)
|
| 384 |
gr.Row(modal_window)
|
| 385 |
gr.HTML(modal_and_cart_js)
|
| 386 |
+
|
| 387 |
+
# Cart & Final Order Page
|
| 388 |
with gr.Column(visible=False) as cart_section:
|
| 389 |
gr.Markdown("### Cart & Final Order Page")
|
| 390 |
|
|
|
|
| 403 |
# Button Bindings
|
| 404 |
# Login Button
|
| 405 |
login_button.click(
|
| 406 |
+
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."),
|
|
|
|
|
|
|
| 407 |
inputs=[login_email, login_password],
|
| 408 |
outputs=[login_section, menu_section, login_error],
|
| 409 |
)
|
|
|
|
| 410 |
# Signup Button
|
| 411 |
signup_button.click(
|
| 412 |
+
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)),
|
| 413 |
inputs=[signup_name, signup_phone, signup_email, signup_password],
|
| 414 |
outputs=[signup_message, login_section, signup_section],
|
| 415 |
)
|
|
|
|
| 416 |
# Navigate to Signup Page
|
| 417 |
go_to_signup.click(
|
| 418 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 419 |
outputs=[login_section, signup_section],
|
| 420 |
)
|
|
|
|
| 421 |
# Navigate Back to Login Page
|
| 422 |
go_to_login.click(
|
| 423 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 424 |
outputs=[login_section, signup_section],
|
| 425 |
)
|
|
|
|
| 426 |
# Navigate 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 |
# Navigate Back to Menu Page
|
| 432 |
back_to_menu_button.click(
|
| 433 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 434 |
outputs=[menu_section, cart_section],
|
| 435 |
)
|
| 436 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
return demo
|
| 438 |
|
| 439 |
if __name__ == "__main__":
|