Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,8 +21,6 @@ menu_data = [
|
|
| 21 |
]
|
| 22 |
|
| 23 |
|
| 24 |
-
cart = []
|
| 25 |
-
|
| 26 |
extras = [
|
| 27 |
{"name": "Extra Raitha 4oz", "price": "$1.00"},
|
| 28 |
{"name": "Extra Raitha 8oz", "price": "$2.00"},
|
|
@@ -65,83 +63,74 @@ def display_dishes(category):
|
|
| 65 |
html_content += "</div>"
|
| 66 |
return html_content
|
| 67 |
|
| 68 |
-
|
| 69 |
-
# Add to cart
|
| 70 |
-
def add_to_cart(item_name, quantity, custom_preference):
|
| 71 |
-
cart.append({"name": item_name, "quantity": quantity, "custom_preference": custom_preference})
|
| 72 |
-
return display_cart()
|
| 73 |
-
|
| 74 |
-
# Display cart items
|
| 75 |
-
def display_cart():
|
| 76 |
-
if not cart:
|
| 77 |
-
return "<p>Your cart is empty.</p>"
|
| 78 |
-
html_content = "<div style='text-align: left;'>"
|
| 79 |
-
for item in cart:
|
| 80 |
-
html_content += f"<p>- {item['name']} (x{item['quantity']}) - Custom: {item['custom_preference']}</p>"
|
| 81 |
-
html_content += "</div>"
|
| 82 |
-
return html_content
|
| 83 |
-
|
| 84 |
# Main Gradio App
|
| 85 |
with gr.Blocks() as demo:
|
| 86 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 87 |
|
| 88 |
-
|
| 89 |
-
gr.HTML("<span style='font-size: 24px; cursor: pointer;'>π</span>")
|
| 90 |
-
btn_cart = gr.Button("View Cart")
|
| 91 |
-
|
| 92 |
-
cart_display = gr.HTML(value=display_cart())
|
| 93 |
-
|
| 94 |
with gr.Row():
|
| 95 |
btn_all = gr.Button("ALL")
|
| 96 |
btn_vegan = gr.Button("VEGAN")
|
| 97 |
btn_halal = gr.Button("HALAL")
|
| 98 |
|
| 99 |
-
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 105 |
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 106 |
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
<
|
| 110 |
-
<
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
<textarea id="popup-custom" placeholder="Add your custom preferences here..." style="width: 100%; margin-top: 10px; padding: 5px; border: 1px solid #ddd; border-radius: 5px;"></textarea>
|
| 114 |
|
| 115 |
-
<button onclick="
|
|
|
|
|
|
|
|
|
|
| 116 |
</div>
|
| 117 |
<script>
|
| 118 |
-
function showPopup(
|
| 119 |
-
document.getElementById('popup-
|
|
|
|
| 120 |
document.getElementById('popup-description').textContent = description;
|
| 121 |
-
document.getElementById('popup-price').textContent = price;
|
| 122 |
-
|
|
|
|
| 123 |
document.getElementById('popup').style.display = 'block';
|
| 124 |
}
|
| 125 |
-
|
| 126 |
function closePopup() {
|
| 127 |
document.getElementById('popup').style.display = 'none';
|
| 128 |
}
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
const quantity = document.getElementById('popup-quantity').value;
|
| 133 |
-
const customPreference = document.getElementById('popup-custom').value;
|
| 134 |
-
gr.Interface.postMessage('add_to_cart', [name, quantity, customPreference]);
|
| 135 |
-
closePopup();
|
| 136 |
}
|
| 137 |
</script>
|
| 138 |
""")
|
| 139 |
|
| 140 |
-
|
| 141 |
# Button click events
|
| 142 |
-
btn_all.click(
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
]
|
| 22 |
|
| 23 |
|
|
|
|
|
|
|
| 24 |
extras = [
|
| 25 |
{"name": "Extra Raitha 4oz", "price": "$1.00"},
|
| 26 |
{"name": "Extra Raitha 8oz", "price": "$2.00"},
|
|
|
|
| 63 |
html_content += "</div>"
|
| 64 |
return html_content
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# Main Gradio App
|
| 67 |
with gr.Blocks() as demo:
|
| 68 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 69 |
|
| 70 |
+
# Buttons for category selection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
with gr.Row():
|
| 72 |
btn_all = gr.Button("ALL")
|
| 73 |
btn_vegan = gr.Button("VEGAN")
|
| 74 |
btn_halal = gr.Button("HALAL")
|
| 75 |
|
| 76 |
+
# Dish display
|
| 77 |
+
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 78 |
|
| 79 |
+
# JavaScript for managing the pop-up
|
| 80 |
+
gr.HTML(f"""
|
| 81 |
+
<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 82 |
+
background-color: white; padding: 20px; border-radius: 10px;
|
| 83 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
|
| 84 |
+
<span onclick="closePopup()" style="position: absolute; top: 10px; right: 10px; cursor: pointer; font-size: 20px;">×</span>
|
| 85 |
+
|
| 86 |
+
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 87 |
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 88 |
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 89 |
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 93 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 94 |
+
""" + "".join([f'<label style="margin-right: 10px; display: block;"><input type="checkbox" name="extras" value="{extra["name"]}" style="margin-right: 5px;">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
|
| 95 |
+
</div>
|
|
|
|
| 96 |
|
| 97 |
+
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
|
| 98 |
+
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 99 |
+
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 100 |
+
|
| 101 |
</div>
|
| 102 |
<script>
|
| 103 |
+
function showPopup(image, title, description, price) {
|
| 104 |
+
document.getElementById('popup-image').src = image;
|
| 105 |
+
document.getElementById('popup-title').textContent = title;
|
| 106 |
document.getElementById('popup-description').textContent = description;
|
| 107 |
+
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 108 |
+
|
| 109 |
+
// Display the popup
|
| 110 |
document.getElementById('popup').style.display = 'block';
|
| 111 |
}
|
|
|
|
| 112 |
function closePopup() {
|
| 113 |
document.getElementById('popup').style.display = 'none';
|
| 114 |
}
|
| 115 |
+
function addToCart(dishName, spiceLevel) {
|
| 116 |
+
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 117 |
+
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
}
|
| 119 |
</script>
|
| 120 |
""")
|
| 121 |
|
|
|
|
| 122 |
# Button click events
|
| 123 |
+
btn_all.click(
|
| 124 |
+
lambda: gr.update(value=display_dishes("ALL")),
|
| 125 |
+
outputs=dish_display
|
| 126 |
+
)
|
| 127 |
+
btn_vegan.click(
|
| 128 |
+
lambda: gr.update(value=display_dishes("VEGAN")),
|
| 129 |
+
outputs=dish_display
|
| 130 |
+
)
|
| 131 |
+
btn_halal.click(
|
| 132 |
+
lambda: gr.update(value=display_dishes("HALAL")),
|
| 133 |
+
outputs=dish_display
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
demo.launch()
|