Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,103 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
#
|
| 5 |
|
| 6 |
-
# Custom CSS
|
| 7 |
st.markdown("""
|
| 8 |
<style>
|
| 9 |
-
/*
|
| 10 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
background-color: #90EE90;
|
| 12 |
-
padding:
|
| 13 |
-
border-bottom: 1px solid #
|
| 14 |
-
|
| 15 |
}
|
| 16 |
|
| 17 |
-
/* Hide
|
| 18 |
-
[data-testid="stHeader"] {
|
| 19 |
-
|
| 20 |
-
height: 0;
|
| 21 |
}
|
| 22 |
|
| 23 |
-
/*
|
| 24 |
-
[data-testid="
|
| 25 |
-
|
| 26 |
-
top: 0 !important;
|
| 27 |
-
background-color: white !important;
|
| 28 |
-
z-index: 999 !important;
|
| 29 |
}
|
| 30 |
</style>
|
| 31 |
""", unsafe_allow_html=True)
|
| 32 |
|
| 33 |
-
# Create a
|
| 34 |
-
# This
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
with header_container:
|
| 39 |
-
st.markdown("""
|
| 40 |
-
<div class="custom-sticky-header">
|
| 41 |
-
<h1>Map descriptions to SBS codes with Sentence Transformer + Reasoning</h1>
|
| 42 |
-
<h3>Select specific Chapter for quicker results</h3>
|
| 43 |
-
</div>
|
| 44 |
-
""", unsafe_allow_html=True)
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
# Add a
|
| 54 |
st.write("")
|
| 55 |
|
| 56 |
-
#
|
| 57 |
st.sidebar.header("SBS V2.0 mapper")
|
| 58 |
st.sidebar.write("(work in progress)")
|
| 59 |
st.sidebar.text("Demo by JA-RAD")
|
| 60 |
|
| 61 |
-
#
|
| 62 |
type_text_page = st.Page(
|
| 63 |
page="pages/type_text.py",
|
| 64 |
title="DEMO (work in progress)",
|
| 65 |
icon=":material/keyboard:",
|
| 66 |
default=True,)
|
| 67 |
|
|
|
|
| 68 |
pg = st.navigation(pages=[type_text_page])
|
| 69 |
-
pg.run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# Looking at the UCSF example, they use a custom component approach with specific CSS
|
| 4 |
+
# Let's implement a similar solution
|
| 5 |
|
| 6 |
+
# Custom CSS based on the UCSF implementation
|
| 7 |
st.markdown("""
|
| 8 |
<style>
|
| 9 |
+
/* CSS similar to UCSF implementation */
|
| 10 |
+
div.block-container {
|
| 11 |
+
padding-top: 1rem;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
div[data-testid="stDecoratedAppViewContainer"] > div:first-child {
|
| 15 |
+
position: sticky !important;
|
| 16 |
+
top: 0 !important;
|
| 17 |
+
background-color: white;
|
| 18 |
+
z-index: 999;
|
| 19 |
+
padding: 0px !important;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/* Custom header styling */
|
| 23 |
+
.custom-header {
|
| 24 |
background-color: #90EE90;
|
| 25 |
+
padding: 1rem;
|
| 26 |
+
border-bottom: 1px solid #ddd;
|
| 27 |
+
width: 100%;
|
| 28 |
}
|
| 29 |
|
| 30 |
+
/* Hide default Streamlit header */
|
| 31 |
+
header[data-testid="stHeader"] {
|
| 32 |
+
display: none;
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
+
/* Additional fixes specific to Hugging Face embedding */
|
| 36 |
+
section[data-testid="stSidebar"] {
|
| 37 |
+
z-index: 0;
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
</style>
|
| 40 |
""", unsafe_allow_html=True)
|
| 41 |
|
| 42 |
+
# Create a custom header at the very top (this is key)
|
| 43 |
+
# This must be the very first Streamlit element
|
| 44 |
+
with st.container():
|
| 45 |
+
st.markdown('<div class="custom-header">', unsafe_allow_html=True)
|
| 46 |
+
col1, col2 = st.columns([1, 9])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
with col1:
|
| 49 |
+
# Add logo
|
| 50 |
+
try:
|
| 51 |
+
st.image("images/menu_book_60dp_75FBFD.png", width=60)
|
| 52 |
+
except:
|
| 53 |
+
st.write("📚") # Fallback emoji if image doesn't load
|
| 54 |
+
|
| 55 |
+
with col2:
|
| 56 |
+
st.markdown("""
|
| 57 |
+
<h2 style="margin: 0; padding: 0;">Map descriptions to SBS codes with Sentence Transformer + Reasoning</h2>
|
| 58 |
+
<p style="margin: 0; padding: 0;">Select specific Chapter for quicker results</p>
|
| 59 |
+
""", unsafe_allow_html=True)
|
| 60 |
+
|
| 61 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 62 |
|
| 63 |
+
# Add a bit of spacing
|
| 64 |
st.write("")
|
| 65 |
|
| 66 |
+
# Sidebar content (similar to your original code)
|
| 67 |
st.sidebar.header("SBS V2.0 mapper")
|
| 68 |
st.sidebar.write("(work in progress)")
|
| 69 |
st.sidebar.text("Demo by JA-RAD")
|
| 70 |
|
| 71 |
+
# Page setup
|
| 72 |
type_text_page = st.Page(
|
| 73 |
page="pages/type_text.py",
|
| 74 |
title="DEMO (work in progress)",
|
| 75 |
icon=":material/keyboard:",
|
| 76 |
default=True,)
|
| 77 |
|
| 78 |
+
# Navigation
|
| 79 |
pg = st.navigation(pages=[type_text_page])
|
| 80 |
+
pg.run()
|
| 81 |
+
|
| 82 |
+
# Inject CSS and JS as early as possible in your app
|
| 83 |
+
st.markdown(custom_css, unsafe_allow_html=True)
|
| 84 |
+
st.markdown(js_fix, unsafe_allow_html=True)
|
| 85 |
+
|
| 86 |
+
# --- PAGE SETUP ---
|
| 87 |
+
type_text_page = st.Page(
|
| 88 |
+
page="pages/type_text.py",
|
| 89 |
+
title="DEMO (work in progress)",
|
| 90 |
+
icon=":material/keyboard:",
|
| 91 |
+
default=True,)
|
| 92 |
+
|
| 93 |
+
# --- Your Streamlit App ---
|
| 94 |
+
st.title("Map descriptions to SBS codes with Sentence Transformer + Reasoning")
|
| 95 |
+
st.subheader("Select specific Chapter for quicker results")
|
| 96 |
+
st.logo(image="images/menu_book_60dp_75FBFD.png")
|
| 97 |
+
st.sidebar.header("SBS V2.0 mapper")
|
| 98 |
+
st.sidebar.write("(work in progress)")
|
| 99 |
+
st.sidebar.text("Demo by JA-RAD")
|
| 100 |
+
|
| 101 |
+
# --- NAVIGATION SETUP ---
|
| 102 |
+
pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
|
| 103 |
+
pg.run()
|