import pandas as pd import gradio as gr # Load menu data from the Excel file def load_menu(file_path="menu.xlsx"): menu_data = pd.read_excel(file_path) grouped_menu = menu_data.groupby("Category") menu = {category: items.to_dict(orient="records") for category, items in grouped_menu} return menu # Generate HTML content for the menu def generate_menu_html(menu): html_content = "" for category, items in menu.items(): html_content += f"

{category}

" for item in items: html_content += f"""
{item['Dish Name']}

{item['Dish Name']}

Price: ${item['Price']}

""" html_content += "
" return html_content # Fetch dish details for the pop-up card def fetch_dish_details(dish_name, menu_data_path="menu.xlsx"): menu_data = pd.read_excel(menu_data_path) item = menu_data[menu_data["Dish Name"] == dish_name].to_dict(orient="records") if item: details = item[0] html = f"""

{details['Dish Name']}

{details['Dish Name']}

Description: {details['Description']}

Ingredients: {details['Ingredients']}

Allergen Info: {details['Allergen Info']}

Recommended Items: {details['Recommended Items']}

Spice Levels: {details['Spice Levels']}

""" return html else: return "

Dish not found.

" # Gradio interface for the main menu and dish details def main_interface(): menu = load_menu() menu_html = generate_menu_html(menu) return menu_html def detail_interface(dish_name): details_html = fetch_dish_details(dish_name) return details_html # Gradio App with gr.Blocks() as app: with gr.Row(): gr.Markdown("# Dynamic Menu Display") with gr.Row(): menu_output = gr.HTML() detail_output = gr.HTML() with gr.Row(): dish_name_input = gr.Textbox(label="Dish Name", placeholder="Enter dish name to view details.") fetch_button = gr.Button("Fetch Details") fetch_button.click(fn=detail_interface, inputs=[dish_name_input], outputs=[detail_output]) menu_output.value = main_interface() # Launch the app if __name__ == "__main__": app.launch()