File size: 1,895 Bytes
66f5c36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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():
    # 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_stream(recommend(query))
        # Example: Provide a logout button
        if st.sidebar.button("Logout"):
            st.session_state.logged_in = False
            st.rerun()

if __name__ == "__main__":
    main()