Spaces:
Build error
Build error
Update app.py
Browse files10 unmodified lines111213141516178 unmodified lines2627282930313212 unmodified lines454647484950516 unmodified lines5859606162636465666728 unmodified lines96979899100101102174 unmodified lines27727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739810 unmodified linesdf = pd.read_excel(USER_FILE)return {row['Username']: row['Password'] for _, row in df.iterrows()}except FileNotFoundError:# Create the file if it doesn't existdf = pd.DataFrame(columns=["Username", "Password"])df.to_excel(USER_FILE, index=False)return {}8 unmodified linesusers = load_users()if username in users:return "Username already exists. Please choose a different username."# Hash the password before savinghashed_password = hashpw(password.encode(), gensalt()).decode()users[username] = hashed_passwordsave_users(users)12 unmodified linesdef login_user(username, password):success, message = validate_login(username, password)if success:active_sessions[username] = True # Add to active sessionsreturn messagereturn message6 unmodified linesreturn f"{username} has been logged out successfully."return "No active session found for this user."# Function to load menu datadef load_menu():menu_file = "menu.xlsx" # Ensure this file existstry:return pd.read_excel(menu_file)except Exception as e:28 unmodified lines"""return html_content# JavaScript for modal and cart behavior (unchanged)modal_and_cart_js = """<style>.cart-container {174 unmodified lines</script>"""# Gradio app definitiondef app():with gr.Blocks() as demo:gr.Markdown("## Secure Food Ordering System with Login")with gr.Tabs():# Login Tabwith gr.Tab("Login"):gr.Markdown("### Login Page")username = gr.Textbox(label="Username")password = gr.Textbox(label="Password", type="password")login_btn = gr.Button("Login")login_message = gr.Label()login_btn.click(login_user,inputs=[username, password],outputs=[login_message],)# Signup Tabwith gr.Tab("Signup"):gr.Markdown("### Signup Page")signup_username = gr.Textbox(label="Username")signup_password = gr.Textbox(label="Password", type="password")signup_btn = gr.Button("Signup")signup_message = gr.Label()signup_btn.click(signup_user,inputs=[signup_username, signup_password],outputs=[signup_message],)# Menu Tabwith gr.Tab("Menu Page"):gr.Markdown("### Menu Page (Only for Logged-In Users)")# Input for username to verify loginmenu_username = gr.Textbox(label="Enter Username to Verify Login", placeholder="Enter your username")menu_check = gr.Button("Check Login Status")login_status = gr.Label()menu_content = gr.HTML(value="")# Function to check login statusdef check_login_status(username):if is_logged_in(username):return "Welcome to the menu page!", filter_menu("All")return "You are not logged in!", ""# Bind login check buttonmenu_check.click(check_login_status,inputs=[menu_username],outputs=[login_status, menu_content],)# Define Radio button for selecting preferenceselected_preference = gr.Radio(choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],value="All",label="Choose a Preference",)# Output area for menu itemsmenu_output = gr.HTML(value=filter_menu("All"))# Dynamically update the menu based on preferenceselected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])# Floating cart displaycart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")# Final order displayfinal_order_output = gr.HTML(value="", elem_id="final-order")# Modal windowmodal_window = gr.HTML("""<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;"><div style="text-align: right;"><button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button></div><img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" /><h2 id="modal-name"></h2><p id="modal-description"></p><p id="modal-price"></p><label for="biryani-extras">Biryani Extras:</label><div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;"><label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label><label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label><label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label><label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label><label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label><label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label><label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label></div><label for="quantity">Quantity:</label><input type="number" id="quantity" value="1" min="1" style="width: 50px;" /><br><br><textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea><br><br><button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button></div>""")# Layout for the menu pagegr.Row([selected_preference])gr.Row(menu_output)gr.Row(cart_output)gr.Row(modal_window)gr.Row(final_order_output)gr.HTML(modal_and_cart_js)return demoif __name__ == "__main__":demo = app()demo.launch()10 unmodified lines1112131415168 unmodified lines25262728293012 unmodified lines434445464748496 unmodified lines565758596061626364656628 unmodified lines9596979899100101174 unmodified lines27627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836910 unmodified linesdf = pd.read_excel(USER_FILE)return {row['Username']: row['Password'] for _, row in df.iterrows()}except FileNotFoundError:df = pd.DataFrame(columns=["Username", "Password"])df.to_excel(USER_FILE, index=False)return {}8 unmodified linesusers = load_users()if username in users:return "Username already exists. Please choose a different username."hashed_password = hashpw(password.encode(), gensalt()).decode()users[username] = hashed_passwordsave_users(users)12 unmodified linesdef login_user(username, password):success, message = validate_login(username, password)if success:active_sessions[username] = Truereturn messagereturn message6 unmodified linesreturn f"{username} has been logged out successfully."return "No active session found for this user."# Menu functionality: Your original code will remain here as-is# Keeping all your existing menu, cart, modal logic intact# Function to load the menu datadef load_menu():menu_file = "menu.xlsx" # Ensure this file exists in the same directorytry:return pd.read_excel(menu_file)except Exception as e:28 unmodified lines"""return html_content# JavaScript for modal and cart behaviormodal_and_cart_js = """<style>.cart-container {174 unmodified lines</script>"""# Gradio appdef app():with gr.Blocks() as demo:gr.Markdown("## Secure Food Ordering System")# Login and Signup Tabswith gr.Tabs():with gr.Tab("Login"):username = gr.Textbox(label="Username")password = gr.Textbox(label="Password", type="password")login_btn = gr.Button("Login")login_message = gr.Label()login_btn.click(login_user, [username, password], [login_message])with gr.Tab("Signup"):signup_username = gr.Textbox(label="Username")signup_password = gr.Textbox(label="Password", type="password")signup_btn = gr.Button("Signup")signup_message = gr.Label()signup_btn.click(signup_user, [signup_username, signup_password], [signup_message])# Menu Page Tabwith gr.Tab("Menu Page"):gr.Markdown("### Menu Page")# Preserve your menu-related code exactly as it was# Add your exact original menu, cart, and modal code hereselected_preference = gr.Radio(choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],value="All",label="Choose a Preference",)# Output area for menu itemsmenu_output = gr.HTML(value=filter_menu("All"))# Floating cart displaycart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")# Final order displayfinal_order_output = gr.HTML(value="", elem_id="final-order")# Modal windowmodal_window = gr.HTML("""<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;"><div style="text-align: right;"><button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button></div><img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" /><h2 id="modal-name"></h2><p id="modal-description"></p><p id="modal-price"></p><!-- Biryani Extras --><label for="biryani-extras">Biryani Extras :</label><div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;"><label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label><label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label><label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label><label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label><label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label><label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label><label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label></div><!-- Quantity and Special Instructions --><label for="quantity">Quantity:</label><input type="number" id="quantity" value="1" min="1" style="width: 50px;" /><br><br><textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea><br><br><!-- Add to Cart Button --><button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button></div>""")# Update menu dynamically based on preferenceselected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])# Layoutgr.Row([selected_preference])gr.Row(menu_output)gr.Row(cart_output)gr.Row(modal_window)gr.Row(final_order_output)gr.HTML(modal_and_cart_js)return demoif __name__ == "__main__":app().launch()
app.py+76-105