Spaces:
Runtime error
Runtime error
File size: 2,369 Bytes
6df278b ebe0573 8824d70 ebe0573 3ebf37d 6df278b 3ebf37d 6df278b |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 = """
<style>
[data-testid='stAppViewContainer'] {
background: rgba(0, 0, 0, 0.5);
background-image: url("https://wallpapertag.com/wallpaper/full/8/4/9/608783-cool-gothic-wallpapers-1920x1200-picture.jpg");
background-blend-mode: overlay;
background-position: center;
background-size: cover;
}
</style>
"""
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()
|