georad commited on
Commit
25eb2b4
·
verified ·
1 Parent(s): 5c61a4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -75
app.py CHANGED
@@ -1,85 +1,84 @@
1
- import streamlit as st
2
 
3
- # Custom CSS to ensure sticky header in both Streamlit and Hugging Face environments
4
- st.markdown("""
 
5
  <style>
6
- /* Target both Streamlit native and Hugging Face iframe embedding */
7
- /* Make the header sticky */
8
- header[data-testid="stHeader"] {
9
- position: fixed;
10
- top: 0;
11
- left: 0;
12
- right: 0;
13
- height: auto;
14
- z-index: 999990;
15
- background-color: white;
16
- box-shadow: 0 1px 5px rgba(0,0,0,0.1);
17
  }
18
-
19
- /* For Hugging Face specific iframe handling */
20
- section.main {
21
- padding-top: 70px;
 
 
22
  }
23
-
24
- /* Ensure content doesn't get hidden under the header */
25
- .block-container {
26
- padding-top: 1rem;
27
- }
28
-
29
  /* Fix for Hugging Face iframe specific issues */
30
- iframe body .stApp {
31
- padding-top: 3rem;
32
  }
33
-
34
- /* Alternative approach: Create your own sticky header container */
35
- div.sticky-header {
36
- position: fixed;
37
- top: 0;
38
- left: 0;
39
- right: 0;
40
- z-index: 999999;
41
- background-color: white;
42
- padding: 1rem;
43
- box-shadow: 0 2px 5px rgba(0,0,0,0.1);
44
- /* Ensures content below isn't hidden */
45
- margin-bottom: 3rem;
46
  }
47
-
48
- /* Create space below custom sticky header */
49
- div.sticky-header-spacer {
50
- height: 6rem;
51
  }
52
  </style>
53
- """, unsafe_allow_html=True)
54
-
55
- # Option 1: Using Streamlit's native header (modified with CSS above)
56
- st.title("My App with Sticky Header")
57
-
58
- # Option 2: Custom sticky header implementation
59
- # Uncomment and use this approach if the CSS-only solution doesn't work
60
-
61
- # Custom sticky header container
62
- st.markdown('<div class="sticky-header">', unsafe_allow_html=True)
63
- st.title("My App with Custom Sticky Header")
64
- # Add any other header elements here
65
- st.markdown('</div>', unsafe_allow_html=True)
66
-
67
- # Add spacer to ensure content isn't hidden under the header
68
- st.markdown('<div class="sticky-header-spacer"></div>', unsafe_allow_html=True)
69
-
70
-
71
- # Rest of your app
72
- st.write("Scroll down to test the sticky header")
73
-
74
- # Add dummy content to enable scrolling
75
- for i in range(30):
76
- st.write(f"Content block {i}")
77
- st.write("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
78
-
79
-
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  # --- Your Streamlit App ---
82
- #st.logo(image="images/menu_book_60dp_75FBFD.png")
83
  st.title("Map descriptions to SBS codes with Sentence Transformer + Reasoning")
84
  st.subheader("Select specific Chapter for quicker results")
85
  st.logo(image="images/menu_book_60dp_75FBFD.png")
@@ -87,9 +86,6 @@ st.sidebar.header("SBS V2.0 mapper")
87
  st.sidebar.write("(work in progress)")
88
  st.sidebar.text("Demo by JA-RAD")
89
 
90
-
91
-
92
  # --- NAVIGATION SETUP ---
93
  pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
94
- ##pg = st.navigation({"Chapter_Index": [start_page], "Demo": [type_text_page, upload_file_page], "About": [about_page]}) # WITH SECTIONS
95
- pg.run()
 
1
+ import streamlit as st
2
 
3
+ # ---- HEADER CONFIGURATION ----
4
+ # More precise CSS selectors and properties for cross-platform compatibility
5
+ custom_css = """
6
  <style>
7
+ /* Target the header with multiple selectors for better compatibility */
8
+ header[data-testid="stHeader"],
9
+ .stApp > header {
10
+ position: fixed !important;
11
+ top: 0 !important;
12
+ left: 0 !important;
13
+ right: 0 !important;
14
+ width: 100% !important;
15
+ z-index: 999999 !important;
16
+ background-color: #90EE90 !important;
17
+ box-shadow: 0 1px 5px rgba(0,0,0,0.1) !important;
18
  }
19
+
20
+ /* Adjust main content to prevent overlap with fixed header */
21
+ section[data-testid="stMain"],
22
+ .main .block-container {
23
+ padding-top: 60px !important; /* Match your header height */
24
+ margin-top: 10px !important;
25
  }
26
+
 
 
 
 
 
27
  /* Fix for Hugging Face iframe specific issues */
28
+ .st-emotion-cache-lrlib {
29
+ padding-top: 60px !important;
30
  }
31
+
32
+ /* For Hugging Face specific iframe handling */
33
+ iframe#streamlit-iframe {
34
+ padding-top: 0 !important;
 
 
 
 
 
 
 
 
 
35
  }
36
+
37
+ /* Target Hugging Face's iframe content specifically */
38
+ body.hf-w-body .stApp {
39
+ padding-top: 60px !important;
40
  }
41
  </style>
42
+ """
43
+
44
+ # Some Hugging Face deployments need JavaScript for header fixing
45
+ js_fix = """
46
+ <script>
47
+ // This script helps ensure the header stays fixed in Hugging Face's iframe environment
48
+ window.addEventListener('DOMContentLoaded', (event) => {
49
+ // Short delay to ensure DOM is fully loaded
50
+ setTimeout(() => {
51
+ const header = document.querySelector('header[data-testid="stHeader"]');
52
+ if (header) {
53
+ header.style.position = 'fixed';
54
+ header.style.top = '0';
55
+ header.style.zIndex = '999999';
56
+ header.style.width = '100%';
57
+ header.style.backgroundColor = '#90EE90';
58
+
59
+ // Add padding to main content
60
+ const mainContent = document.querySelector('section[data-testid="stMain"]');
61
+ if (mainContent) {
62
+ mainContent.style.paddingTop = '70px';
63
+ }
64
+ }
65
+ }, 100);
66
+ });
67
+ </script>
68
+ """
69
+
70
+ # Inject CSS and JS as early as possible in your app
71
+ st.markdown(custom_css, unsafe_allow_html=True)
72
+ st.markdown(js_fix, unsafe_allow_html=True)
73
+
74
+ # --- PAGE SETUP ---
75
+ type_text_page = st.Page(
76
+ page="pages/type_text.py",
77
+ title="DEMO (work in progress)",
78
+ icon=":material/keyboard:",
79
+ default=True,)
80
 
81
  # --- Your Streamlit App ---
 
82
  st.title("Map descriptions to SBS codes with Sentence Transformer + Reasoning")
83
  st.subheader("Select specific Chapter for quicker results")
84
  st.logo(image="images/menu_book_60dp_75FBFD.png")
 
86
  st.sidebar.write("(work in progress)")
87
  st.sidebar.text("Demo by JA-RAD")
88
 
 
 
89
  # --- NAVIGATION SETUP ---
90
  pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
91
+ pg.run()