Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -341,10 +341,24 @@ def app():
|
|
| 341 |
# Output area for menu items
|
| 342 |
menu_output = gr.HTML(value=filter_menu("All"))
|
| 343 |
|
| 344 |
-
#
|
| 345 |
-
view_cart_button = gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
|
| 347 |
-
# Modal window
|
| 348 |
modal_window = gr.HTML("""
|
| 349 |
<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;">
|
| 350 |
<div style="text-align: right;">
|
|
@@ -374,32 +388,100 @@ def app():
|
|
| 374 |
<!-- Add to Cart Button -->
|
| 375 |
<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>
|
| 376 |
</div>
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
|
| 381 |
-
|
| 382 |
gr.Row([selected_preference])
|
| 383 |
gr.Row(menu_output)
|
| 384 |
gr.Row(modal_window)
|
| 385 |
-
gr.
|
|
|
|
| 386 |
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
|
|
|
|
|
|
|
|
|
| 390 |
|
| 391 |
-
|
| 392 |
-
|
|
|
|
| 393 |
|
| 394 |
-
|
| 395 |
-
|
|
|
|
|
|
|
| 396 |
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
|
|
|
|
|
|
|
| 403 |
# Button Bindings
|
| 404 |
# Login Button
|
| 405 |
login_button.click(
|
|
@@ -423,18 +505,42 @@ def app():
|
|
| 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__":
|
| 440 |
app().launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
# Output area for menu items
|
| 342 |
menu_output = gr.HTML(value=filter_menu("All"))
|
| 343 |
|
| 344 |
+
# Floating "View Cart" Button
|
| 345 |
+
view_cart_button = gr.HTML('''
|
| 346 |
+
<div id="view-cart-button" style="
|
| 347 |
+
position: fixed;
|
| 348 |
+
bottom: 20px;
|
| 349 |
+
right: 20px;
|
| 350 |
+
z-index: 1000;
|
| 351 |
+
background-color: #007bff;
|
| 352 |
+
color: white;
|
| 353 |
+
border-radius: 50px;
|
| 354 |
+
padding: 10px 20px;
|
| 355 |
+
font-size: 16px;
|
| 356 |
+
cursor: pointer;
|
| 357 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
|
| 358 |
+
" onclick="openCartModal()">View Cart</div>
|
| 359 |
+
''')
|
| 360 |
|
| 361 |
+
# Modal window for item customization
|
| 362 |
modal_window = gr.HTML("""
|
| 363 |
<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;">
|
| 364 |
<div style="text-align: right;">
|
|
|
|
| 388 |
<!-- Add to Cart Button -->
|
| 389 |
<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>
|
| 390 |
</div>
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
# Modal for Cart Details
|
| 394 |
+
cart_modal = gr.HTML('''
|
| 395 |
+
<div id="cart-modal" style="
|
| 396 |
+
display: none;
|
| 397 |
+
position: fixed;
|
| 398 |
+
top: 0;
|
| 399 |
+
left: 0;
|
| 400 |
+
width: 100%;
|
| 401 |
+
height: 100%;
|
| 402 |
+
background-color: rgba(0, 0, 0, 0.5);
|
| 403 |
+
z-index: 1100;
|
| 404 |
+
">
|
| 405 |
+
<div style="
|
| 406 |
+
position: absolute;
|
| 407 |
+
bottom: 0;
|
| 408 |
+
left: 0;
|
| 409 |
+
width: 100%;
|
| 410 |
+
background: white;
|
| 411 |
+
border-radius: 20px 20px 0 0;
|
| 412 |
+
padding: 20px;
|
| 413 |
+
max-height: 70%;
|
| 414 |
+
overflow-y: auto;
|
| 415 |
+
box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.2);
|
| 416 |
+
">
|
| 417 |
+
<button onclick="closeCartModal()" style="
|
| 418 |
+
float: right;
|
| 419 |
+
background: none;
|
| 420 |
+
border: none;
|
| 421 |
+
font-size: 20px;
|
| 422 |
+
font-weight: bold;
|
| 423 |
+
cursor: pointer;
|
| 424 |
+
">×</button>
|
| 425 |
+
<h3 style="margin-top: 0;">Your Cart</h3>
|
| 426 |
+
<div id="cart-content">
|
| 427 |
+
<!-- Cart items will be dynamically updated here -->
|
| 428 |
+
</div>
|
| 429 |
+
</div>
|
| 430 |
+
</div>
|
| 431 |
+
''')
|
| 432 |
|
| 433 |
+
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 434 |
gr.Row([selected_preference])
|
| 435 |
gr.Row(menu_output)
|
| 436 |
gr.Row(modal_window)
|
| 437 |
+
gr.Row(view_cart_button)
|
| 438 |
+
gr.Row(cart_modal)
|
| 439 |
|
| 440 |
+
# Add JavaScript for modal behavior
|
| 441 |
+
gr.HTML('''
|
| 442 |
+
<script>
|
| 443 |
+
function openCartModal() {
|
| 444 |
+
document.getElementById('cart-modal').style.display = 'block';
|
| 445 |
+
}
|
| 446 |
|
| 447 |
+
function closeCartModal() {
|
| 448 |
+
document.getElementById('cart-modal').style.display = 'none';
|
| 449 |
+
}
|
| 450 |
|
| 451 |
+
// Dynamically update the cart content
|
| 452 |
+
function updateCartContent(htmlContent) {
|
| 453 |
+
document.getElementById('cart-content').innerHTML = htmlContent;
|
| 454 |
+
}
|
| 455 |
|
| 456 |
+
// Update the cart display dynamically
|
| 457 |
+
function updateCartDisplay() {
|
| 458 |
+
let totalBill = 0;
|
| 459 |
+
let cartHTML = "<div>";
|
| 460 |
+
cart.forEach((item, index) => {
|
| 461 |
+
totalBill += item.itemTotal;
|
| 462 |
+
cartHTML += `<div style="margin-bottom: 10px; border: 1px solid #ccc; border-radius: 5px; padding: 10px;">
|
| 463 |
+
<strong>${item.name}</strong> (x${item.quantity}) - $${item.itemTotal.toFixed(2)}
|
| 464 |
+
<br>Extras: ${item.extras.join(", ") || "None"}
|
| 465 |
+
<br>Instructions: ${item.instructions || "None"}
|
| 466 |
+
</div>`;
|
| 467 |
+
});
|
| 468 |
+
cartHTML += `</div><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 469 |
+
cartHTML += `<button onclick="submitCart()" style="
|
| 470 |
+
background-color: #007bff;
|
| 471 |
+
color: white;
|
| 472 |
+
padding: 10px 20px;
|
| 473 |
+
border: none;
|
| 474 |
+
border-radius: 5px;
|
| 475 |
+
font-size: 16px;
|
| 476 |
+
cursor: pointer;
|
| 477 |
+
">Submit</button>`;
|
| 478 |
+
updateCartContent(cartHTML);
|
| 479 |
+
}
|
| 480 |
+
</script>
|
| 481 |
+
''')
|
| 482 |
|
| 483 |
+
# Cart & Final Order Page (Not needed as the cart is shown in the modal now)
|
| 484 |
+
|
| 485 |
# Button Bindings
|
| 486 |
# Login Button
|
| 487 |
login_button.click(
|
|
|
|
| 505 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 506 |
outputs=[login_section, signup_section],
|
| 507 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
|
| 509 |
return demo
|
| 510 |
|
| 511 |
if __name__ == "__main__":
|
| 512 |
app().launch()
|
| 513 |
+
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
# Modal window
|
| 517 |
+
modal_window = gr.HTML("""
|
| 518 |
+
<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;">
|
| 519 |
+
<div style="text-align: right;">
|
| 520 |
+
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
| 521 |
+
</div>
|
| 522 |
+
<img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
|
| 523 |
+
<h2 id="modal-name"></h2>
|
| 524 |
+
<p id="modal-description"></p>
|
| 525 |
+
<p id="modal-price"></p>
|
| 526 |
+
<!-- Biryani Extras -->
|
| 527 |
+
<label for="biryani-extras">Extras :</label>
|
| 528 |
+
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 529 |
+
<label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
|
| 530 |
+
<label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
|
| 531 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
|
| 532 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
|
| 533 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
|
| 534 |
+
<label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
|
| 535 |
+
<label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
|
| 536 |
+
</div>
|
| 537 |
+
<!-- Quantity and Special Instructions -->
|
| 538 |
+
<label for="quantity">Quantity:</label>
|
| 539 |
+
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
| 540 |
+
<br><br>
|
| 541 |
+
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
| 542 |
+
<br><br>
|
| 543 |
+
<!-- Add to Cart Button -->
|
| 544 |
+
<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>
|
| 545 |
+
</div>
|
| 546 |
+
|