Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,15 @@ menu_data = [
|
|
| 20 |
{"name": "Chicken Manchurian", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Chicken_manchurian.jpg", "description": "A popular Indo-Chinese dish featuring fried chicken pieces tossed in a tangy and spicy sauce.", "price": 13.99},
|
| 21 |
]
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Filter dishes by category
|
| 26 |
def filter_dishes(category):
|
|
@@ -45,7 +53,7 @@ def display_dishes(category):
|
|
| 45 |
<div style='text-align: center;'>
|
| 46 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 47 |
style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
|
| 48 |
-
<button onclick="
|
| 49 |
style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 50 |
border-radius: 5px; cursor: pointer;">Add</button>
|
| 51 |
</div>
|
|
@@ -54,76 +62,77 @@ def display_dishes(category):
|
|
| 54 |
html_content += "</div>"
|
| 55 |
return html_content
|
| 56 |
|
| 57 |
-
# Add item to cart
|
| 58 |
-
def add_to_cart(item_name, item_price):
|
| 59 |
-
cart_items.append({"name": item_name, "price": item_price})
|
| 60 |
-
return f"{item_name} added to cart!"
|
| 61 |
-
|
| 62 |
-
# Display cart items
|
| 63 |
-
def display_cart():
|
| 64 |
-
if not cart_items:
|
| 65 |
-
return "<p>Your cart is empty.</p>"
|
| 66 |
-
html_content = "<ul>"
|
| 67 |
-
for item in cart_items:
|
| 68 |
-
html_content += f"<li>{item['name']} - ${item['price']}</li>"
|
| 69 |
-
html_content += "</ul>"
|
| 70 |
-
return html_content
|
| 71 |
-
|
| 72 |
# Main Gradio App
|
| 73 |
with gr.Blocks() as demo:
|
| 74 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 75 |
|
| 76 |
-
#
|
| 77 |
with gr.Row():
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
<button id="btn-all" onclick="filterDishes('ALL')" style="padding: 5px 10px; margin: 5px;">ALL</button>
|
| 82 |
-
<button id="btn-vegan" onclick="filterDishes('VEGAN')" style="padding: 5px 10px; margin: 5px;">VEGAN</button>
|
| 83 |
-
<button id="btn-halal" onclick="filterDishes('HALAL')" style="padding: 5px 10px; margin: 5px;">HALAL</button>
|
| 84 |
-
</div>
|
| 85 |
-
""")
|
| 86 |
-
with gr.Column(scale=1, min_width=50):
|
| 87 |
-
gr.HTML("""
|
| 88 |
-
<div style="text-align: right;">
|
| 89 |
-
<button onclick="showCart()" style="background: none; border: none; cursor: pointer;">
|
| 90 |
-
π Cart
|
| 91 |
-
</button>
|
| 92 |
-
</div>
|
| 93 |
-
""")
|
| 94 |
|
| 95 |
# Dish display
|
| 96 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
<script>
|
| 104 |
-
function
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
});
|
| 110 |
-
}
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
.then(response => response.text())
|
| 115 |
-
.then(alert);
|
| 116 |
}
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
});
|
| 124 |
}
|
| 125 |
</script>
|
| 126 |
""")
|
| 127 |
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
|
|
|
|
|
| 20 |
{"name": "Chicken Manchurian", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Chicken_manchurian.jpg", "description": "A popular Indo-Chinese dish featuring fried chicken pieces tossed in a tangy and spicy sauce.", "price": 13.99},
|
| 21 |
]
|
| 22 |
|
| 23 |
+
extras = [
|
| 24 |
+
{"name": "Extra Raitha 4oz", "price": "$1.00"},
|
| 25 |
+
{"name": "Extra Raitha 8oz", "price": "$2.00"},
|
| 26 |
+
{"name": "Extra Salan 4oz", "price": "$1.00"},
|
| 27 |
+
{"name": "Extra Salan 8oz", "price": "$2.00"},
|
| 28 |
+
{"name": "Extra Onion", "price": "$1.00"},
|
| 29 |
+
{"name": "Extra Onion & Lemon", "price": "$2.00"},
|
| 30 |
+
{"name": "Extra Fried Onion 4oz", "price": "$2.00"},
|
| 31 |
+
]
|
| 32 |
|
| 33 |
# Filter dishes by category
|
| 34 |
def filter_dishes(category):
|
|
|
|
| 53 |
<div style='text-align: center;'>
|
| 54 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 55 |
style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
|
| 56 |
+
<button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')"
|
| 57 |
style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 58 |
border-radius: 5px; cursor: pointer;">Add</button>
|
| 59 |
</div>
|
|
|
|
| 62 |
html_content += "</div>"
|
| 63 |
return html_content
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# Main Gradio App
|
| 66 |
with gr.Blocks() as demo:
|
| 67 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 68 |
|
| 69 |
+
# Buttons for category selection
|
| 70 |
with gr.Row():
|
| 71 |
+
btn_all = gr.Button("ALL")
|
| 72 |
+
btn_vegan = gr.Button("VEGAN")
|
| 73 |
+
btn_halal = gr.Button("HALAL")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
# Dish display
|
| 76 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 77 |
|
| 78 |
+
# JavaScript for managing the pop-up
|
| 79 |
+
gr.HTML(f"""
|
| 80 |
+
<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 81 |
+
background-color: white; padding: 20px; border-radius: 10px;
|
| 82 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
|
| 83 |
+
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 84 |
+
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 85 |
+
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 86 |
+
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 87 |
+
|
| 88 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
|
| 89 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 90 |
+
""" + "".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]) + """
|
| 91 |
+
</div>
|
| 92 |
|
| 93 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</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="checkbox" name="extras" value="{extra["name"]}" style="margin-right: 5px;">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
|
| 99 |
+
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 100 |
+
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 101 |
+
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 102 |
+
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 103 |
+
</div>
|
| 104 |
<script>
|
| 105 |
+
function showPopup(image, title, description, price) {
|
| 106 |
+
document.getElementById('popup-image').src = image;
|
| 107 |
+
document.getElementById('popup-title').textContent = title;
|
| 108 |
+
document.getElementById('popup-description').textContent = description;
|
| 109 |
+
document.getElementById('popup-price').textContent = "Price: " + price;
|
|
|
|
|
|
|
| 110 |
|
| 111 |
+
// Display the popup
|
| 112 |
+
document.getElementById('popup').style.display = 'block';
|
|
|
|
|
|
|
| 113 |
}
|
| 114 |
+
function closePopup() {
|
| 115 |
+
document.getElementById('popup').style.display = 'none';
|
| 116 |
+
}
|
| 117 |
+
function addToCart(dishName, spiceLevel) {
|
| 118 |
+
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 119 |
+
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
|
|
|
| 120 |
}
|
| 121 |
</script>
|
| 122 |
""")
|
| 123 |
|
| 124 |
+
# Button click events
|
| 125 |
+
btn_all.click(
|
| 126 |
+
lambda: gr.update(value=display_dishes("ALL")),
|
| 127 |
+
outputs=dish_display
|
| 128 |
+
)
|
| 129 |
+
btn_vegan.click(
|
| 130 |
+
lambda: gr.update(value=display_dishes("VEGAN")),
|
| 131 |
+
outputs=dish_display
|
| 132 |
+
)
|
| 133 |
+
btn_halal.click(
|
| 134 |
+
lambda: gr.update(value=display_dishes("HALAL")),
|
| 135 |
+
outputs=dish_display
|
| 136 |
+
)
|
| 137 |
|
| 138 |
+
demo.launch()
|