Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,119 +1,133 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import qrcode
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
#
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# Menu data
|
| 4 |
+
menu_data = [
|
| 5 |
+
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
|
| 7 |
+
"description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
|
| 8 |
+
"price": "$8.99"},
|
| 9 |
+
{"name": "Chicken Biryani", "category": "HALAL",
|
| 10 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg",
|
| 11 |
+
"description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
|
| 12 |
+
"price": "$12.99"},
|
| 13 |
+
{"name": "Paneer Butter Masala", "category": "VEGAN",
|
| 14 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg",
|
| 15 |
+
"description": "Paneer cooked in a rich and creamy tomato-based gravy.",
|
| 16 |
+
"price": "$10.99"}
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
# Spice levels and extras
|
| 20 |
+
spice_levels = ["American Mild", "American Medium", "American Spicy",
|
| 21 |
+
"Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
|
| 22 |
+
extras = [
|
| 23 |
+
{"name": "Extra Raitha 4oz", "price": "$1.00"},
|
| 24 |
+
{"name": "Extra Onion", "price": "$1.00"},
|
| 25 |
+
{"name": "Extra Fried Onion 4oz", "price": "$2.00"}
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
# Filter dishes by category
|
| 29 |
+
def filter_dishes(category):
|
| 30 |
+
if category == "ALL":
|
| 31 |
+
return menu_data
|
| 32 |
+
return [dish for dish in menu_data if dish["category"] == category]
|
| 33 |
+
|
| 34 |
+
# Generate dish cards with "Add" button
|
| 35 |
+
def display_dishes(category):
|
| 36 |
+
filtered_dishes = filter_dishes(category)
|
| 37 |
+
html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"
|
| 38 |
+
for dish in filtered_dishes:
|
| 39 |
+
html_content += f"""
|
| 40 |
+
<div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
|
| 41 |
+
width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 42 |
+
background-color: #f9f9f9;'>
|
| 43 |
+
<div style='flex: 1; margin-right: 20px; text-align: left;'>
|
| 44 |
+
<h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
|
| 45 |
+
<p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
|
| 46 |
+
<p style='font-size: 16px; color: #444; margin: 0;'>Price: {dish['price']}</p>
|
| 47 |
+
</div>
|
| 48 |
+
<div style='text-align: center;'>
|
| 49 |
+
<img src='{dish['image']}' alt='{dish['name']}'
|
| 50 |
+
style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
|
| 51 |
+
<button onclick=\"showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')\"
|
| 52 |
+
style=\"margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 53 |
+
border-radius: 5px; cursor: pointer;\">Add</button>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
"""
|
| 57 |
+
html_content += "</div>"
|
| 58 |
+
return html_content
|
| 59 |
+
|
| 60 |
+
# Main Gradio App
|
| 61 |
+
with gr.Blocks() as demo:
|
| 62 |
+
gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Dynamic Menu with Pop-up 🍛</h1>")
|
| 63 |
+
|
| 64 |
+
# Buttons for category selection
|
| 65 |
+
with gr.Row():
|
| 66 |
+
btn_all = gr.Button("ALL")
|
| 67 |
+
btn_vegan = gr.Button("VEGAN")
|
| 68 |
+
btn_halal = gr.Button("HALAL")
|
| 69 |
+
|
| 70 |
+
# Dish display
|
| 71 |
+
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 72 |
+
|
| 73 |
+
# JavaScript for managing the pop-up
|
| 74 |
+
gr.HTML(f"""
|
| 75 |
+
<div id=\"popup\" style=\"display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 76 |
+
background-color: white; padding: 20px; border-radius: 10px;
|
| 77 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;\">
|
| 78 |
+
<img id=\"popup-image\" src=\"\" alt=\"\" style=\"width: 100%; height: auto; border-radius: 10px;\">
|
| 79 |
+
<h2 id=\"popup-title\" style=\"margin-top: 20px; color: #444;\"></h2>
|
| 80 |
+
<p id=\"popup-description\" style=\"margin-top: 10px; font-size: 16px; color: #666;\"></p>
|
| 81 |
+
<p id=\"popup-price\" style=\"margin-top: 10px; font-size: 16px; color: #444;\"></p>
|
| 82 |
+
|
| 83 |
+
<h4 style=\"text-align: left; margin-top: 20px;\">Choose a spice level</h4>
|
| 84 |
+
<div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\">
|
| 85 |
+
""" + """".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]) + """
|
| 86 |
+
</div>
|
| 87 |
+
|
| 88 |
+
<h4 style=\"text-align: left; margin-top: 20px;\">Choose Extras</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=\"checkbox\" name=\"extras\" value=\"{extra["name"]}\" style=\"margin-right: 5px;\">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
|
| 91 |
+
</div>
|
| 92 |
+
|
| 93 |
+
<button onclick=\"addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)\"
|
| 94 |
+
style=\"margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 95 |
+
border-radius: 5px; cursor: pointer;\">Add to Cart</button>
|
| 96 |
+
<button onclick=\"closePopup()\" style=\"margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 97 |
+
color: white; border: none; border-radius: 5px; cursor: pointer;\">Close</button>
|
| 98 |
+
</div>
|
| 99 |
+
<script>
|
| 100 |
+
function showPopup(image, title, description, price) {
|
| 101 |
+
document.getElementById('popup-image').src = image;
|
| 102 |
+
document.getElementById('popup-title').textContent = title;
|
| 103 |
+
document.getElementById('popup-description').textContent = description;
|
| 104 |
+
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 105 |
+
|
| 106 |
+
// Display the popup
|
| 107 |
+
document.getElementById('popup').style.display = 'block';
|
| 108 |
+
}
|
| 109 |
+
function closePopup() {
|
| 110 |
+
document.getElementById('popup').style.display = 'none';
|
| 111 |
+
}
|
| 112 |
+
function addToCart(dishName, spiceLevel) {
|
| 113 |
+
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 114 |
+
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
| 115 |
+
}
|
| 116 |
+
</script>
|
| 117 |
+
""")
|
| 118 |
+
|
| 119 |
+
# Button click events
|
| 120 |
+
btn_all.click(
|
| 121 |
+
lambda: gr.update(value=display_dishes("ALL")),
|
| 122 |
+
outputs=dish_display
|
| 123 |
+
)
|
| 124 |
+
btn_vegan.click(
|
| 125 |
+
lambda: gr.update(value=display_dishes("VEGAN")),
|
| 126 |
+
outputs=dish_display
|
| 127 |
+
)
|
| 128 |
+
btn_halal.click(
|
| 129 |
+
lambda: gr.update(value=display_dishes("HALAL")),
|
| 130 |
+
outputs=dish_display
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
demo.launch()
|