# Streamlit app script import streamlit as st from recommend import recommend # A simple function to check login credentials (for demonstration purposes) def check_login(username, password): # Hardcoding a simple example username and password user = "admin" pwd = "pass123" return username == user and password == pwd # Main application code def main(): styles = """ """ st.set_page_config(page_title='Articles Recommender') # st.markdown(styles, unsafe_allow_html=True) # Initialize session state for login status if "logged_in" not in st.session_state: st.session_state.logged_in = False # If not logged in, display login form if not st.session_state.logged_in: st.title("Login Page") username = st.text_input("Username") password = st.text_input("Password", type="password") if st.button("Login"): if check_login(username, password): # Update session state to indicate user is logged in # st.session_state.username = username st.session_state.logged_in = True st.rerun() # Rerun the script to reflect the new state else: st.error("Invalid credentials. Please try again.") # If logged in, redirect to another page or show different content else: # This can be another Streamlit page, or a condition to render a different view st.title(f"Welcome :)!") cols = st.columns([3,1]) with cols[0]: query = st.text_input('Search here', placeholder="Describe what you're looking for", label_visibility="collapsed") with cols[1]: btn = st.button('Search') if btn and query: with st.spinner('Searching...'): st.write(recommend(query)) # Example: Provide a logout button if st.sidebar.button("Logout"): st.session_state.logged_in = False st.rerun() if __name__ == "__main__": main()