Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,7 +62,6 @@ modal_and_cart_js = """
|
|
| 62 |
document.getElementById('modal-name').innerText = name;
|
| 63 |
document.getElementById('modal-description').innerText = description;
|
| 64 |
document.getElementById('modal-price').innerText = price;
|
| 65 |
-
// Reset spice levels and extras
|
| 66 |
const spiceLevelInputs = document.querySelectorAll('input[name="spice-level"]');
|
| 67 |
spiceLevelInputs.forEach(input => input.checked = false);
|
| 68 |
const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
|
|
@@ -98,22 +97,18 @@ modal_and_cart_js = """
|
|
| 98 |
cart.forEach((item, index) => {
|
| 99 |
totalBill += item.itemTotal;
|
| 100 |
const extras = item.extras.join(', ');
|
| 101 |
-
cartHTML += `<li
|
| 102 |
});
|
| 103 |
cartHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 104 |
document.getElementById('floating-cart').innerHTML = cartHTML;
|
| 105 |
}
|
| 106 |
-
function removeItem(index) {
|
| 107 |
-
cart.splice(index, 1);
|
| 108 |
-
updateCartDisplay();
|
| 109 |
-
}
|
| 110 |
function finalizeOrder() {
|
| 111 |
if (cart.length === 0) {
|
| 112 |
alert("Your cart is empty. Please add items before finalizing.");
|
| 113 |
return;
|
| 114 |
}
|
| 115 |
finalized = true;
|
| 116 |
-
let finalOrderHTML = "<h3>Final Order
|
| 117 |
let totalBill = 0;
|
| 118 |
cart.forEach(item => {
|
| 119 |
totalBill += item.itemTotal;
|
|
@@ -121,11 +116,8 @@ modal_and_cart_js = """
|
|
| 121 |
finalOrderHTML += `<li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>`;
|
| 122 |
});
|
| 123 |
finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 124 |
-
|
| 125 |
-
document.getElementById('
|
| 126 |
-
document.getElementById('cart-container').style.display = 'none';
|
| 127 |
-
document.getElementById('finalize-container').style.display = 'none';
|
| 128 |
-
document.getElementById('summary-container').style.display = 'block';
|
| 129 |
}
|
| 130 |
</script>
|
| 131 |
"""
|
|
@@ -135,46 +127,77 @@ def app():
|
|
| 135 |
with gr.Blocks() as demo:
|
| 136 |
gr.Markdown("## Dynamic Menu with Preferences")
|
| 137 |
|
| 138 |
-
#
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
value="All",
|
| 145 |
-
label="Choose a Preference",
|
| 146 |
-
)
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
|
| 151 |
-
#
|
| 152 |
-
|
| 153 |
-
with cart_container:
|
| 154 |
-
# Floating cart display
|
| 155 |
-
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
| 156 |
|
| 157 |
-
#
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
-
#
|
| 163 |
-
|
| 164 |
-
with summary_container:
|
| 165 |
-
summary_output = gr.HTML(value="", elem_id="summary-page")
|
| 166 |
|
| 167 |
# Update menu dynamically based on preference
|
| 168 |
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 169 |
|
| 170 |
-
# Finalize order button click event
|
| 171 |
-
finalize_button.click(lambda: "Order finalized!", inputs=[], outputs=[], _js="finalizeOrder")
|
| 172 |
-
|
| 173 |
# Layout
|
| 174 |
-
gr.Row([
|
| 175 |
-
gr.Row(
|
| 176 |
-
gr.Row(
|
| 177 |
-
gr.Row(
|
|
|
|
|
|
|
| 178 |
gr.HTML(modal_and_cart_js)
|
| 179 |
|
| 180 |
return demo
|
|
|
|
| 62 |
document.getElementById('modal-name').innerText = name;
|
| 63 |
document.getElementById('modal-description').innerText = description;
|
| 64 |
document.getElementById('modal-price').innerText = price;
|
|
|
|
| 65 |
const spiceLevelInputs = document.querySelectorAll('input[name="spice-level"]');
|
| 66 |
spiceLevelInputs.forEach(input => input.checked = false);
|
| 67 |
const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
|
|
|
|
| 97 |
cart.forEach((item, index) => {
|
| 98 |
totalBill += item.itemTotal;
|
| 99 |
const extras = item.extras.join(', ');
|
| 100 |
+
cartHTML += `<li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>`;
|
| 101 |
});
|
| 102 |
cartHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 103 |
document.getElementById('floating-cart').innerHTML = cartHTML;
|
| 104 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
function finalizeOrder() {
|
| 106 |
if (cart.length === 0) {
|
| 107 |
alert("Your cart is empty. Please add items before finalizing.");
|
| 108 |
return;
|
| 109 |
}
|
| 110 |
finalized = true;
|
| 111 |
+
let finalOrderHTML = "<h3>Your Final Order:</h3><ul>";
|
| 112 |
let totalBill = 0;
|
| 113 |
cart.forEach(item => {
|
| 114 |
totalBill += item.itemTotal;
|
|
|
|
| 116 |
finalOrderHTML += `<li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>`;
|
| 117 |
});
|
| 118 |
finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 119 |
+
finalOrderHTML += `<p style='color: green; font-size: 18px;'>Your final order has been placed. Thank you!</p>`;
|
| 120 |
+
document.getElementById('final-order').innerHTML = finalOrderHTML;
|
|
|
|
|
|
|
|
|
|
| 121 |
}
|
| 122 |
</script>
|
| 123 |
"""
|
|
|
|
| 127 |
with gr.Blocks() as demo:
|
| 128 |
gr.Markdown("## Dynamic Menu with Preferences")
|
| 129 |
|
| 130 |
+
# Radio button for selecting preference
|
| 131 |
+
selected_preference = gr.Radio(
|
| 132 |
+
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
| 133 |
+
value="All",
|
| 134 |
+
label="Choose a Preference",
|
| 135 |
+
)
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
+
# Output area for menu items
|
| 138 |
+
menu_output = gr.HTML(value=filter_menu("All"))
|
| 139 |
|
| 140 |
+
# Floating cart display
|
| 141 |
+
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
+
# Final order display
|
| 144 |
+
final_order_output = gr.HTML(value="", elem_id="final-order")
|
| 145 |
+
|
| 146 |
+
# Modal window
|
| 147 |
+
modal_window = gr.HTML("""
|
| 148 |
+
<div id="modal" style="display: none; position: fixed; top: 40%; left: 50%; transform: translate(-50%, -40%); width: 50%; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
|
| 149 |
+
<div style="text-align: right;">
|
| 150 |
+
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
| 151 |
+
</div>
|
| 152 |
+
<img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
|
| 153 |
+
<h2 id="modal-name"></h2>
|
| 154 |
+
<p id="modal-description"></p>
|
| 155 |
+
<p id="modal-price"></p>
|
| 156 |
+
<!-- Spice Levels -->
|
| 157 |
+
<label for="spice-level">Choose a Spice Level (Required):</label>
|
| 158 |
+
<div id="spice-level-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 159 |
+
<label><input type="radio" name="spice-level" value="American Mild" /> American Mild</label>
|
| 160 |
+
<label><input type="radio" name="spice-level" value="American Medium" /> American Medium</label>
|
| 161 |
+
<label><input type="radio" name="spice-level" value="American Spicy" /> American Spicy</label>
|
| 162 |
+
<label><input type="radio" name="spice-level" value="Indian Mild" /> Indian Mild</label>
|
| 163 |
+
<label><input type="radio" name="spice-level" value="Indian Medium" /> Indian Medium</label>
|
| 164 |
+
<label><input type="radio" name="spice-level" value="Indian Very Spicy" /> Indian Very Spicy</label>
|
| 165 |
+
</div>
|
| 166 |
+
<!-- Biryani Extras -->
|
| 167 |
+
<label for="biryani-extras">Biryani Extras (Optional - Choose as many as you like):</label>
|
| 168 |
+
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 169 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha 4oz" /> Extra Raitha 4oz + $1.00</label>
|
| 170 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha 8oz" /> Extra Raitha 8oz + $2.00</label>
|
| 171 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Salan 4oz" /> Extra Salan 4oz + $1.00</label>
|
| 172 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Salan 8oz" /> Extra Salan 8oz + $2.00</label>
|
| 173 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Onion" /> Extra Onion + $1.00</label>
|
| 174 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
|
| 175 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Fried Onion 4oz" /> Extra Fried Onion 4oz + $2.00</label>
|
| 176 |
+
</div>
|
| 177 |
+
<!-- Quantity and Special Instructions -->
|
| 178 |
+
<label for="quantity">Quantity:</label>
|
| 179 |
+
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
| 180 |
+
<br><br>
|
| 181 |
+
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
| 182 |
+
<br><br>
|
| 183 |
+
<!-- Add to Cart Button -->
|
| 184 |
+
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
|
| 185 |
+
</div>
|
| 186 |
+
""")
|
| 187 |
|
| 188 |
+
# Finalize Order Button
|
| 189 |
+
finalize_button = gr.Button("Finalize Order")
|
|
|
|
|
|
|
| 190 |
|
| 191 |
# Update menu dynamically based on preference
|
| 192 |
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 193 |
|
|
|
|
|
|
|
|
|
|
| 194 |
# Layout
|
| 195 |
+
gr.Row([selected_preference])
|
| 196 |
+
gr.Row(menu_output)
|
| 197 |
+
gr.Row(cart_output)
|
| 198 |
+
gr.Row(modal_window)
|
| 199 |
+
gr.Row(finalize_button)
|
| 200 |
+
gr.Row(final_order_output)
|
| 201 |
gr.HTML(modal_and_cart_js)
|
| 202 |
|
| 203 |
return demo
|