Spaces:
Sleeping
Sleeping
Update app.py
Browse files13 unmodified lines141516171819202122232 unmodified lines2627282930313233343528 unmodified lines646566676869707172737475767778798081826 unmodified lines8990919293949596974 unmodified lines1021031041051061071081091102 unmodified lines1131141151161171181195 unmodified lines1251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781799 unmodified lines18919019119213 unmodified lines"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg","description": "Paneer cooked in a rich and creamy tomato-based gravy.","price": "$10.99"},{"name": "Mushroom Soup", "category": "VEGAN","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mushroom_soup.jpg","description": "Creamy mushroom soup with fresh herbs.","price": "$7.99"},{"name": "Butter Naan", "category": "VEGAN","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/butter_naan.jpg","description": "Soft and buttery flatbread, perfect to pair with any curry.",2 unmodified lines"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/fish_curry.jpg","description": "Fresh fish cooked in a spicy and tangy curry.","price": "$13.99"},{"name": "Grilled Veggies", "category": "VEGAN","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/grilled_veggies.jpg","description": "A healthy mix of grilled seasonal vegetables with olive oil.","price": "$9.99"},{"name": "Chicken Kebab", "category": "HALAL","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_kebab.jpg","description": "Juicy chicken kebabs grilled to perfection with a mix of spices.",28 unmodified lines"price": "$7.99"}]# 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 Onion", "price": "$1.00"},{"name": "Extra Fried Onion 4oz", "price": "$2.00"},{"name": "Coke", "price": "$1.50"},{"name": "Pepsi", "price": "$1.50"},{"name": "Lemonade", "price": "$2.00"},{"name": "Spring Rolls", "price": "$4.99"},{"name": "Veg Samosa", "price": "$3.99"},{"name": "Masala Papad", "price": "$2.99"}]# Filter dishes by category6 unmodified linesdef display_dishes(category):filtered_dishes = filter_dishes(category)html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"for idx, dish in enumerate(filtered_dishes):html_content += f"""<div id='dish-{idx}' style='margin: 10px; display: flex; align-items: center; justify-content: space-between;width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;background-color: #f9f9f9;'><div style='flex: 1; margin-right: 20px; text-align: left;'>4 unmodified lines<div style='text-align: center;'><img src='{dish['image']}' alt='{dish['name']}'style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'><button onclick=\"showPopup('{idx}', '{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')\"style=\"margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;border-radius: 5px; cursor: pointer;\">Add</button></div></div>"""2 unmodified lines# Main Gradio Appwith gr.Blocks() as demo:gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Dynamic Menu with Pop-up 🍛</h1>")# Buttons for category selectionwith gr.Row():5 unmodified linesdish_display = gr.HTML(value=display_dishes("ALL"))# JavaScript for managing the pop-upgr.HTML("""<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 a spice level</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="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>'for spice in spice_levels]) + """</div><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(9 unmodified linesoutputs=dish_display)demo.launch()13 unmodified lines141516171819202122232425262728293031323334352 unmodified lines383940414243444546474849505128 unmodified lines8081828384858687888990919293949596976 unmodified lines1041051061071081091101111124 unmodified lines1171181191201211221231241252 unmodified lines1281291301311321331345 unmodified lines1401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881899 unmodified lines19920020120213 unmodified lines"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg","description": "Paneer cooked in a rich and creamy tomato-based gravy.","price": "$10.99"},{"name": "Beef Steak", "category": "HALAL","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/beef_steak.jpg","description": "Juicy beef steak served with mashed potatoes and grilled vegetables.","price": "$15.99"},{"name": "Mushroom Soup", "category": "VEGAN","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mushroom_soup.jpg","description": "Creamy mushroom soup with fresh herbs.","price": "$7.99"},{"name": "Tandoori Chicken", "category": "HALAL","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/tandoori_chicken.jpg","description": "Grilled chicken marinated in yogurt and spices, cooked in a tandoor.","price": "$11.99"},{"name": "Grilled Veggies", "category": "VEGAN","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/grilled_veggies.jpg","description": "A healthy mix of grilled seasonal vegetables with olive oil.","price": "$9.99"},{"name": "Butter Naan", "category": "VEGAN","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/butter_naan.jpg","description": "Soft and buttery flatbread, perfect to pair with any curry.",2 unmodified lines"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/fish_curry.jpg","description": "Fresh fish cooked in a spicy and tangy curry.","price": "$13.99"},{"name": "Vegetable Salad", "category": "VEGAN","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/vegetable_salad.jpg","description": "A mix of fresh greens, tomatoes, cucumbers, and a light dressing.","price": "$6.99"},{"name": "Veg Spring Rolls", "category": "VEGAN","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_spring_rolls.jpg","description": "Crispy spring rolls filled with fresh vegetables.","price": "$5.99"},{"name": "Chicken Kebab", "category": "HALAL","image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_kebab.jpg","description": "Juicy chicken kebabs grilled to perfection with a mix of spices.",28 unmodified lines"price": "$7.99"}]# 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"},{"name": "Extra Salan 4oz", "price": "$1.00"},{"name": "Extra Salan 8oz", "price": "$2.00"},{"name": "Extra Onion", "price": "$1.00"},{"name": "Extra Onion & Lemon", "price": "$2.00"},{"name": "Extra Fried Onion 4oz", "price": "$2.00"},]# Filter dishes by category6 unmodified linesdef display_dishes(category):filtered_dishes = filter_dishes(category)html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"for dish in filtered_dishes:html_content += f"""<div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;background-color: #f9f9f9;'><div style='flex: 1; margin-right: 20px; text-align: left;'>4 unmodified lines<div style='text-align: center;'><img src='{dish['image']}' alt='{dish['name']}'style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'><button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')"style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;border-radius: 5px; cursor: pointer;">Add</button></div></div>"""2 unmodified lines# 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():5 unmodified linesdish_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 a spice level</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="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>' for spice in spice_levels]) + """</div><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(9 unmodified linesoutputs=dish_display)demo.launch()
app.py+73-63