Update pages/type_text.py
Browse files- 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
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
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 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
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 |
-
#
|
230 |
-
|
231 |
-
#
|
232 |
-
|
|
|
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 |
-
#
|
257 |
-
|
258 |
-
#
|
259 |
-
|
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")
|