georad commited on
Commit
f824176
·
verified ·
1 Parent(s): 1cd1a19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -84
app.py CHANGED
@@ -1,99 +1,80 @@
1
- import streamlit as st
2
-
3
- # --- Page Configuration ---
4
- # This configures the topmost header bar (which WILL now be sticky)
5
- st.set_page_config(
6
- page_title="SBS V2.0 mapper", # This title appears in the sticky topmost bar
7
- # Use the logo image here if you want it in the header (optional)
8
- # page_icon="images/menu_book_60dp_75FBFD.png", # Icon for the sticky topmost bar
9
- layout="wide" # Optional: Use wide layout
10
- )
11
-
12
- # --- Custom CSS to Fix Parent Overflow and Make the TOPMOST Header Bar Sticky ---
13
- st.markdown("""
 
 
 
 
 
 
 
14
  <style>
15
- /* Target the main app container and ensure its overflow is visible */
16
- /* This is crucial for sticky positioning relative to the iframe's viewport */
17
- [data-testid="stApp"] {
18
- overflow: visible !important; /* Force overflow to be visible */
19
- }
20
-
21
- /* Target the default Streamlit TOPMOST header bar (the <header> tag) */
22
- header {
23
- position: sticky !important; /* Make this specific bar sticky */
24
- top: 0px !important; /* Stick to the top edge of the iframe's viewport */
25
- z-index: 999 !important; /* Ensure it's always on top */
26
- background-color: rgb(255, 255, 255) !important; /* Background for the sticky bar (white or match default) */
27
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Add shadow */
28
- height: auto !important; /* Force height to adjust based on content */
29
- overflow: visible !important; /* Ensure content inside header is visible */
30
- }
31
-
32
- /* Ensure the container holding the Toolbar (stToolbar) and Status Widget (stStatusWidget) is NOT sticky */
33
- /* This is typically the second direct child div within the stAppViewContainer */
34
- [data-testid="stAppViewContainer"] > div:nth-child(2) {
35
- position: static !important; /* Ensure it's not sticky or fixed */
36
- top: auto !important; /* Reset top positioning */
37
- z-index: auto !important; /* Reset z-index */
38
- /* Remove any background or shadow rules that were applied here if necessary */
39
- }
40
-
41
-
42
- /* Add padding to the main content area to prevent it from starting behind the sticky TOPMOST header bar */
43
- /* Adjust this value to be slightly more than the height of the TOPMOST header bar (the sticky element) */
44
- /* You will likely need to inspect the deployed app to find the exact height of the <header> */
45
- [data-testid="stAppViewContainer"] {
46
- padding-top: 60px; /* Estimate height of the topmost sticky bar (~60px). Adjust after inspection. */
47
- }
48
-
49
- /* Adjust padding for the sidebar content as well */
50
- /* This needs to account only for the height of the sticky topmost bar plus default sidebar padding */
51
- [data-testid="stSidebar"] {
52
- /* Estimate height of topmost bar (~60px) + default sidebar padding (~1rem, which is approx 16px) */
53
- padding-top: calc(60px + 1rem); /* Adjust pixel value after inspection */
54
- }
55
-
56
- /* Ensure the main content block within the container also has correct top padding */
57
- .main .block-container {
58
- padding-top: 1rem; /* Keep or adjust default Streamlit content padding */
59
- }
60
-
61
  </style>
62
- """, unsafe_allow_html=True)
63
 
64
- # --- App Content (will scroll below the sticky TOPMOST bar) ---
 
65
 
66
- # The st.logo call here will place the logo in the sidebar or main body,
67
- # not in either of the top bars. If you want a logo in the sticky header,
68
- # use the page_icon parameter in st.set_page_config above.
69
- st.logo(image="images/menu_book_60dp_75FBFD.png")
 
 
70
 
71
 
 
 
 
 
 
72
  st.sidebar.header("SBS V2.0 mapper")
73
  st.sidebar.write("(work in progress)")
74
  st.sidebar.text("Demo by JA-RAD")
75
 
76
- # Note: st.title and st.subheader here will appear *below* the sticky topmost bar,
77
- # as they are part of the main app content flow. The title in the sticky topmost bar
78
- # comes from st.set_page_config.
79
- st.title("Map descriptions to SBS codes with Sentence Transformer + Reasoning") # This title scrolls
80
- st.subheader("Select specific Chapter for quicker results") # This subheader scrolls
81
 
82
 
83
  # --- NAVIGATION SETUP ---
84
- # Keep your existing navigation setup
85
- type_text_page = st.Page(
86
- page="pages/type_text.py",
87
- title="DEMO (work in progress)",
88
- icon=":material/keyboard:", # This icon can appear in the tab/bookmark
89
- default=True,
90
- )
91
-
92
  pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
93
- pg.run()
94
-
95
- # Add some extra content to make the page scrollable for testing
96
- # Remove this loop in your final application if you have enough content already
97
- for i in range(100):
98
- st.write(f"This is scrollable content line {i}")
99
 
 
1
+ import streamlit as st
2
+
3
+ # Inspect the header element, go to the "Computed" tab in styles, and find its height.
4
+ HEADER_HEIGHT = "60px" # EXAMPLE: Adjust this (e.g., "56px", "4rem")
5
+ HEADER_SELECTOR = 'header[data-testid="stHeader"]'
6
+
7
+ # ---- SELECTOR FOR THE MAIN CONTENT AREA THAT NEEDS PADDING ----
8
+ # Target the first direct div child of the stAppViewContainer which often holds the main scrollable content
9
+ MAIN_CONTENT_SELECTOR = 'section[data-testid="stMain"]'
10
+ #MAIN_CONTENT_SELECTOR = 'section[data-testid="stMain"] > div:nth-child(1)'
11
+ #MAIN_CONTENT_SELECTOR = 'section[data-testid="stMainBlockContainer"]'
12
+ #MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"]'
13
+ #MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"] > div:nth-child(1)'
14
+ # Alternative if the above doesn't work or if your content is further nested:
15
+ #MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"] .main-content-wrapper-class'
16
+ # Or, very commonly, Streamlit wraps main content in a div with class "block-container":
17
+ #MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"] .block-container'
18
+ #MAIN_CONTENT_SELECTOR = '.main .block-container' # A more general selector for block-container
19
+
20
+ custom_css = f"""
21
  <style>
22
+ /* Making the Streamlit header sticky */
23
+ {HEADER_SELECTOR} {{
24
+ position: -webkit-sticky !important; /* For Safari */
25
+ position: sticky !important;
26
+ top: 0 !important;
27
+ z-index: 9999 !important; /* Very high z-index */
28
+ background-color: #90EE90 !important; /* Or your app's header background color */
29
+ /* Add a subtle shadow to make it feel more distinct when content scrolls under */
30
+ /* box-shadow: 0 2px 4px -1px rgba(0,0,0,0.1); */
31
+ /*.reportview-container .main .block-container{{ */
32
+ /* padding-top: 0rem; */
33
+ /* }} */
34
+ }}
35
+
36
+ /* Adding padding to the main content area to prevent overlap with the sticky header */
37
+ {MAIN_CONTENT_SELECTOR} {{
38
+ padding-top: 10px !important; /* {HEADER_HEIGHT} !important; */
39
+ /* background-color: yellow !important; */
40
+ /* border-style: solid !important; */
41
+ /* border-color: red !important; */
42
+ }}
43
+
44
+ /* Optional: If your app is set to wide mode and the header isn't spanning full width */
45
+ /* This might be needed if the sticky positioning affects its width calculation. */
46
+ /*
47
+ #{HEADER_SELECTOR} {{
48
+ # width: 100% !important;
49
+ #}}
50
+ #*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  </style>
52
+ """
53
 
54
+ # Inject CSS as early as possible in your app
55
+ st.markdown(custom_css, unsafe_allow_html=True)
56
 
57
+ # --- PAGE SETUP ---
58
+ type_text_page = st.Page(
59
+ page="pages/type_text.py",
60
+ title="DEMO (work in progress)",
61
+ icon=":material/keyboard:",
62
+ default=True,)
63
 
64
 
65
+ # --- Your Streamlit App ---
66
+ #st.logo(image="images/menu_book_60dp_75FBFD.png")
67
+ st.title("Map descriptions to SBS codes with Sentence Transformer + Reasoning")
68
+ st.subheader("Select specific Chapter for quicker results")
69
+ st.logo(image="images/menu_book_60dp_75FBFD.png")
70
  st.sidebar.header("SBS V2.0 mapper")
71
  st.sidebar.write("(work in progress)")
72
  st.sidebar.text("Demo by JA-RAD")
73
 
 
 
 
 
 
74
 
75
 
76
  # --- NAVIGATION SETUP ---
 
 
 
 
 
 
 
 
77
  pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
78
+ ##pg = st.navigation({"Chapter_Index": [start_page], "Demo": [type_text_page, upload_file_page], "About": [about_page]}) # WITH SECTIONS
79
+ pg.run()
 
 
 
 
80