Spaces:
Sleeping
Sleeping
Update app.py
Browse files65 unmodified lines6667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513665 unmodified linesreturn html_content# Main Gradio Appwith gr.Blocks() as demo:gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")# Buttons for category selectionwith gr.Row():btn_all = gr.Button("ALL")btn_vegan = gr.Button("VEGAN")btn_halal = gr.Button("HALAL")# Dish displaydish_display = gr.HTML(value=display_dishes("ALL"))# JavaScript for managing the pop-upgr.HTML(f"""<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);background-color: white; padding: 20px; border-radius: 10px;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;"><img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;"><h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2><p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p><p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p><h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4><div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">""" + "".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]) + """</div><button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;border-radius: 5px; cursor: pointer;">Add to Cart</button><button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button></div><script>function showPopup(image, title, description, price) {document.getElementById('popup-image').src = image;document.getElementById('popup-title').textContent = title;document.getElementById('popup-description').textContent = description;document.getElementById('popup-price').textContent = "Price: " + price;// Display the popupdocument.getElementById('popup').style.display = 'block';}function closePopup() {document.getElementById('popup').style.display = 'none';}function addToCart(dishName, spiceLevel) {const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");}</script>""")# Button click eventsbtn_all.click(lambda: gr.update(value=display_dishes("ALL")),outputs=dish_display)btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")),outputs=dish_display)btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")),outputs=dish_display)demo.launch()65 unmodified lines6667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414565 unmodified linesreturn html_content# Add to cartdef add_to_cart(item_name, quantity, custom_preference):cart.append({"name": item_name, "quantity": quantity, "custom_preference": custom_preference})return display_cart()# Display cart itemsdef display_cart():if not cart:return "<p>Your cart is empty.</p>"html_content = "<div style='text-align: left;'>"for item in cart:html_content += f"<p>- {item['name']} (x{item['quantity']}) - Custom: {item['custom_preference']}</p>"html_content += "</div>"return html_content# Main Gradio Appwith gr.Blocks() as demo:gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")with gr.Row():btn_cart = gr.Button("View Cart")cart_display = gr.HTML(value=display_cart())with gr.Row():btn_all = gr.Button("ALL")btn_vegan = gr.Button("VEGAN")btn_halal = gr.Button("HALAL")dish_display = gr.HTML(value=display_dishes("ALL"))gr.HTML(f"""<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 400px;"><span onclick="closePopup()" style="position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 18px;">×</span><img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;"><h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2><p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p><p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p><label for="popup-quantity" style="margin-top: 20px; display: block; text-align: left;">Quantity:</label><input id="popup-quantity" type="number" min="1" value="1" style="width: 100%; margin-top: 10px; padding: 5px; border: 1px solid #ddd; border-radius: 5px;"><label for="popup-custom" style="margin-top: 20px; display: block; text-align: left;">Custom Preferences:</label><textarea id="popup-custom" placeholder="Add your custom preferences here..." style="width: 100%; margin-top: 10px; padding: 5px; border: 1px solid #ddd; border-radius: 5px;"></textarea><button onclick="submitPopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button></div><script>function showPopup(name, description, price, image) {document.getElementById('popup-title').textContent = name;document.getElementById('popup-description').textContent = description;document.getElementById('popup-price').textContent = price;document.getElementById('popup-image').src = image;document.getElementById('popup').style.display = 'block';}function closePopup() {document.getElementById('popup').style.display = 'none';}function submitPopup() {const name = document.getElementById('popup-title').textContent;const quantity = document.getElementById('popup-quantity').value;const customPreference = document.getElementById('popup-custom').value;gr.Interface.postMessage('add_to_cart', [name, quantity, customPreference]);closePopup();}</script>")# Button click eventsbtn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)btn_cart.click(lambda: gr.update(value=display_cart()), outputs=cart_display)demo.launch()
app.py+48-39