Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,6 +83,7 @@ menu_data = [
|
|
| 83 |
# The rest of the code remains unchanged
|
| 84 |
|
| 85 |
|
|
|
|
| 86 |
# Spice levels and extras
|
| 87 |
spice_levels = ["American Mild", "American Medium", "American Spicy",
|
| 88 |
"Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
|
|
@@ -152,37 +153,52 @@ with gr.Blocks() as demo:
|
|
| 152 |
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 153 |
|
| 154 |
<h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
|
| 155 |
-
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 156 |
""" + "".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]) + """
|
| 157 |
</div>
|
| 158 |
|
| 159 |
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 160 |
-
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 161 |
""" + "".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]) + """
|
| 162 |
</div>
|
| 163 |
|
| 164 |
-
<button onclick="addToCart(
|
| 165 |
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 166 |
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 167 |
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 168 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 169 |
</div>
|
| 170 |
<script>
|
|
|
|
|
|
|
|
|
|
| 171 |
function showPopup(image, title, description, price) {
|
| 172 |
document.getElementById('popup-image').src = image;
|
| 173 |
document.getElementById('popup-title').textContent = title;
|
| 174 |
document.getElementById('popup-description').textContent = description;
|
| 175 |
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
// Display the popup
|
| 178 |
document.getElementById('popup').style.display = 'block';
|
| 179 |
}
|
|
|
|
| 180 |
function closePopup() {
|
| 181 |
document.getElementById('popup').style.display = 'none';
|
| 182 |
}
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
</script>
|
| 188 |
""")
|
|
@@ -201,4 +217,4 @@ with gr.Blocks() as demo:
|
|
| 201 |
outputs=dish_display
|
| 202 |
)
|
| 203 |
|
| 204 |
-
demo.launch()
|
|
|
|
| 83 |
# The rest of the code remains unchanged
|
| 84 |
|
| 85 |
|
| 86 |
+
|
| 87 |
# Spice levels and extras
|
| 88 |
spice_levels = ["American Mild", "American Medium", "American Spicy",
|
| 89 |
"Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
|
|
|
|
| 153 |
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 154 |
|
| 155 |
<h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
|
| 156 |
+
<div id="spice-levels-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 157 |
""" + "".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]) + """
|
| 158 |
</div>
|
| 159 |
|
| 160 |
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 161 |
+
<div id="extras-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 162 |
""" + "".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]) + """
|
| 163 |
</div>
|
| 164 |
|
| 165 |
+
<button onclick="addToCart()"
|
| 166 |
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 167 |
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 168 |
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 169 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 170 |
</div>
|
| 171 |
<script>
|
| 172 |
+
let selectedSpice = null;
|
| 173 |
+
let selectedExtras = [];
|
| 174 |
+
|
| 175 |
function showPopup(image, title, description, price) {
|
| 176 |
document.getElementById('popup-image').src = image;
|
| 177 |
document.getElementById('popup-title').textContent = title;
|
| 178 |
document.getElementById('popup-description').textContent = description;
|
| 179 |
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 180 |
|
| 181 |
+
// Reset selections
|
| 182 |
+
selectedSpice = null;
|
| 183 |
+
selectedExtras = [];
|
| 184 |
+
const spiceInputs = document.querySelectorAll('input[name=spice]');
|
| 185 |
+
spiceInputs.forEach(input => input.checked = false);
|
| 186 |
+
const extraInputs = document.querySelectorAll('input[name=extras]');
|
| 187 |
+
extraInputs.forEach(input => input.checked = false);
|
| 188 |
+
|
| 189 |
// Display the popup
|
| 190 |
document.getElementById('popup').style.display = 'block';
|
| 191 |
}
|
| 192 |
+
|
| 193 |
function closePopup() {
|
| 194 |
document.getElementById('popup').style.display = 'none';
|
| 195 |
}
|
| 196 |
+
|
| 197 |
+
function addToCart() {
|
| 198 |
+
selectedSpice = document.querySelector('input[name=spice]:checked')?.value || "No spice selected";
|
| 199 |
+
selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(input => input.value);
|
| 200 |
+
alert(`Dish added with spice: ${selectedSpice} and extras: ${selectedExtras.join(", ")}`);
|
| 201 |
+
closePopup();
|
| 202 |
}
|
| 203 |
</script>
|
| 204 |
""")
|
|
|
|
| 217 |
outputs=dish_display
|
| 218 |
)
|
| 219 |
|
| 220 |
+
demo.launch()
|