DynamicMenuApp / app.py
DSatishchandra's picture
Update app.py
920d44a verified
raw
history blame
1.9 kB
import pandas as pd
import gradio as gr
# Load the menu data from the Excel file
def load_menu(file_path="menu.xlsx"):
menu_data = pd.read_excel(file_path)
return menu_data
# Filter the menu based on user preference
def filter_menu(preference):
menu_data = load_menu()
if preference != "All":
filtered_data = menu_data[menu_data["Category"] == preference]
else:
filtered_data = menu_data
# Generate HTML for filtered menu
html_content = ""
for _, item in filtered_data.iterrows():
html_content += f"""
<div style="border: 1px solid #ddd; margin: 10px; padding: 10px; border-radius: 8px; display: flex; align-items: center;">
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; object-fit: cover; margin-right: 10px;">
<div>
<h4>{item['Dish Name']}</h4>
<p>{item['Description']}</p>
<p><strong>Price:</strong> ${item['Price']}</p>
<button style="background-color: #28a745; color: white; border: none; padding: 5px 10px; border-radius: 5px; cursor: pointer;">Add</button>
</div>
</div>
"""
return html_content
# Gradio app definition
def app():
preferences = ["All", "Vegan", "Halal", "Guilt-Free"]
with gr.Blocks() as demo:
gr.Markdown("# Dynamic Menu with Preferences")
# Radio buttons for preferences
selected_preference = gr.Radio(preferences, label="Choose a Preference")
# Display the filtered menu
menu_output = gr.HTML()
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
# Initial menu load (all items)
menu_output.value = filter_menu("All")
return demo
# Run the app
if __name__ == "__main__":
demo = app()
demo.launch()