Spaces:
Sleeping
Sleeping
Update app.py
Browse files12394 unmodified lines98991001011021031041 unmodified line10610710810911011111211311411511611711811912012112212312412512612712812913016 unmodified lines1471481491501511521531541551561578 unmodified lines166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213import gradio as grmenu_data = [94 unmodified linesfunction 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: 100%; height: 250px; border-radius: 10px; margin-bottom: 10px;"><h3 style="margin-top: 10px;">${name}</h3><p>${description}</p>1 unmodified line<h4 style="margin-top: 20px;">Choose a Spice Level</h4><div style="display: flex; flex-wrap: wrap; gap: 10px;">${["American Mild", "American Medium", "American Spicy", "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"].map(spice => `<label style="margin-right: 10px;"><input type="radio" name="spice" value="${spice}"> ${spice}</label>`).join("")}</div><h4 style="margin-top: 20px;">Choose Extras</h4><div style="display: flex; flex-wrap: wrap; gap: 10px;">${["Extra Raitha 4oz + $1.00", "Extra Raitha 8oz + $2.00", "Extra Onion + $1.00", "Extra Onion & Lemon + $2.00"].map(extra => `<label style="margin-right: 10px;"><input type="checkbox" name="extras" value="${extra}"> ${extra}</label>`).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";}16 unmodified lines"""# Generate dish cardsdef display_dishes(category, keyword=""):html_content = "<div style='display: flex; flex-direction: column; gap: 20px; padding-bottom: 20px; box-sizing: border-box;'>"for dish in menu_data:# Filter by category and keywordif (category == "ALL" or dish["category"] == category) and (keyword.lower() in dish["name"].lower()):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;'>8 unmodified linesAdd</button></div></div>"""html_content += "</div>"return html_content# Main Gradio Appwith gr.Blocks(css="#dish-container {min-height: 100vh; overflow-y: auto;}") 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>")# Two containerswith gr.Row():with gr.Column():gr.HTML("<h2 style='text-align: center;'>All Dishes</h2>")all_dishes_display = gr.HTML(value=display_dishes("ALL"))with gr.Column():gr.HTML("<h2 style='text-align: center;'>Vegan and Halal Dishes</h2>")vegan_halal_display = gr.HTML(value=display_dishes("ALL", keyword=""))# Inputs to filter containerskeyword_input_all = gr.Textbox(label="Search in All Dishes",placeholder="Enter keyword to filter (e.g., Chicken)")keyword_input_vegan_halal = gr.Textbox(label="Search in Vegan and Halal",placeholder="Enter keyword to filter (e.g., Curry)")# Update containers dynamicallykeyword_input_all.change(lambda keyword: gr.update(value=display_dishes("ALL", keyword)),inputs=keyword_input_all,outputs=all_dishes_display)keyword_input_vegan_halal.change(lambda keyword: gr.update(value=display_dishes("VEGAN", keyword) + display_dishes("HALAL", keyword)),inputs=keyword_input_vegan_halal,outputs=vegan_halal_display)demo.launch()1234594 unmodified lines1001011021031041051061 unmodified line10810911011111211311411511611711811912012112212312412512612712812913013113216 unmodified lines1491501511521531541551561571588 unmodified lines167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214You said:import gradio as grmenu_data = [94 unmodified linesfunction 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: 100%; height: 250px; border-radius: 10px; margin-bottom: 10px;"><h3 style="margin-top: 10px;">${name}</h3><p>${description}</p>1 unmodified line<h4 style="margin-top: 20px;">Choose a Spice Level</h4><div style="display: flex; flex-wrap: wrap; gap: 10px;">${["American Mild", "American Medium", "American Spicy", "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"].map(spice =><label style="margin-right: 10px;"><input type="radio" name="spice" value="${spice}"> ${spice}</label>).join("")}</div><h4 style="margin-top: 20px;">Choose Extras</h4><div style="display: flex; flex-wrap: wrap; gap: 10px;">${["Extra Raitha 4oz + $1.00", "Extra Raitha 8oz + $2.00", "Extra Onion + $1.00", "Extra Onion & Lemon + $2.00"].map(extra =><label style="margin-right: 10px;"><input type="checkbox" name="extras" value="${extra}"> ${extra}</label>).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";}16 unmodified lines"""# Generate dish cardsdef display_dishes(category):html_content = "<div style='display: flex; flex-direction: column; gap: 20px; padding-bottom: 20px; box-sizing: border-box;'>"for dish in menu_data:if category == "ALL":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;'>8 unmodified linesAdd</button></div>elif category == dish["category"] == category:html_content += f"""<div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; height:100%; 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; text-align: center;'><img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'><button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"style='margin-top: 10px; 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 (css="#dish-container {min-height: 100vh; overflow-y: auto;}") 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>")category_selector = gr.Radio(["ALL", "VEGAN", "HALAL"],label="Select Category",value="ALL")# Dish displaydish_display = gr.HTML(value=display_dishes("ALL"))# Radio button change eventcategory_selector.change(lambda category: gr.update(value=display_dishes(category)),inputs=category_selector,outputs=dish_display)demo.launch()
app.py+40-39