Spaces:
Sleeping
Sleeping
# From https://docs.streamlit.io/develop/tutorials/multipage/st.page_link-nav | |
import streamlit as st | |
import os | |
import project_config | |
def authenticated_menu(): | |
# Insert profile picture | |
pfp_path = str(project_config.MEDIA_DIR / 'pfp' / f"{st.session_state.profile_pic}.png") | |
if not os.path.exists(pfp_path): | |
pfp_path = str(project_config.MEDIA_DIR / 'pfp' / "gravity.png") | |
st.sidebar.image(pfp_path, use_column_width=True) | |
st.sidebar.markdown("---") | |
# Show a navigation menu for authenticated users | |
# st.sidebar.page_link("app.py", label="Switch Accounts", icon="π") | |
st.sidebar.page_link("pages/about.py", label="About", icon="π") | |
st.sidebar.page_link("pages/input.py", label="Input", icon="π‘") | |
st.sidebar.page_link("pages/predict.py", label="Predict", icon="π", | |
disabled=("query" not in st.session_state)) | |
st.sidebar.page_link("pages/validate.py", label="Validate", icon="β ", | |
disabled=("query" not in st.session_state)) | |
# st.sidebar.page_link("pages/explore.py", label="Explore", icon="π") | |
if st.session_state.role in ["admin"]: | |
st.sidebar.page_link("pages/admin.py", label="Manage Users", icon="π§") | |
# Show the logout button | |
st.sidebar.markdown("---") | |
st.sidebar.button("Log Out", on_click=lambda: st.session_state.clear()) | |
def unauthenticated_menu(): | |
# Show a navigation menu for unauthenticated users | |
st.sidebar.page_link("app.py", label="Log In", icon="π") | |
def menu(): | |
# Determine if a user is logged in or not, then show the correct navigation menu | |
if "role" not in st.session_state or st.session_state.role is None: | |
unauthenticated_menu() | |
return | |
authenticated_menu() | |
def menu_with_redirect(): | |
# Redirect users to the main page if not logged in, otherwise continue to | |
# render the navigation menu | |
if "role" not in st.session_state or st.session_state.role is None: | |
st.switch_page("app.py") | |
menu() |