Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from cart import Cart # Import Cart from cart.py
|
| 3 |
-
|
| 4 |
|
| 5 |
# Menu data
|
| 6 |
menu_data = [
|
|
@@ -22,10 +20,15 @@ menu_data = [
|
|
| 22 |
{"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},
|
| 23 |
]
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Filter dishes by category
|
| 31 |
def filter_dishes(category):
|
|
@@ -33,90 +36,100 @@ def filter_dishes(category):
|
|
| 33 |
return menu_data
|
| 34 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
def
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
<
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
</div>
|
| 55 |
"""
|
| 56 |
-
|
| 57 |
-
return
|
| 58 |
|
| 59 |
# Main Gradio App
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
-
gr.HTML("<h1 style='text-align: center;'>π Biryani Hub Menu π</h1>")
|
| 62 |
|
| 63 |
-
#
|
| 64 |
with gr.Row():
|
| 65 |
btn_all = gr.Button("ALL")
|
| 66 |
btn_vegan = gr.Button("VEGAN")
|
| 67 |
btn_halal = gr.Button("HALAL")
|
| 68 |
|
| 69 |
-
# Dish display
|
| 70 |
-
dish_display = gr.HTML()
|
| 71 |
-
popup_display = gr.HTML()
|
| 72 |
-
cart_display = gr.HTML("Cart is empty.")
|
| 73 |
-
cart_total = gr.Textbox(value="Total: $0.00", interactive=False)
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
<
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
</div>
|
| 86 |
-
"""
|
| 87 |
-
html_content += "</div>"
|
| 88 |
-
return html_content
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
<script>
|
| 93 |
-
function showPopup(
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
.
|
| 101 |
-
document.getElementById("popup").innerHTML = data.html;
|
| 102 |
-
document.getElementById("popup").style.display = "block";
|
| 103 |
-
});
|
| 104 |
}
|
| 105 |
function closePopup() {
|
| 106 |
-
document.getElementById(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
}
|
| 108 |
</script>
|
| 109 |
""")
|
| 110 |
|
| 111 |
-
#
|
| 112 |
-
btn_all.click(
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# Menu data
|
| 4 |
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 |
+
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):
|
|
|
|
| 36 |
return menu_data
|
| 37 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 38 |
|
| 39 |
+
# Generate dish cards with "Add" button
|
| 40 |
+
def display_dishes(category):
|
| 41 |
+
filtered_dishes = filter_dishes(category)
|
| 42 |
+
html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"
|
| 43 |
+
for dish in filtered_dishes:
|
| 44 |
+
html_content += f"""
|
| 45 |
+
<div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
|
| 46 |
+
width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 47 |
+
background-color: #f9f9f9;'>
|
| 48 |
+
<div style='flex: 1; margin-right: 20px; text-align: left;'>
|
| 49 |
+
<h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
|
| 50 |
+
<p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
|
| 51 |
+
<p style='font-size: 16px; color: #444; margin: 0;'>Price: {dish['price']}</p>
|
| 52 |
+
</div>
|
| 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>
|
| 60 |
</div>
|
| 61 |
"""
|
| 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 |
+
|
| 89 |
+
|
| 90 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 91 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 92 |
+
""" + "".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]) + """
|
| 93 |
</div>
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
|
| 96 |
+
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 97 |
+
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 98 |
+
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 99 |
+
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 100 |
+
</div>
|
| 101 |
<script>
|
| 102 |
+
function showPopup(image, title, description, price) {
|
| 103 |
+
document.getElementById('popup-image').src = image;
|
| 104 |
+
document.getElementById('popup-title').textContent = title;
|
| 105 |
+
document.getElementById('popup-description').textContent = description;
|
| 106 |
+
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 107 |
+
|
| 108 |
+
// Display the popup
|
| 109 |
+
document.getElementById('popup').style.display = 'block';
|
|
|
|
|
|
|
|
|
|
| 110 |
}
|
| 111 |
function closePopup() {
|
| 112 |
+
document.getElementById('popup').style.display = 'none';
|
| 113 |
+
}
|
| 114 |
+
function addToCart(dishName, spiceLevel) {
|
| 115 |
+
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 116 |
+
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
| 117 |
}
|
| 118 |
</script>
|
| 119 |
""")
|
| 120 |
|
| 121 |
+
# Button click events
|
| 122 |
+
btn_all.click(
|
| 123 |
+
lambda: gr.update(value=display_dishes("ALL")),
|
| 124 |
+
outputs=dish_display
|
| 125 |
+
)
|
| 126 |
+
btn_vegan.click(
|
| 127 |
+
lambda: gr.update(value=display_dishes("VEGAN")),
|
| 128 |
+
outputs=dish_display
|
| 129 |
+
)
|
| 130 |
+
btn_halal.click(
|
| 131 |
+
lambda: gr.update(value=display_dishes("HALAL")),
|
| 132 |
+
outputs=dish_display
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
demo.launch()
|