Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # Menu data | |
| menu_data = [ | |
| {"name": "Samosa", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/blob/main/pictures/Potato-Samosa.jpg", "description": "A delicious potato samosa with plant-based potato, lettuce.", "price": 8.99}, | |
| {"name": "Chicken Biryani", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/blob/main/pictures/Chicken-Biryani.jpg", "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.", "price": 12.99}, | |
| {"name": "Paneer Butter Masala", "category": "VEGETARIAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/paneer_butter_masala.jpg", "description": "Soft paneer cubes simmered in a creamy tomato-based gravy, enriched with butter and spices.", "price": 10.99}, | |
| {"name": "Chilli Chicken", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/chilli_chicken.jpg", "description": "A spicy Indo-Chinese dish featuring fried chicken pieces tossed with peppers and chilies.", "price": 13.99}, | |
| {"name": "Veg Manchurian", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/veg_manchurian.jpg", "description": "Deep-fried vegetable balls tossed in a tangy and spicy Indo-Chinese sauce.", "price": 9.99}, | |
| {"name": "Fish Curry", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/fish_curry.jpg", "description": "A flavorful curry made with tender fish pieces simmered in a spiced coconut gravy.", "price": 14.99}, | |
| {"name": "Mutton Biryani", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/mutton_biryani.jpg", "description": "Fragrant rice layered with tender mutton and aromatic spices, cooked to perfection.", "price": 15.99}, | |
| {"name": "Paneer Biryani", "category": "VEGETARIAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/paneer_biryani.jpg", "description": "A delightful biryani made with marinated paneer cubes and basmati rice, infused with spices.", "price": 11.99}, | |
| {"name": "Onion Pakoda", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/onion_pakoda.jpg", "description": "Crispy deep-fried onion fritters, seasoned with spices, a popular tea-time snack.", "price": 5.99}, | |
| {"name": "Chilli Gobi", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/chilli_gobi.jpg", "description": "Crispy cauliflower florets tossed in a spicy and tangy sauce, an Indo-Chinese favorite.", "price": 9.99}, | |
| {"name": "Potato Samosa", "category": "VEGETARIAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/potato_samosa.jpg", "description": "Crispy pastry filled with a spiced potato mixture, deep-fried to golden perfection.", "price": 4.99}, | |
| {"name": "Prawn Fry", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/prawn_fry.jpg", "description": "Spicy and crispy fried prawns, marinated with a blend of spices and herbs.", "price": 14.99}, | |
| {"name": "Sukka Gosht (Goat)", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/sukka_gosht.jpg", "description": "Dry goat meat preparation cooked with a medley of spices, offering a rich and hearty flavor.", "price": 16.99}, | |
| {"name": "Channa Masala", "category": "VEGETARIAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/channa_masala.jpg", "description": "A hearty curry made with chickpeas simmered in a spiced tomato gravy.", "price": 8.99}, | |
| {"name": "Vegetable Biryani", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/veg_biryani.jpg", "description": "A medley of vegetables and basmati rice cooked with aromatic spices, a vegetarian delight.", "price": 10.99}, | |
| {"name": "Chicken Manchurian", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/chicken_manchurian.jpg", "description": "A popular Indo-Chinese dish featuring fried chicken pieces tossed in a tangy and spicy sauce.", "price": 13.99}, | |
| ] | |
| cart = [] | |
| 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 category | |
| def filter_dishes(category): | |
| if category == "ALL": | |
| return menu_data | |
| return [dish for dish in menu_data if dish["category"] == category] | |
| # Generate dish cards with "Add" button | |
| def 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;'> | |
| <h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4> | |
| <p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p> | |
| <p style='font-size: 16px; color: #444; margin: 0;'>Price: {dish['price']}</p> | |
| </div> | |
| <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> | |
| """ | |
| html_content += "</div>" | |
| return html_content | |
| # Add to cart | |
| def add_to_cart(item_name, quantity, custom_preference): | |
| cart.append({"name": item_name, "quantity": quantity, "custom_preference": custom_preference}) | |
| return display_cart() | |
| # Display cart items | |
| def display_cart(): | |
| if not cart: | |
| return "<p>Your cart is empty.</p>" | |
| html_content = "<div style='text-align: left;'>" | |
| for item in cart: | |
| html_content += f"<p>- {item['name']} (x{item['quantity']}) - Custom: {item['custom_preference']}</p>" | |
| html_content += "</div>" | |
| return html_content | |
| # Main Gradio App | |
| with gr.Blocks() as demo: | |
| gr.HTML("<h1 style='text-align: center; color: #333;'>๐ Biryani Hub Menu ๐</h1>") | |
| with gr.Row(): | |
| gr.HTML("<span style='font-size: 24px; cursor: pointer;'>๐</span>") | |
| btn_cart = gr.Button("View Cart") | |
| cart_display = gr.HTML(value=display_cart()) | |
| with gr.Row(): | |
| btn_all = gr.Button("ALL") | |
| btn_vegan = gr.Button("VEGAN") | |
| btn_halal = gr.Button("HALAL") | |
| dish_display = gr.HTML(value=display_dishes("ALL")) | |
| gr.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: 400px;"> | |
| <span onclick="closePopup()" style="position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 18px;">×</span> | |
| <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> | |
| <p id="popup-image-url" style="margin-top: 10px; font-size: 14px; color: #666;"></p> | |
| <label for="popup-quantity" style="margin-top: 20px; display: block; text-align: left;">Quantity:</label> | |
| <input id="popup-quantity" type="number" min="1" value="1" style="width: 100%; margin-top: 10px; padding: 5px; border: 1px solid #ddd; border-radius: 5px;"> | |
| <label for="popup-custom" style="margin-top: 20px; display: block; text-align: left;">Custom Preferences:</label> | |
| <textarea id="popup-custom" placeholder="Add your custom preferences here..." style="width: 100%; margin-top: 10px; padding: 5px; border: 1px solid #ddd; border-radius: 5px;"></textarea> | |
| <button onclick="submitPopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button> | |
| </div> | |
| <script> | |
| function showPopup(name, description, price, imageUrl) { | |
| document.getElementById('popup-title').textContent = name; | |
| document.getElementById('popup-description').textContent = description; | |
| document.getElementById('popup-price').textContent = price; | |
| document.getElementById('popup-image-url').textContent = imageUrl; | |
| document.getElementById('popup').style.display = 'block'; | |
| } | |
| function closePopup() { | |
| document.getElementById('popup').style.display = 'none'; | |
| } | |
| function submitPopup() { | |
| const name = document.getElementById('popup-title').textContent; | |
| const quantity = document.getElementById('popup-quantity').value; | |
| const customPreference = document.getElementById('popup-custom').value; | |
| gr.Interface.postMessage('add_to_cart', [name, quantity, customPreference]); | |
| closePopup(); | |
| } | |
| </script> | |
| """) | |
| # Button click events | |
| btn_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) | |
| btn_cart.click(lambda: gr.update(value=display_cart()), outputs=cart_display) | |
| demo.launch() | |