Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
cart = []
|
| 5 |
-
|
| 6 |
menu_data = [
|
| 7 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 8 |
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
|
|
@@ -15,114 +13,190 @@ menu_data = [
|
|
| 15 |
{"name": "Paneer Butter Masala", "category": "VEGAN",
|
| 16 |
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg",
|
| 17 |
"description": "Paneer cooked in a rich and creamy tomato-based gravy.",
|
| 18 |
-
"price": "$10.99"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
]
|
| 20 |
|
| 21 |
-
# Function to add an item to the cart
|
| 22 |
-
def add_to_cart(item_name):
|
| 23 |
-
cart.append({"item_name": item_name})
|
| 24 |
-
return f"'{item_name}' has been added to your cart!"
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
def display_dishes(category):
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
<
|
| 47 |
-
<p style='
|
| 48 |
-
<p style='
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
</div>
|
| 53 |
-
|
|
|
|
| 54 |
html_content += "</div>"
|
| 55 |
return html_content
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
<
|
| 60 |
-
async function addItemToCart(itemName) {
|
| 61 |
-
try {
|
| 62 |
-
const response = await fetch("/run/add_to_cart", {
|
| 63 |
-
method: "POST",
|
| 64 |
-
headers: { "Content-Type": "application/json" },
|
| 65 |
-
body: JSON.stringify({ item_name: itemName })
|
| 66 |
-
});
|
| 67 |
-
const result = await response.json();
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
} catch (error) {
|
| 75 |
-
console.error("Error:", error);
|
| 76 |
-
alert("Something went wrong!");
|
| 77 |
-
}
|
| 78 |
-
}
|
| 79 |
-
</script>
|
| 80 |
-
"""
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
gr.HTML("<h1 style='text-align: center;'>🍛 Welcome to the Biryani Hub 🍛</h1>")
|
| 85 |
-
gr.HTML(popup_js) # Add JavaScript for handling interactions
|
| 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 |
|
| 120 |
-
#
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
)
|
| 126 |
|
| 127 |
-
|
| 128 |
-
demo.launch()
|
|
|
|
| 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",
|
|
|
|
| 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 |
+
{"name": "Beef Steak", "category": "HALAL",
|
| 18 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/beef_steak.jpg",
|
| 19 |
+
"description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
|
| 20 |
+
"price": "$15.99"},
|
| 21 |
+
{"name": "Mushroom Soup", "category": "VEGAN",
|
| 22 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mushroom_soup.jpg",
|
| 23 |
+
"description": "Creamy mushroom soup with fresh herbs.",
|
| 24 |
+
"price": "$7.99"},
|
| 25 |
+
{"name": "Tandoori Chicken", "category": "HALAL",
|
| 26 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/tandoori_chicken.jpg",
|
| 27 |
+
"description": "Grilled chicken marinated in yogurt and spices, cooked in a tandoor.",
|
| 28 |
+
"price": "$11.99"},
|
| 29 |
+
{"name": "Grilled Veggies", "category": "VEGAN",
|
| 30 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/grilled_veggies.jpg",
|
| 31 |
+
"description": "A healthy mix of grilled seasonal vegetables with olive oil.",
|
| 32 |
+
"price": "$9.99"},
|
| 33 |
+
{"name": "Butter Naan", "category": "VEGAN",
|
| 34 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/butter_naan.jpg",
|
| 35 |
+
"description": "Soft and buttery flatbread, perfect to pair with any curry.",
|
| 36 |
+
"price": "$2.99"},
|
| 37 |
+
{"name": "Fish Curry", "category": "HALAL",
|
| 38 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/fish_curry.jpg",
|
| 39 |
+
"description": "Fresh fish cooked in a spicy and tangy curry.",
|
| 40 |
+
"price": "$13.99"},
|
| 41 |
+
{"name": "Vegetable Salad", "category": "VEGAN",
|
| 42 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/vegetable_salad.jpg",
|
| 43 |
+
"description": "A mix of fresh greens, tomatoes, cucumbers, and a light dressing.",
|
| 44 |
+
"price": "$6.99"},
|
| 45 |
+
{"name": "Veg Spring Rolls", "category": "VEGAN",
|
| 46 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_spring_rolls.jpg",
|
| 47 |
+
"description": "Crispy spring rolls filled with fresh vegetables.",
|
| 48 |
+
"price": "$5.99"},
|
| 49 |
+
{"name": "Chicken Kebab", "category": "HALAL",
|
| 50 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_kebab.jpg",
|
| 51 |
+
"description": "Juicy chicken kebabs grilled to perfection with a mix of spices.",
|
| 52 |
+
"price": "$9.99"},
|
| 53 |
+
{"name": "Dal Makhani", "category": "VEGAN",
|
| 54 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/dal_makhani.jpg",
|
| 55 |
+
"description": "Rich and creamy black lentils slow-cooked with spices.",
|
| 56 |
+
"price": "$8.99"},
|
| 57 |
+
{"name": "Lamb Curry", "category": "HALAL",
|
| 58 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/lamb_curry.jpg",
|
| 59 |
+
"description": "Tender lamb pieces cooked in a flavorful curry sauce.",
|
| 60 |
+
"price": "$14.99"},
|
| 61 |
+
{"name": "Mixed Veg Curry", "category": "VEGAN",
|
| 62 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mixed_veg_curry.jpg",
|
| 63 |
+
"description": "A medley of fresh vegetables cooked in a lightly spiced curry.",
|
| 64 |
+
"price": "$9.99"},
|
| 65 |
+
{"name": "Chicken Wings", "category": "HALAL",
|
| 66 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_wings.jpg",
|
| 67 |
+
"description": "Crispy chicken wings tossed in a tangy sauce.",
|
| 68 |
+
"price": "$12.99"},
|
| 69 |
+
{"name": "Aloo Paratha", "category": "VEGAN",
|
| 70 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/aloo_paratha.jpg",
|
| 71 |
+
"description": "Indian flatbread stuffed with spiced mashed potatoes.",
|
| 72 |
+
"price": "$3.99"},
|
| 73 |
+
{"name": "Egg Curry", "category": "HALAL",
|
| 74 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/egg_curry.jpg",
|
| 75 |
+
"description": "Boiled eggs cooked in a spiced tomato gravy.",
|
| 76 |
+
"price": "$9.99"},
|
| 77 |
+
{"name": "Chickpea Salad", "category": "VEGAN",
|
| 78 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chickpea_salad.jpg",
|
| 79 |
+
"description": "A refreshing salad made with chickpeas, fresh vegetables, and herbs.",
|
| 80 |
+
"price": "$7.99"}
|
| 81 |
]
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
# Spice levels and extras
|
| 85 |
+
spice_levels = ["American Mild", "American Medium", "American Spicy",
|
| 86 |
+
"Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
|
| 87 |
+
extras = [
|
| 88 |
+
{"name": "Extra Raitha 4oz", "price": "$1.00"},
|
| 89 |
+
{"name": "Extra Raitha 8oz", "price": "$2.00"},
|
| 90 |
+
{"name": "Extra Salan 4oz", "price": "$1.00"},
|
| 91 |
+
{"name": "Extra Salan 8oz", "price": "$2.00"},
|
| 92 |
+
{"name": "Extra Onion", "price": "$1.00"},
|
| 93 |
+
{"name": "Extra Onion & Lemon", "price": "$2.00"},
|
| 94 |
+
{"name": "Extra Fried Onion 4oz", "price": "$2.00"},
|
| 95 |
+
]
|
| 96 |
+
|
| 97 |
+
# Filter dishes by category
|
| 98 |
+
def filter_dishes(category):
|
| 99 |
+
if category == "ALL":
|
| 100 |
+
return menu_data
|
| 101 |
+
return [dish for dish in menu_data if dish["category"] == category]
|
| 102 |
|
| 103 |
+
# Generate dish cards with "Add" button
|
| 104 |
def display_dishes(category):
|
| 105 |
+
filtered_dishes = filter_dishes(category)
|
| 106 |
+
html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"
|
| 107 |
+
for dish in filtered_dishes:
|
| 108 |
+
html_content += f"""
|
| 109 |
+
<div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
|
| 110 |
+
width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 111 |
+
background-color: #f9f9f9;'>
|
| 112 |
+
<div style='flex: 1; margin-right: 20px; text-align: left;'>
|
| 113 |
+
<h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
|
| 114 |
+
<p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
|
| 115 |
+
<p style='font-size: 16px; color: #444; margin: 0;'>Price: {dish['price']}</p>
|
| 116 |
+
</div>
|
| 117 |
+
<div style='text-align: center;'>
|
| 118 |
+
<img src='{dish['image']}' alt='{dish['name']}'
|
| 119 |
+
style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
|
| 120 |
+
<button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')"
|
| 121 |
+
style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 122 |
+
border-radius: 5px; cursor: pointer;">Add</button>
|
| 123 |
</div>
|
| 124 |
+
</div>
|
| 125 |
+
"""
|
| 126 |
html_content += "</div>"
|
| 127 |
return html_content
|
| 128 |
|
| 129 |
+
# Main Gradio App
|
| 130 |
+
with gr.Blocks() as demo:
|
| 131 |
+
gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
+
# Buttons for category selection
|
| 134 |
+
with gr.Row():
|
| 135 |
+
btn_all = gr.Button("ALL")
|
| 136 |
+
btn_vegan = gr.Button("VEGAN")
|
| 137 |
+
btn_halal = gr.Button("HALAL")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
# Dish display
|
| 140 |
+
dish_display = gr.HTML(value=display_dishes("ALL"))
|
|
|
|
|
|
|
| 141 |
|
| 142 |
+
# JavaScript for managing the pop-up
|
| 143 |
+
gr.HTML(f"""
|
| 144 |
+
<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 145 |
+
background-color: white; padding: 20px; border-radius: 10px;
|
| 146 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
|
| 147 |
+
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 148 |
+
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 149 |
+
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 150 |
+
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 151 |
+
|
| 152 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
|
| 153 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 154 |
+
""" + "".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]) + """
|
| 155 |
+
</div>
|
| 156 |
|
| 157 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 158 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 159 |
+
""" + "".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]) + """
|
| 160 |
+
</div>
|
| 161 |
|
| 162 |
+
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
|
| 163 |
+
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 164 |
+
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 165 |
+
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 166 |
+
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 167 |
+
</div>
|
| 168 |
+
<script>
|
| 169 |
+
function showPopup(image, title, description, price) {
|
| 170 |
+
document.getElementById('popup-image').src = image;
|
| 171 |
+
document.getElementById('popup-title').textContent = title;
|
| 172 |
+
document.getElementById('popup-description').textContent = description;
|
| 173 |
+
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 174 |
|
| 175 |
+
// Display the popup
|
| 176 |
+
document.getElementById('popup').style.display = 'block';
|
| 177 |
+
}
|
| 178 |
+
function closePopup() {
|
| 179 |
+
document.getElementById('popup').style.display = 'none';
|
| 180 |
+
}
|
| 181 |
+
function addToCart(dishName, spiceLevel) {
|
| 182 |
+
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 183 |
+
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
| 184 |
+
}
|
| 185 |
+
</script>
|
| 186 |
+
""")
|
| 187 |
|
| 188 |
+
# Button click events
|
| 189 |
+
btn_all.click(
|
| 190 |
+
lambda: gr.update(value=display_dishes("ALL")),
|
| 191 |
+
outputs=dish_display
|
| 192 |
+
)
|
| 193 |
+
btn_vegan.click(
|
| 194 |
+
lambda: gr.update(value=display_dishes("VEGAN")),
|
| 195 |
+
outputs=dish_display
|
| 196 |
+
)
|
| 197 |
+
btn_halal.click(
|
| 198 |
+
lambda: gr.update(value=display_dishes("HALAL")),
|
| 199 |
+
outputs=dish_display
|
| 200 |
)
|
| 201 |
|
| 202 |
+
demo.launch()
|
|
|