Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,89 +64,74 @@ def display_dishes(category):
|
|
| 64 |
html_content += "</div>"
|
| 65 |
return html_content
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
# Main Gradio App
|
| 68 |
with gr.Blocks() as demo:
|
| 69 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
gr.HTML("""
|
| 73 |
-
<style>
|
| 74 |
-
#small-btn {
|
| 75 |
-
padding: 5px 10px;
|
| 76 |
-
font-size: 14px;
|
| 77 |
-
border-radius: 5px;
|
| 78 |
-
margin: 5px;
|
| 79 |
-
}
|
| 80 |
-
</style>
|
| 81 |
-
""")
|
| 82 |
-
|
| 83 |
-
# Buttons for category selection
|
| 84 |
with gr.Row():
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
# Dish display
|
| 90 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 91 |
|
| 92 |
-
#
|
| 93 |
-
gr.HTML(
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
<
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
|
| 111 |
-
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 112 |
-
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 113 |
-
</div>
|
| 114 |
-
<script>
|
| 115 |
-
function showPopup(image, title, description, price) {{
|
| 116 |
-
document.getElementById('popup-image').src = image;
|
| 117 |
-
document.getElementById('popup-title').textContent = title;
|
| 118 |
-
document.getElementById('popup-description').textContent = description;
|
| 119 |
-
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 120 |
-
|
| 121 |
-
// Display the popup
|
| 122 |
-
document.getElementById('popup').style.display = 'block';
|
| 123 |
-
}}
|
| 124 |
-
function closePopup() {{
|
| 125 |
-
document.getElementById('popup').style.display = 'none';
|
| 126 |
-
}}
|
| 127 |
-
function addToCart() {{
|
| 128 |
-
const extras = Array.from(document.querySelectorAll('input[name=extras]:checked'))
|
| 129 |
-
.map(extra => extra.value)
|
| 130 |
-
.join(", ");
|
| 131 |
-
alert("Item added to cart with extras: " + extras);
|
| 132 |
-
closePopup();
|
| 133 |
-
}}
|
| 134 |
-
</script>
|
| 135 |
-
""")
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
# Button click events
|
| 139 |
-
btn_all.click(
|
| 140 |
-
lambda: gr.update(value=display_dishes("ALL")),
|
| 141 |
-
outputs=dish_display
|
| 142 |
-
)
|
| 143 |
-
btn_vegan.click(
|
| 144 |
-
lambda: gr.update(value=display_dishes("VEGAN")),
|
| 145 |
-
outputs=dish_display
|
| 146 |
-
)
|
| 147 |
-
btn_halal.click(
|
| 148 |
-
lambda: gr.update(value=display_dishes("HALAL")),
|
| 149 |
-
outputs=dish_display
|
| 150 |
-
)
|
| 151 |
-
|
| 152 |
-
demo.launch()
|
|
|
|
| 64 |
html_content += "</div>"
|
| 65 |
return html_content
|
| 66 |
|
| 67 |
+
def add_to_cart(item_name, item_price):
|
| 68 |
+
cart_items.append({"name": item_name, "price": item_price})
|
| 69 |
+
return f"{item_name} added to cart!"
|
| 70 |
+
|
| 71 |
+
# Display cart items
|
| 72 |
+
def display_cart():
|
| 73 |
+
if not cart_items:
|
| 74 |
+
return "<p>Your cart is empty.</p>"
|
| 75 |
+
html_content = "<ul>"
|
| 76 |
+
for item in cart_items:
|
| 77 |
+
html_content += f"<li>{item['name']} - ${item['price']}</li>"
|
| 78 |
+
html_content += "</ul>"
|
| 79 |
+
return html_content
|
| 80 |
+
|
| 81 |
# Main Gradio App
|
| 82 |
with gr.Blocks() as demo:
|
| 83 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 84 |
|
| 85 |
+
# Header with category buttons and cart icon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
with gr.Row():
|
| 87 |
+
with gr.Column(scale=6, min_width=300):
|
| 88 |
+
gr.HTML("""
|
| 89 |
+
<div style="text-align: left;">
|
| 90 |
+
<button id="btn-all" onclick="filterDishes('ALL')" style="padding: 5px 10px; margin: 5px;">ALL</button>
|
| 91 |
+
<button id="btn-vegan" onclick="filterDishes('VEGAN')" style="padding: 5px 10px; margin: 5px;">VEGAN</button>
|
| 92 |
+
<button id="btn-halal" onclick="filterDishes('HALAL')" style="padding: 5px 10px; margin: 5px;">HALAL</button>
|
| 93 |
+
</div>
|
| 94 |
+
""")
|
| 95 |
+
with gr.Column(scale=1, min_width=50):
|
| 96 |
+
gr.HTML("""
|
| 97 |
+
<div style="text-align: right;">
|
| 98 |
+
<button onclick="showCart()" style="background: none; border: none; cursor: pointer;">
|
| 99 |
+
π Cart
|
| 100 |
+
</button>
|
| 101 |
+
</div>
|
| 102 |
+
""")
|
| 103 |
|
| 104 |
# Dish display
|
| 105 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 106 |
|
| 107 |
+
# Cart display
|
| 108 |
+
cart_display = gr.HTML(value="<p>Your cart is empty.</p>")
|
| 109 |
+
|
| 110 |
+
# JavaScript functions
|
| 111 |
+
gr.HTML("""
|
| 112 |
+
<script>
|
| 113 |
+
function filterDishes(category) {
|
| 114 |
+
fetch(`/filter_dishes?category=${category}`)
|
| 115 |
+
.then(response => response.json())
|
| 116 |
+
.then(data => {
|
| 117 |
+
document.querySelector('#dish-display').innerHTML = data.html;
|
| 118 |
+
});
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
function addToCart(name, price) {
|
| 122 |
+
fetch(`/add_to_cart?item_name=${name}&item_price=${price}`)
|
| 123 |
+
.then(response => response.text())
|
| 124 |
+
.then(alert);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
function showCart() {
|
| 128 |
+
fetch(`/display_cart`)
|
| 129 |
+
.then(response => response.text())
|
| 130 |
+
.then(data => {
|
| 131 |
+
document.querySelector('#cart-display').innerHTML = data;
|
| 132 |
+
});
|
| 133 |
+
}
|
| 134 |
+
</script>
|
| 135 |
+
""")
|
| 136 |
|
| 137 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|