Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,6 +63,10 @@ menu_data = [
|
|
| 63 |
# The rest of the code remains unchanged
|
| 64 |
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
def filter_dishes(category):
|
| 67 |
if category == "ALL":
|
| 68 |
return menu_data
|
|
@@ -80,11 +84,12 @@ def display_dishes(category):
|
|
| 80 |
<div style='flex: 1; margin-right: 20px; text-align: left;'>
|
| 81 |
<h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
|
| 82 |
<p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
|
|
|
|
| 83 |
</div>
|
| 84 |
<div style='text-align: center;'>
|
| 85 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 86 |
style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
|
| 87 |
-
<button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}')"
|
| 88 |
style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 89 |
border-radius: 5px; cursor: pointer;">Add</button>
|
| 90 |
</div>
|
|
@@ -110,21 +115,29 @@ with gr.Blocks() as demo:
|
|
| 110 |
gr.HTML("""
|
| 111 |
<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 112 |
background-color: white; padding: 20px; border-radius: 10px;
|
| 113 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width:
|
| 114 |
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 115 |
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 116 |
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 117 |
-
<
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 120 |
-
<button onclick="closePopup()" style="margin-top:
|
| 121 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 122 |
</div>
|
| 123 |
<script>
|
| 124 |
-
function showPopup(image, title, description) {
|
| 125 |
document.getElementById('popup-image').src = image;
|
| 126 |
document.getElementById('popup-title').textContent = title;
|
| 127 |
document.getElementById('popup-description').textContent = description;
|
|
|
|
| 128 |
|
| 129 |
// Display the popup
|
| 130 |
document.getElementById('popup').style.display = 'block';
|
|
@@ -132,8 +145,8 @@ with gr.Blocks() as demo:
|
|
| 132 |
function closePopup() {
|
| 133 |
document.getElementById('popup').style.display = 'none';
|
| 134 |
}
|
| 135 |
-
function addToCart(dishName) {
|
| 136 |
-
alert(dishName + " has been added to the cart!");
|
| 137 |
}
|
| 138 |
</script>
|
| 139 |
""")
|
|
|
|
| 63 |
# The rest of the code remains unchanged
|
| 64 |
|
| 65 |
|
| 66 |
+
spice_levels = ["American Mild", "American Medium", "American Spicy",
|
| 67 |
+
"Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
|
| 68 |
+
|
| 69 |
+
# Filter dishes by category
|
| 70 |
def filter_dishes(category):
|
| 71 |
if category == "ALL":
|
| 72 |
return menu_data
|
|
|
|
| 84 |
<div style='flex: 1; margin-right: 20px; text-align: left;'>
|
| 85 |
<h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
|
| 86 |
<p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
|
| 87 |
+
<p style='font-size: 16px; color: #444; margin: 0;'>Price: {dish['price']}</p>
|
| 88 |
</div>
|
| 89 |
<div style='text-align: center;'>
|
| 90 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 91 |
style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
|
| 92 |
+
<button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')"
|
| 93 |
style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 94 |
border-radius: 5px; cursor: pointer;">Add</button>
|
| 95 |
</div>
|
|
|
|
| 115 |
gr.HTML("""
|
| 116 |
<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 117 |
background-color: white; padding: 20px; border-radius: 10px;
|
| 118 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
|
| 119 |
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 120 |
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 121 |
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 122 |
+
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 123 |
+
|
| 124 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
|
| 125 |
+
<form id="spice-levels">
|
| 126 |
+
""" + "".join([f'<label style="margin-right: 10px;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>' for spice in spice_levels]) + """
|
| 127 |
+
</form>
|
| 128 |
+
|
| 129 |
+
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
|
| 130 |
+
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 131 |
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 132 |
+
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 133 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 134 |
</div>
|
| 135 |
<script>
|
| 136 |
+
function showPopup(image, title, description, price) {
|
| 137 |
document.getElementById('popup-image').src = image;
|
| 138 |
document.getElementById('popup-title').textContent = title;
|
| 139 |
document.getElementById('popup-description').textContent = description;
|
| 140 |
+
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 141 |
|
| 142 |
// Display the popup
|
| 143 |
document.getElementById('popup').style.display = 'block';
|
|
|
|
| 145 |
function closePopup() {
|
| 146 |
document.getElementById('popup').style.display = 'none';
|
| 147 |
}
|
| 148 |
+
function addToCart(dishName, spiceLevel) {
|
| 149 |
+
alert(dishName + " with " + spiceLevel + " spice level has been added to the cart!");
|
| 150 |
}
|
| 151 |
</script>
|
| 152 |
""")
|