import gradio as gr from utils.database_handler import check_credentials, save_user import pandas as pd # Function to load the menu data def load_menu(): menu_file = "menu.xlsx" # Ensure this file exists in the same directory try: return pd.read_excel(menu_file) except Exception as e: raise ValueError(f"Error loading menu file: {e}") # Function to filter menu items based on preference def filter_menu(preference): menu_data = load_menu() if preference == "Halal/Non-Veg": filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)] elif preference == "Vegetarian": filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)] elif preference == "Guilt-Free": filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)] else: filtered_data = menu_data html_content = "" for _, item in filtered_data.iterrows(): html_content += f"""

{item['Dish Name']}

${item['Price ($)']}

{item['Description']}

\"{item['Dish
""" return html_content # JavaScript for modal and cart behavior modal_and_cart_js = """ """ def app_interface(): # Login Button Actions def authenticate_user(email, password): if check_credentials(email, password): return ( gr.update(visible=False), # Hide login page gr.update(visible=True), # Show preferences page gr.update(visible=True), # Show menu page "", # Clear any error message ) else: return ( gr.update(visible=True), # Show error box gr.update(visible=False), # Keep preferences page hidden gr.update(visible=False), # Keep menu page hidden "Invalid email or password. Try again.", # Error message ) def navigate_to_signup(): return gr.update(visible=False), gr.update(visible=True) def create_account(name, phone, email, password): if save_user(name, phone, email, password): return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False) else: return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True) def navigate_to_login(): return gr.update(visible=True), gr.update(visible=False) with gr.Blocks() as app: # Login Page with gr.Column(visible=True) as login_section: gr.Markdown("# Login Page") email = gr.Textbox(label="Email", placeholder="Enter your email") password = gr.Textbox(label="Password", placeholder="Enter your password", type="password") error_box = gr.Markdown("", visible=False) login_btn = gr.Button("Login") create_account_btn = gr.Button("Create an Account") # Sign-Up Page with gr.Column(visible=False) as signup_section: gr.Markdown("# Sign Up Page") name = gr.Textbox(label="Name", placeholder="Enter your full name") phone = gr.Textbox(label="Phone", placeholder="Enter your phone number") signup_email = gr.Textbox(label="Email", placeholder="Enter your email") signup_password = gr.Textbox(label="Password", placeholder="Enter a password", type="password") success_message = gr.Markdown("", visible=False) error_message = gr.Markdown("", visible=False) submit_btn = gr.Button("Sign Up") back_to_login_btn = gr.Button("Back to Login") # Preferences Page with gr.Column(visible=False) as preference_section: gr.Markdown("# Preferences Page") # Menu Page with gr.Column(visible=False) as menu_section: gr.Markdown("## Dynamic Menu with Preferences") selected_preference = gr.Radio( choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"], value="All", label="Choose a Preference", ) menu_output = gr.HTML(value=filter_menu("All")) cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart") selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output]) # Button Actions for Login login_btn.click( authenticate_user, inputs=[email, password], outputs=[login_section, preference_section, menu_section, error_box], ) create_account_btn.click( navigate_to_signup, inputs=[], outputs=[login_section, signup_section], ) # Button Actions for Sign-Up submit_btn.click( create_account, inputs=[name, phone, signup_email, signup_password], outputs=[success_message, signup_section, login_section], ) back_to_login_btn.click( navigate_to_login, inputs=[], outputs=[login_section, signup_section], ) return app if __name__ == "__main__": app = app_interface() app.launch()