Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,36 +21,27 @@ menu_data = [
|
|
| 21 |
]
|
| 22 |
|
| 23 |
|
| 24 |
-
# Cart management
|
| 25 |
-
cart = []
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
total_price = 0
|
| 40 |
-
for item in cart:
|
| 41 |
-
item_total = item['price'] * item['count']
|
| 42 |
-
total_price += item_total
|
| 43 |
-
cart_html += f"<tr><td>{item['name']}</td><td>{item['extras']}</td><td>${item['price']}</td><td>{item['count']}</td><td>${item_total:.2f}</td></tr>"
|
| 44 |
-
cart_html += f"<tr><td colspan='4' style='text-align:right;'><strong>Total</strong></td><td><strong>${total_price:.2f}</strong></td></tr></table>"
|
| 45 |
-
return cart_html
|
| 46 |
|
| 47 |
-
#
|
| 48 |
def filter_dishes(category):
|
| 49 |
if category == "ALL":
|
| 50 |
return menu_data
|
| 51 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 52 |
|
| 53 |
-
#
|
| 54 |
def display_dishes(category):
|
| 55 |
filtered_dishes = filter_dishes(category)
|
| 56 |
html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"
|
|
@@ -76,88 +67,77 @@ def display_dishes(category):
|
|
| 76 |
html_content += "</div>"
|
| 77 |
return html_content
|
| 78 |
|
| 79 |
-
|
| 80 |
-
#Spice levels and extras options
|
| 81 |
-
spice_levels = ["Mild", "Medium", "Spicy", "Extra Spicy"]
|
| 82 |
-
extras = [
|
| 83 |
-
{"name": "Extra Cheese", "price": "$2.00"},
|
| 84 |
-
{"name": "Extra Sauce", "price": "$1.50"},
|
| 85 |
-
{"name": "No Onions", "price": "$0.00"},
|
| 86 |
-
{"name": "No Garlic", "price": "$0.00"}
|
| 87 |
-
]
|
| 88 |
-
|
| 89 |
-
# Main Gradio Application
|
| 90 |
with gr.Blocks() as demo:
|
| 91 |
-
gr.HTML("<h1 style='text-align: center;'
|
| 92 |
|
|
|
|
| 93 |
with gr.Row():
|
| 94 |
btn_all = gr.Button("ALL")
|
| 95 |
btn_vegan = gr.Button("VEGAN")
|
| 96 |
btn_halal = gr.Button("HALAL")
|
| 97 |
|
|
|
|
| 98 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 99 |
-
cart_display = gr.HTML(value="<p>Your cart is empty.</p>")
|
| 100 |
-
|
| 101 |
-
btn_all.click(lambda: display_dishes("ALL"), outputs=dish_display)
|
| 102 |
-
btn_vegan.click(lambda: display_dishes("VEGAN"), outputs=dish_display)
|
| 103 |
-
btn_halal.click(lambda: display_dishes("HALAL"), outputs=dish_display)
|
| 104 |
-
|
| 105 |
-
with gr.Row():
|
| 106 |
-
dish_display.render()
|
| 107 |
-
cart_display.render()
|
| 108 |
|
|
|
|
| 109 |
gr.HTML(f"""
|
| 110 |
-
|
| 111 |
background-color: white; padding: 20px; border-radius: 10px;
|
| 112 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 124 |
-
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 125 |
-
""" + "".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]) + """
|
| 126 |
-
</div>
|
| 127 |
-
|
| 128 |
-
<button onclick="addToCartFromPopup()"
|
| 129 |
-
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 130 |
-
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 131 |
-
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 132 |
-
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 133 |
-
</div>
|
| 134 |
-
<script>
|
| 135 |
-
let selectedItem = '';
|
| 136 |
-
let selectedPrice = 0;
|
| 137 |
-
|
| 138 |
-
function showPopup(image, title, description, price) {
|
| 139 |
-
document.getElementById('popup-image').src = image;
|
| 140 |
-
document.getElementById('popup-title').textContent = title;
|
| 141 |
-
document.getElementById('popup-description').textContent = description;
|
| 142 |
-
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 143 |
-
selectedItem = title;
|
| 144 |
-
selectedPrice = price;
|
| 145 |
-
|
| 146 |
-
// Display the popup
|
| 147 |
-
document.getElementById('popup').style.display = 'block';
|
| 148 |
-
}
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
""")
|
| 162 |
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
]
|
| 22 |
|
| 23 |
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# Spice levels and extras
|
| 26 |
+
spice_levels = ["American Mild", "American Medium", "American Spicy",
|
| 27 |
+
"Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
|
| 28 |
+
extras = [
|
| 29 |
+
{"name": "Extra Raitha 4oz", "price": "$1.00"},
|
| 30 |
+
{"name": "Extra Raitha 8oz", "price": "$2.00"},
|
| 31 |
+
{"name": "Extra Salan 4oz", "price": "$1.00"},
|
| 32 |
+
{"name": "Extra Salan 8oz", "price": "$2.00"},
|
| 33 |
+
{"name": "Extra Onion", "price": "$1.00"},
|
| 34 |
+
{"name": "Extra Onion & Lemon", "price": "$2.00"},
|
| 35 |
+
{"name": "Extra Fried Onion 4oz", "price": "$2.00"},
|
| 36 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# Filter dishes by category
|
| 39 |
def filter_dishes(category):
|
| 40 |
if category == "ALL":
|
| 41 |
return menu_data
|
| 42 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 43 |
|
| 44 |
+
# Generate dish cards with "Add" button
|
| 45 |
def display_dishes(category):
|
| 46 |
filtered_dishes = filter_dishes(category)
|
| 47 |
html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"
|
|
|
|
| 67 |
html_content += "</div>"
|
| 68 |
return html_content
|
| 69 |
|
| 70 |
+
# Main Gradio App
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
with gr.Blocks() as demo:
|
| 72 |
+
gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
|
| 73 |
|
| 74 |
+
# Buttons for category selection
|
| 75 |
with gr.Row():
|
| 76 |
btn_all = gr.Button("ALL")
|
| 77 |
btn_vegan = gr.Button("VEGAN")
|
| 78 |
btn_halal = gr.Button("HALAL")
|
| 79 |
|
| 80 |
+
# Dish display
|
| 81 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
# JavaScript for managing the pop-up
|
| 84 |
gr.HTML(f"""
|
| 85 |
+
<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 86 |
background-color: white; padding: 20px; border-radius: 10px;
|
| 87 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
|
| 88 |
+
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 89 |
+
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 90 |
+
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 91 |
+
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 92 |
+
|
| 93 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
|
| 94 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 95 |
+
""" + "".join([f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>' for spice in spice_levels]) + """
|
| 96 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 99 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 100 |
+
""" + "".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]) + """
|
| 101 |
+
</div>
|
| 102 |
|
| 103 |
+
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
|
| 104 |
+
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 105 |
+
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 106 |
+
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 107 |
+
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 108 |
+
</div>
|
| 109 |
+
<script>
|
| 110 |
+
function showPopup(image, title, description, price) {
|
| 111 |
+
document.getElementById('popup-image').src = image;
|
| 112 |
+
document.getElementById('popup-title').textContent = title;
|
| 113 |
+
document.getElementById('popup-description').textContent = description;
|
| 114 |
+
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 115 |
+
|
| 116 |
+
// Display the popup
|
| 117 |
+
document.getElementById('popup').style.display = 'block';
|
| 118 |
+
}
|
| 119 |
+
function closePopup() {
|
| 120 |
+
document.getElementById('popup').style.display = 'none';
|
| 121 |
+
}
|
| 122 |
+
function addToCart(dishName, spiceLevel) {
|
| 123 |
+
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 124 |
+
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
| 125 |
+
}
|
| 126 |
+
</script>
|
| 127 |
""")
|
| 128 |
|
| 129 |
+
# Button click events
|
| 130 |
+
btn_all.click(
|
| 131 |
+
lambda: gr.update(value=display_dishes("ALL")),
|
| 132 |
+
outputs=dish_display
|
| 133 |
+
)
|
| 134 |
+
btn_vegan.click(
|
| 135 |
+
lambda: gr.update(value=display_dishes("VEGAN")),
|
| 136 |
+
outputs=dish_display
|
| 137 |
+
)
|
| 138 |
+
btn_halal.click(
|
| 139 |
+
lambda: gr.update(value=display_dishes("HALAL")),
|
| 140 |
+
outputs=dish_display
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
demo.launch()
|