sbsmapper / app.py
georad's picture
Update app.py
5c61a4a verified
raw
history blame
2.82 kB
import streamlit as st
# Custom CSS to ensure sticky header in both Streamlit and Hugging Face environments
st.markdown("""
<style>
/* Target both Streamlit native and Hugging Face iframe embedding */
/* Make the header sticky */
header[data-testid="stHeader"] {
position: fixed;
top: 0;
left: 0;
right: 0;
height: auto;
z-index: 999990;
background-color: white;
box-shadow: 0 1px 5px rgba(0,0,0,0.1);
}
/* For Hugging Face specific iframe handling */
section.main {
padding-top: 70px;
}
/* Ensure content doesn't get hidden under the header */
.block-container {
padding-top: 1rem;
}
/* Fix for Hugging Face iframe specific issues */
iframe body .stApp {
padding-top: 3rem;
}
/* Alternative approach: Create your own sticky header container */
div.sticky-header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 999999;
background-color: white;
padding: 1rem;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
/* Ensures content below isn't hidden */
margin-bottom: 3rem;
}
/* Create space below custom sticky header */
div.sticky-header-spacer {
height: 6rem;
}
</style>
""", unsafe_allow_html=True)
# Option 1: Using Streamlit's native header (modified with CSS above)
st.title("My App with Sticky Header")
# Option 2: Custom sticky header implementation
# Uncomment and use this approach if the CSS-only solution doesn't work
# Custom sticky header container
st.markdown('<div class="sticky-header">', unsafe_allow_html=True)
st.title("My App with Custom Sticky Header")
# Add any other header elements here
st.markdown('</div>', unsafe_allow_html=True)
# Add spacer to ensure content isn't hidden under the header
st.markdown('<div class="sticky-header-spacer"></div>', unsafe_allow_html=True)
# Rest of your app
st.write("Scroll down to test the sticky header")
# Add dummy content to enable scrolling
for i in range(30):
st.write(f"Content block {i}")
st.write("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
# --- Your Streamlit App ---
#st.logo(image="images/menu_book_60dp_75FBFD.png")
st.title("Map descriptions to SBS codes with Sentence Transformer + Reasoning")
st.subheader("Select specific Chapter for quicker results")
st.logo(image="images/menu_book_60dp_75FBFD.png")
st.sidebar.header("SBS V2.0 mapper")
st.sidebar.write("(work in progress)")
st.sidebar.text("Demo by JA-RAD")
# --- NAVIGATION SETUP ---
pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
##pg = st.navigation({"Chapter_Index": [start_page], "Demo": [type_text_page, upload_file_page], "About": [about_page]}) # WITH SECTIONS
pg.run()