Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -129,7 +129,10 @@ modal_and_cart_js = """
|
|
| 129 |
});
|
| 130 |
finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 131 |
document.getElementById('final-order').innerHTML = finalOrderHTML;
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
| 133 |
}
|
| 134 |
</script>
|
| 135 |
"""
|
|
@@ -139,80 +142,46 @@ def app():
|
|
| 139 |
with gr.Blocks() as demo:
|
| 140 |
gr.Markdown("## Dynamic Menu with Preferences")
|
| 141 |
|
| 142 |
-
#
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
#
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
<div id="spice-level-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 171 |
-
<label><input type="radio" name="spice-level" value="American Mild" /> American Mild</label>
|
| 172 |
-
<label><input type="radio" name="spice-level" value="American Medium" /> American Medium</label>
|
| 173 |
-
<label><input type="radio" name="spice-level" value="American Spicy" /> American Spicy</label>
|
| 174 |
-
<label><input type="radio" name="spice-level" value="Indian Mild" /> Indian Mild</label>
|
| 175 |
-
<label><input type="radio" name="spice-level" value="Indian Medium" /> Indian Medium</label>
|
| 176 |
-
<label><input type="radio" name="spice-level" value="Indian Very Spicy" /> Indian Very Spicy</label>
|
| 177 |
-
</div>
|
| 178 |
-
<!-- Biryani Extras -->
|
| 179 |
-
<label for="biryani-extras">Biryani Extras (Optional - Choose as many as you like):</label>
|
| 180 |
-
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 181 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha 4oz" /> Extra Raitha 4oz + $1.00</label>
|
| 182 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha 8oz" /> Extra Raitha 8oz + $2.00</label>
|
| 183 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Salan 4oz" /> Extra Salan 4oz + $1.00</label>
|
| 184 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Salan 8oz" /> Extra Salan 8oz + $2.00</label>
|
| 185 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Onion" /> Extra Onion + $1.00</label>
|
| 186 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
|
| 187 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Fried Onion 4oz" /> Extra Fried Onion 4oz + $2.00</label>
|
| 188 |
-
</div>
|
| 189 |
-
<!-- Quantity and Special Instructions -->
|
| 190 |
-
<label for="quantity">Quantity:</label>
|
| 191 |
-
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
| 192 |
-
<br><br>
|
| 193 |
-
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
| 194 |
-
<br><br>
|
| 195 |
-
<!-- Add to Cart Button -->
|
| 196 |
-
<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>
|
| 197 |
-
</div>
|
| 198 |
-
""")
|
| 199 |
-
|
| 200 |
-
# Finalize Order Button
|
| 201 |
-
finalize_button = gr.Button("Finalize Order")
|
| 202 |
-
|
| 203 |
-
# Finalize order button click event
|
| 204 |
-
finalize_button.click(lambda: "Order finalized!", outputs=[final_order_output])
|
| 205 |
|
| 206 |
# Update menu dynamically based on preference
|
| 207 |
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 208 |
|
|
|
|
|
|
|
|
|
|
| 209 |
# Layout
|
| 210 |
-
gr.Row([
|
| 211 |
-
gr.Row(
|
| 212 |
-
gr.Row(
|
| 213 |
-
gr.Row(
|
| 214 |
-
gr.Row(finalize_button)
|
| 215 |
-
gr.Row(final_order_output)
|
| 216 |
gr.HTML(modal_and_cart_js)
|
| 217 |
|
| 218 |
return demo
|
|
|
|
| 129 |
});
|
| 130 |
finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 131 |
document.getElementById('final-order').innerHTML = finalOrderHTML;
|
| 132 |
+
document.getElementById('menu-container').style.display = 'none';
|
| 133 |
+
document.getElementById('cart-container').style.display = 'none';
|
| 134 |
+
document.getElementById('finalize-container').style.display = 'none';
|
| 135 |
+
document.getElementById('final-order-container').style.display = 'block';
|
| 136 |
}
|
| 137 |
</script>
|
| 138 |
"""
|
|
|
|
| 142 |
with gr.Blocks() as demo:
|
| 143 |
gr.Markdown("## Dynamic Menu with Preferences")
|
| 144 |
|
| 145 |
+
# Menu container
|
| 146 |
+
menu_container = gr.Group(visible=True, elem_id="menu-container")
|
| 147 |
+
with menu_container:
|
| 148 |
+
# Radio button for selecting preference
|
| 149 |
+
selected_preference = gr.Radio(
|
| 150 |
+
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
| 151 |
+
value="All",
|
| 152 |
+
label="Choose a Preference",
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
# Output area for menu items
|
| 156 |
+
menu_output = gr.HTML(value=filter_menu("All"))
|
| 157 |
+
|
| 158 |
+
# Cart container
|
| 159 |
+
cart_container = gr.Group(visible=True, elem_id="cart-container")
|
| 160 |
+
with cart_container:
|
| 161 |
+
# Floating cart display
|
| 162 |
+
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
| 163 |
+
|
| 164 |
+
# Finalize order button
|
| 165 |
+
finalize_container = gr.Group(visible=True, elem_id="finalize-container")
|
| 166 |
+
with finalize_container:
|
| 167 |
+
finalize_button = gr.Button("Finalize Order")
|
| 168 |
+
|
| 169 |
+
# Final order display container
|
| 170 |
+
final_order_container = gr.Group(visible=False, elem_id="final-order-container")
|
| 171 |
+
with final_order_container:
|
| 172 |
+
final_order_output = gr.HTML(value="", elem_id="final-order")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
# Update menu dynamically based on preference
|
| 175 |
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 176 |
|
| 177 |
+
# Finalize order button click event
|
| 178 |
+
finalize_button.click(None, [], [final_order_output], _js="finalizeOrder")
|
| 179 |
+
|
| 180 |
# Layout
|
| 181 |
+
gr.Row([menu_container])
|
| 182 |
+
gr.Row([cart_container])
|
| 183 |
+
gr.Row([finalize_container])
|
| 184 |
+
gr.Row([final_order_container])
|
|
|
|
|
|
|
| 185 |
gr.HTML(modal_and_cart_js)
|
| 186 |
|
| 187 |
return demo
|