Spaces:
Sleeping
Sleeping
File size: 2,645 Bytes
f128fe5 ba1c7a0 f128fe5 ba1c7a0 01b734e f18a5e1 01b734e f18a5e1 f128fe5 ba1c7a0 f128fe5 |
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# From https://docs.streamlit.io/develop/tutorials/multipage/st.page_link-nav
import streamlit as st
def authenticated_menu():
st.markdown("""
<style>
.circle-image {
width: 100px;
height: 100px;
border-radius: 50%;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
border: 2px solid black;
margin: 0 auto 10px auto;
}
.circle-image img {
width: 100%;
height: 100%;
object-fit: cover;
}
.username {
font-size: 20px;
font-weight: bold;
text-align: center;
margin-top: 0px;
}
</style>
""", unsafe_allow_html=True)
# Show the user's profile picture
st.sidebar.markdown(f'<div class="circle-image"><img src="{st.session_state.profile_pic}" /></div>', unsafe_allow_html=True)
# Show the user's name
# st.sidebar.markdown(f"Logged in as {st.session_state.name}.")
st.sidebar.markdown(f'<div class="username">{st.session_state.name}</div>', unsafe_allow_html=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="π")
st.sidebar.page_link("pages/validate.py", label="Validate", icon="β
")
# 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() |