Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,6 +93,30 @@ extras = [
|
|
| 93 |
{"name": "Extra Onion & Lemon", "price": "$2.00"}
|
| 94 |
]
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# JavaScript for popup modal
|
| 97 |
popup_js = """
|
| 98 |
<script>
|
|
@@ -147,9 +171,9 @@ popup_html = """
|
|
| 147 |
</div>
|
| 148 |
"""
|
| 149 |
|
| 150 |
-
# Generate dish cards
|
| 151 |
def display_dishes(category):
|
| 152 |
-
|
|
|
|
| 153 |
for dish in menu_data:
|
| 154 |
if category == "ALL" or dish["category"] == category:
|
| 155 |
html_content += f"""
|
|
@@ -160,10 +184,9 @@ def display_dishes(category):
|
|
| 160 |
<h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3>
|
| 161 |
<p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
|
| 162 |
<p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
|
| 163 |
-
<button
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
</button>
|
| 167 |
</div>
|
| 168 |
"""
|
| 169 |
html_content += "</div>"
|
|
@@ -173,12 +196,10 @@ def display_dishes(category):
|
|
| 173 |
|
| 174 |
# Main Gradio App
|
| 175 |
with gr.Blocks() as demo:
|
| 176 |
-
gr.HTML(
|
| 177 |
-
gr.HTML(popup_js) # Add the JavaScript
|
| 178 |
-
|
| 179 |
-
gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")
|
| 180 |
|
| 181 |
with gr.Tabs():
|
|
|
|
| 182 |
with gr.Tab("Menu"):
|
| 183 |
with gr.Row():
|
| 184 |
btn_all = gr.Button("ALL")
|
|
@@ -188,22 +209,24 @@ with gr.Blocks() as demo:
|
|
| 188 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 189 |
|
| 190 |
btn_all.click(
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
btn_vegan.click(
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
btn_halal.click(
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
|
|
|
|
| 203 |
with gr.Tab("Cart"):
|
| 204 |
cart_display = gr.HTML(value=display_cart())
|
| 205 |
-
gr.Button("Refresh Cart")
|
| 206 |
-
|
|
|
|
| 207 |
outputs=cart_display
|
| 208 |
)
|
| 209 |
|
|
|
|
| 93 |
{"name": "Extra Onion & Lemon", "price": "$2.00"}
|
| 94 |
]
|
| 95 |
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# Global cart variable
|
| 99 |
+
cart = []
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def add_to_cart(item_name, spice_level=None, extras=None):
|
| 103 |
+
"""Add selected item to cart."""
|
| 104 |
+
cart.append({"item_name": item_name, "spice_level": spice_level, "extras": extras or []})
|
| 105 |
+
return f"{item_name} added to cart!"
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def display_cart():
|
| 109 |
+
"""Return the current cart contents."""
|
| 110 |
+
if not cart:
|
| 111 |
+
return "Your cart is empty."
|
| 112 |
+
cart_content = "<h3>Your Cart:</h3><ul>"
|
| 113 |
+
for item in cart:
|
| 114 |
+
extras = ', '.join(item['extras']) if item['extras'] else "No extras"
|
| 115 |
+
cart_content += f"<li>{item['item_name']} - Spice: {item['spice_level'] or 'Default'} - Extras: {extras}</li>"
|
| 116 |
+
cart_content += "</ul>"
|
| 117 |
+
return cart_content
|
| 118 |
+
|
| 119 |
+
|
| 120 |
# JavaScript for popup modal
|
| 121 |
popup_js = """
|
| 122 |
<script>
|
|
|
|
| 171 |
</div>
|
| 172 |
"""
|
| 173 |
|
|
|
|
| 174 |
def display_dishes(category):
|
| 175 |
+
"""Render dishes dynamically based on the selected category."""
|
| 176 |
+
html_content = "<div style='display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;'>"
|
| 177 |
for dish in menu_data:
|
| 178 |
if category == "ALL" or dish["category"] == category:
|
| 179 |
html_content += f"""
|
|
|
|
| 184 |
<h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3>
|
| 185 |
<p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
|
| 186 |
<p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
|
| 187 |
+
<button style='padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 188 |
+
border-radius: 5px; cursor: pointer;'
|
| 189 |
+
onclick="addToCart('{dish['name']}')">Add to Cart</button>
|
|
|
|
| 190 |
</div>
|
| 191 |
"""
|
| 192 |
html_content += "</div>"
|
|
|
|
| 196 |
|
| 197 |
# Main Gradio App
|
| 198 |
with gr.Blocks() as demo:
|
| 199 |
+
gr.HTML("<h1 style='text-align: center;'>🍛 Welcome to the Biryani Hub 🍛</h1>")
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
with gr.Tabs():
|
| 202 |
+
# Menu Tab
|
| 203 |
with gr.Tab("Menu"):
|
| 204 |
with gr.Row():
|
| 205 |
btn_all = gr.Button("ALL")
|
|
|
|
| 209 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 210 |
|
| 211 |
btn_all.click(
|
| 212 |
+
lambda: display_dishes("ALL"),
|
| 213 |
+
outputs=dish_display
|
| 214 |
+
)
|
| 215 |
btn_vegan.click(
|
| 216 |
+
lambda: display_dishes("VEGAN"),
|
| 217 |
+
outputs=dish_display
|
| 218 |
+
)
|
| 219 |
btn_halal.click(
|
| 220 |
+
lambda: display_dishes("HALAL"),
|
| 221 |
+
outputs=dish_display
|
| 222 |
+
)
|
| 223 |
|
| 224 |
+
# Cart Tab
|
| 225 |
with gr.Tab("Cart"):
|
| 226 |
cart_display = gr.HTML(value=display_cart())
|
| 227 |
+
refresh_cart_btn = gr.Button("Refresh Cart")
|
| 228 |
+
refresh_cart_btn.click(
|
| 229 |
+
lambda: display_cart(),
|
| 230 |
outputs=cart_display
|
| 231 |
)
|
| 232 |
|