Spaces:
Sleeping
Sleeping
Update app.py
Browse files137 unmodified lines138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246137 unmodified lines# Dish displaydish_display = gr.HTML(value=display_dishes("ALL"))popup_js = """<script>let cursorX = 0;let cursorY = 0;document.addEventListener("mousemove", (event) => {cursorX = event.clientX;cursorY = event.clientY;});function showPopup(name, description, price) {const popup = document.getElementById("custom-popup");popup.style.left = cursorX + "px";popup.style.top = cursorY + "px";popup.innerHTML = `<h3 style="margin: 0;">${name}</h3><p style="margin: 5px 0;">${description}</p><p style="margin: 5px 0; font-weight: bold;">Price: ${price}</p>`;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; border-radius: 10px; box-shadow: 0px 4px 6px rgba(0,0,0,0.1);"></div>"""# Generate dish cardsdef display_dishes(category):html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: space-between;'>"for dish in menu_data:if category == "ALL" or dish["category"] == category: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 onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}')"style='background-color: #007bff; color: white; border: none; padding: 5px 10px; cursor: pointer;'>Add</button></div>"""html_content += "</div>"return html_content# 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 onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')"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"))# JavaScript for managing the pop-upgr.HTML(f"""137 unmodified lines138139140141142143137 unmodified lines# Dish displaydish_display = gr.HTML(value=display_dishes("ALL"))# JavaScript for managing the pop-upgr.HTML(f"""
app.py-103