Spaces:
Sleeping
Sleeping
Update app.py
Browse files81 unmodified lines82838485868788899031 unmodified lines12212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617719 unmodified lines19719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225381 unmodified lines# Spice levels and extrasspice_levels = ["American Mild", "American Medium", "American Spicy","Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]extras = [{"name": "Extra Raitha 4oz", "price": "$1.00"},{"name": "Extra Raitha 8oz", "price": "$2.00"},31 unmodified lines`).join("")}</div><button onclick="closePopup()" 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; margin-left: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>`;popup.style.display = "block";overlay.style.display = "block";}function closePopup() {const popup = document.getElementById("custom-popup");const overlay = document.getElementById("overlay");popup.style.display = "none";overlay.style.display = "none";}</script>"""# HTML for popup modalpopup_html = """<div id="overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; z-index: 999;"></div><div id="custom-popup"style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 60%; max-width: 600px; background: white; padding: 20px; border-radius: 10px; box-shadow: 0px 4px 6px rgba(0,0,0,0.1); display: none; z-index: 1000; text-align: center;"></div>"""# Generate dish cardsimport gradio as grmenu_data = [{"name": "Veg Burger", "category": "VEGAN","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg","description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.","price": "$8.99"},{"name": "Chicken Biryani", "category": "HALAL","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg","description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.","price": "$12.99"}# Add more items as needed]# JavaScript for popup modalpopup_js = """<script>function showPopup(name, description, price, image) {const popup = document.getElementById("custom-popup");const overlay = document.getElementById("overlay");popup.innerHTML = `<img src="${image}" alt="${name}" style="width: auto; height: 250px; border-radius: 10px; margin-bottom: 10px;"><h3 style="margin-top: 10px;">${name}</h3><p>${description}</p><p style="font-weight: bold;">Price: ${price}</p><button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button><button onclick="closePopup()" style="margin-top: 20px; margin-left: 10px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>`;19 unmodified lines"""# Generate dish cardsdef display_dishes(category):html_content = "<div style='display: flex; flex-direction: column; gap: 20px; width: 80%; margin: auto;'>"for dish in menu_data:if category == "ALL" or dish["category"] == category:html_content += f"""<div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'><div style='flex: 3; text-align: left;'><h3 style='margin: 0; font-size: 20px;'>{dish['name']}</h3><p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p><p style='margin: 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p></div><div style='flex: 1; display: flex; flex-direction: row; align-items: center;'><img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px; margin-bottom: 10px;'><button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"style='padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>Add</button></div></div>"""html_content += "</div>"return html_content# Main Gradio Appwith gr.Blocks() as demo:gr.HTML(popup_html) # Add the popup container and overlaygr.HTML(popup_js) # Add the JavaScriptgr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")# Buttons for filtering categorieswith 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"))# 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()81 unmodified lines8283848586878831 unmodified lines12012112212312412519 unmodified lines14514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918081 unmodified linesspice_levels = ["American Mild", "American Medium", "American Spicy", "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]extras = [{"name": "Extra Raitha 4oz", "price": "$1.00"},{"name": "Extra Raitha 8oz", "price": "$2.00"},31 unmodified lines`).join("")}</div><button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button><button onclick="closePopup()" style="margin-top: 20px; margin-left: 10px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>`;19 unmodified lines"""# Generate dish cardsdef display_dishes():html_content = "<div style='display: flex; flex-direction: column; gap: 20px; width: 80%; margin: auto;'>"for dish in menu_data:html_content += f"""<div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'><div style='flex: 3; text-align: left;'><h3 style='margin: 0; font-size: 20px;'>{dish['name']}</h3><p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p><p style='margin: 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p></div><div style='flex: 1; display: flex; flex-direction: column; align-items: center;'><img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px; margin-bottom: 10px;'><button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"style='padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>Add</button></div></div>"""html_content += "</div>"return html_content# Main Gradio Appwith gr.Blocks() as demo:gr.HTML(popup_html) # Add the popup container and overlaygr.HTML(popup_js) # Add the JavaScriptgr.HTML("<h1 style='text-align: center;'>\ud83c\udf5b Biryani Hub Menu \ud83c\udf5b</h1>")# Dish displaydish_display = gr.HTML(value=display_dishes())demo.launch()
app.py+20-93