upload-v1.5.12
Browse files- recommend.py +49 -21
recommend.py
CHANGED
@@ -1,21 +1,49 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Streamlit app script
|
2 |
+
import streamlit as st
|
3 |
+
from recommend import recommend
|
4 |
+
# A simple function to check login credentials (for demonstration purposes)
|
5 |
+
def check_login(username, password):
|
6 |
+
# Hardcoding a simple example username and password
|
7 |
+
user = "admin"
|
8 |
+
pwd = "pass123"
|
9 |
+
return username == user and password == pwd
|
10 |
+
|
11 |
+
# Main application code
|
12 |
+
def main():
|
13 |
+
# Initialize session state for login status
|
14 |
+
if "logged_in" not in st.session_state:
|
15 |
+
st.session_state.logged_in = False
|
16 |
+
|
17 |
+
# If not logged in, display login form
|
18 |
+
if not st.session_state.logged_in:
|
19 |
+
st.title("Login Page")
|
20 |
+
username = st.text_input("Username")
|
21 |
+
password = st.text_input("Password", type="password")
|
22 |
+
if st.button("Login"):
|
23 |
+
if check_login(username, password):
|
24 |
+
# Update session state to indicate user is logged in
|
25 |
+
# st.session_state.username = username
|
26 |
+
st.session_state.logged_in = True
|
27 |
+
st.rerun() # Rerun the script to reflect the new state
|
28 |
+
else:
|
29 |
+
st.error("Invalid credentials. Please try again.")
|
30 |
+
|
31 |
+
# If logged in, redirect to another page or show different content
|
32 |
+
else:
|
33 |
+
# This can be another Streamlit page, or a condition to render a different view
|
34 |
+
st.title(f"Welcome :)!")
|
35 |
+
cols = st.columns([3,1])
|
36 |
+
with cols[0]:
|
37 |
+
query = st.text_input('Search here', placeholder="Describe what you're looking for", label_visibility="collapsed")
|
38 |
+
with cols[1]:
|
39 |
+
btn = st.button('Search')
|
40 |
+
if btn and query:
|
41 |
+
with st.spinner('Searching...'):
|
42 |
+
st.write_stream(recommend(query))
|
43 |
+
# Example: Provide a logout button
|
44 |
+
if st.sidebar.button("Logout"):
|
45 |
+
st.session_state.logged_in = False
|
46 |
+
st.rerun()
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
main()
|