georad commited on
Commit
f4ae373
·
verified ·
1 Parent(s): 1c7dd78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -40
app.py CHANGED
@@ -1,69 +1,103 @@
1
  import streamlit as st
2
 
3
- # Remove any previous custom CSS styles
4
- # Create a custom sticky header using Streamlit components
5
 
6
- # Custom CSS only for basic styling, not position control
7
  st.markdown("""
8
  <style>
9
- /* Basic styling for our custom header */
10
- .custom-sticky-header {
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  background-color: #90EE90;
12
- padding: 10px 15px;
13
- border-bottom: 1px solid #ccc;
14
- margin-bottom: 20px;
15
  }
16
 
17
- /* Hide the default Streamlit header */
18
- [data-testid="stHeader"] {
19
- visibility: hidden;
20
- height: 0;
21
  }
22
 
23
- /* Ensure our custom header stays at the top */
24
- [data-testid="stVerticalBlock"] > div:first-child {
25
- position: sticky !important;
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 placeholder for the sticky header at the very top of the app
34
- # This has to be the first element in your app
35
- header_container = st.container()
36
-
37
- # Use the container to create a custom header
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
- # Add the image directly in the header
47
- try:
48
- st.image("images/menu_book_60dp_75FBFD.png", width=100)
49
- except:
50
- # In case the image path doesn't work
51
- st.write("Logo image")
 
 
 
 
 
 
 
 
52
 
53
- # Add a small spacer
54
  st.write("")
55
 
56
- # Rest of your app works as normal
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
- # Your page setup and navigation
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()