georad commited on
Commit
27950ba
·
verified ·
1 Parent(s): 1f31ecc

Update pages/type_text.py

Browse files
Files changed (1) hide show
  1. pages/type_text.py +51 -54
pages/type_text.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
  import pandas as pd
3
  from io import StringIO
4
  import json
@@ -22,55 +23,49 @@ def make_spinner(text = "In progress..."):
22
  with st.spinner(text):
23
  yield
24
 
25
- def scroll_past_status_bar():
26
- st.markdown("""
27
- <script>
28
- // This function finds the correct elements in Streamlit's DOM structure
29
- function scrollPastStatusBar() {
30
- try {
31
- // Get the document of the parent (Streamlit app)
32
- const doc = window.parent.document;
33
-
34
- // Find all the major containers
35
- const appFrame = doc.querySelector('.stApp');
36
- const mainSection = appFrame.querySelector('section.main');
37
- const blockContainer = mainSection.querySelector('.block-container');
38
- const stStatusWidget = doc.querySelector('.stStatusWidget');
39
-
40
- if (blockContainer && stStatusWidget) {
41
- // Get the height of the status widget
42
- const statusHeight = stStatusWidget.offsetHeight;
43
-
44
- // Calculate the position to scroll to
45
- // This will scroll to just above the status bar
46
- const scrollPosition = blockContainer.scrollHeight - window.innerHeight + statusHeight + 20;
47
-
48
- // Perform the scroll on the appropriate container
49
- if (mainSection.scrollTo) {
50
- mainSection.scrollTo({
51
- top: scrollPosition,
52
  behavior: 'smooth'
53
  });
 
 
54
  }
55
-
56
- // Also try scrolling the window as a fallback
57
- window.parent.scrollTo({
58
- top: document.body.scrollHeight,
59
- behavior: 'smooth'
60
- });
61
  }
62
- } catch (e) {
63
- console.error("Scroll error:", e);
64
- }
65
- }
66
-
67
- // Set multiple attempts with delays
68
- setTimeout(scrollPastStatusBar, 100);
69
- setTimeout(scrollPastStatusBar, 300);
70
- setTimeout(scrollPastStatusBar, 600);
71
- </script>
72
- """, unsafe_allow_html=True)
73
-
74
 
75
  #@st.cache
76
  def convert_df(df:pd.DataFrame):
@@ -226,10 +221,11 @@ if INTdesc_input is not None and st.button("Map to SBS codes", key="run_st_model
226
  dfALL = pd.concat([dfALL, pd.DataFrame([dictA])], ignore_index=True)
227
 
228
  st.dataframe(data=dfALL, hide_index=True)
229
- # Add extra space at the bottom to ensure results aren't hidden by status bar
230
- st.markdown("<div style='height: 70px;'></div>", unsafe_allow_html=True)
231
- # Call the scroll function
232
- scroll_past_status_bar()
 
233
 
234
  display_format = "ask REASONING MODEL: Which, if any, of the following SBS descriptions corresponds best to " + INTdesc_input +"? "
235
  #st.write(display_format)
@@ -253,11 +249,12 @@ if INTdesc_input is not None and st.button("Map to SBS codes", key="run_st_model
253
  max_new_tokens=256,
254
  )
255
  st.write(outputs[0]["generated_text"][-1]["content"])
256
- # Add extra space at the bottom to ensure results aren't hidden by status bar
257
- st.markdown("<div style='height: 70px;'></div>", unsafe_allow_html=True)
258
- # Call the scroll function
259
- scroll_past_status_bar()
260
-
 
261
  bs, b1, b2, b3, bLast = st.columns([0.75, 1.5, 1.5, 1.5, 0.75])
262
  with b1:
263
  #csvbutton = download_button(results, "results.csv", "📥 Download .csv")
 
1
  import streamlit as st
2
+ import streamlit.components.v1 as components
3
  import pandas as pd
4
  from io import StringIO
5
  import json
 
23
  with st.spinner(text):
24
  yield
25
 
26
+ def scroll_to_results():
27
+ # Create a hidden HTML component with JavaScript that specifically targets
28
+ # Streamlit's structure and accounts for the fixed status bar
29
+ components.html(
30
+ """
31
+ <script>
32
+ // Wait for the page to be fully loaded
33
+ window.onload = function() {
34
+ // Function to scroll with offset for status bar
35
+ function scrollToResults() {
36
+ try {
37
+ // Get the Streamlit app frame
38
+ const streamlitApp = window.parent.document.querySelector('.stApp');
39
+ if (!streamlitApp) return;
40
+
41
+ // Find the main content area
42
+ const mainContent = streamlitApp.querySelector('.main .block-container');
43
+ if (!mainContent) return;
44
+
45
+ // Calculate scroll position: full scroll minus space for status bar
46
+ const statusBarHeight = 60; // Adjust based on your status bar height
47
+ const scrollTarget = mainContent.scrollHeight - statusBarHeight;
48
+
49
+ // Scroll the content area
50
+ mainContent.scrollTo({
51
+ top: scrollTarget,
 
52
  behavior: 'smooth'
53
  });
54
+ } catch (e) {
55
+ console.error("Error scrolling:", e);
56
  }
 
 
 
 
 
 
57
  }
58
+
59
+ // Execute scroll attempts with delays
60
+ setTimeout(scrollToResults, 100);
61
+ setTimeout(scrollToResults, 500);
62
+ setTimeout(scrollToResults, 1000);
63
+ };
64
+ </script>
65
+ """,
66
+ height=0,
67
+ width=0,
68
+ )
 
69
 
70
  #@st.cache
71
  def convert_df(df:pd.DataFrame):
 
221
  dfALL = pd.concat([dfALL, pd.DataFrame([dictA])], ignore_index=True)
222
 
223
  st.dataframe(data=dfALL, hide_index=True)
224
+ # Call the scroll function after displaying results
225
+ scroll_to_results()
226
+ # Add a small spacer to ensure there's room below the results
227
+ # (this helps prevent the last bit of content from being hidden by the status bar)
228
+ st.markdown("<div style='height: 60px;'></div>", unsafe_allow_html=True)
229
 
230
  display_format = "ask REASONING MODEL: Which, if any, of the following SBS descriptions corresponds best to " + INTdesc_input +"? "
231
  #st.write(display_format)
 
249
  max_new_tokens=256,
250
  )
251
  st.write(outputs[0]["generated_text"][-1]["content"])
252
+ # Call the scroll function after displaying results
253
+ scroll_to_results()
254
+ # Add a small spacer to ensure there's room below the results
255
+ # (this helps prevent the last bit of content from being hidden by the status bar)
256
+ st.markdown("<div style='height: 60px;'></div>", unsafe_allow_html=True)
257
+
258
  bs, b1, b2, b3, bLast = st.columns([0.75, 1.5, 1.5, 1.5, 0.75])
259
  with b1:
260
  #csvbutton = download_button(results, "results.csv", "📥 Download .csv")