Spaces:
Sleeping
Sleeping
Update app.py
Browse files137 unmodified lines138139140141142143137 unmodified lines# Dish displaydish_display = gr.HTML(value=display_dishes("ALL"))# JavaScript for managing the pop-upgr.HTML(f"""137 unmodified lines138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232137 unmodified lines# Dish displaydish_display = gr.HTML(value=display_dishes("ALL"))popup_js = """<script>document.addEventListener("mousemove", (event) => {const popup = document.getElementById("custom-popup");if (popup && popup.style.display === "block") {popup.style.left = event.clientX + "px";popup.style.top = event.clientY + "px";}});function showPopup(message) {const popup = document.getElementById("custom-popup");popup.innerHTML = message;popup.style.display = "block";}function hidePopup() {const popup = document.getElementById("custom-popup");popup.style.display = "none";}</script>"""# HTML for popup containerpopup_html = """<div id="custom-popup"style="position: fixed; display: none; background: white; border: 1px solid black; padding: 10px; z-index: 1000;"></div>"""# Filter dishes by categorydef filter_dishes(category):if category == "ALL":return menu_datareturn [dish for dish in menu_data if dish["category"] == category]# Generate dish cardsdef display_dishes(category):filtered_dishes = filter_dishes(category)html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: space-between;'>"for dish in filtered_dishes:html_content += f"""<div style='margin: 10px; width: 30%; border: 1px solid #ddd; border-radius: 10px; padding: 10px;'><img src='{dish['image']}' alt='{dish['name']}' style='width: 100%; height: auto; border-radius: 5px;'><h3>{dish['name']}</h3><p>{dish['description']}</p><p>Price: {dish['price']}</p><button onmouseover="showPopup('{dish['name']} - {dish['price']}')"onmouseout="hidePopup()"style='background-color: #007bff; color: white; border: none; padding: 5px 10px; cursor: pointer;'>Add</button></div>"""html_content += "</div>"return html_content# Main Gradio Appwith gr.Blocks() as demo:gr.HTML(popup_html) # Add the popup containergr.HTML(popup_js) # Add the JavaScriptgr.HTML("<h1 style='text-align: center;'>Dynamic Restaurant 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()# JavaScript for managing the pop-upgr.HTML(f"""
app.py+89