Update pages/type_text.py
Browse files- pages/type_text.py +16 -36
pages/type_text.py
CHANGED
@@ -9,6 +9,8 @@ import time
|
|
9 |
import os
|
10 |
os.getenv("HF_TOKEN")
|
11 |
|
|
|
|
|
12 |
def get_device_map() -> str:
|
13 |
return 'cuda' if torch.cuda.is_available() else 'cpu'
|
14 |
device = get_device_map() # 'cpu'
|
@@ -20,40 +22,6 @@ def make_spinner(text = "In progress..."):
|
|
20 |
with st.spinner(text):
|
21 |
yield
|
22 |
|
23 |
-
def auto_scroll_to_bottom():
|
24 |
-
# JavaScript to scroll to bottom
|
25 |
-
js_code = """
|
26 |
-
<script>
|
27 |
-
// Wait for the page to fully render
|
28 |
-
const scrollToBottom = () => {
|
29 |
-
// Get the main Streamlit iframe
|
30 |
-
const streamlitDoc = window.parent.document;
|
31 |
-
// Get the app container
|
32 |
-
const appContainer = streamlitDoc.querySelector('.main');
|
33 |
-
if (appContainer) {
|
34 |
-
// Scroll the app container to the bottom
|
35 |
-
appContainer.scrollTop = appContainer.scrollHeight;
|
36 |
-
} else {
|
37 |
-
// Fallback to scrolling the entire page
|
38 |
-
window.parent.scrollTo(0, streamlitDoc.body.scrollHeight);
|
39 |
-
}
|
40 |
-
};
|
41 |
-
|
42 |
-
// Try immediately
|
43 |
-
scrollToBottom();
|
44 |
-
|
45 |
-
// Also try after a short delay to ensure content is rendered
|
46 |
-
setTimeout(scrollToBottom, 200);
|
47 |
-
|
48 |
-
// And after a longer delay just to be safe
|
49 |
-
setTimeout(scrollToBottom, 500);
|
50 |
-
</script>
|
51 |
-
"""
|
52 |
-
|
53 |
-
# Render the JavaScript code
|
54 |
-
html = f'<div style="display:none">{js_code}</div>'
|
55 |
-
st.components.v1.html(html, height=0)
|
56 |
-
|
57 |
#@st.cache
|
58 |
def convert_df(df:pd.DataFrame):
|
59 |
return df.to_csv(index=False).encode('utf-8')
|
@@ -208,7 +176,13 @@ if INTdesc_input is not None and st.button("Map to SBS codes", key="run_st_model
|
|
208 |
dfALL = pd.concat([dfALL, pd.DataFrame([dictA])], ignore_index=True)
|
209 |
|
210 |
st.dataframe(data=dfALL, hide_index=True)
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
|
213 |
display_format = "ask REASONING MODEL: Which, if any, of the following SBS descriptions corresponds best to " + INTdesc_input +"? "
|
214 |
#st.write(display_format)
|
@@ -232,7 +206,13 @@ if INTdesc_input is not None and st.button("Map to SBS codes", key="run_st_model
|
|
232 |
max_new_tokens=256,
|
233 |
)
|
234 |
st.write(outputs[0]["generated_text"][-1]["content"])
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
bs, b1, b2, b3, bLast = st.columns([0.75, 1.5, 1.5, 1.5, 0.75])
|
238 |
with b1:
|
|
|
9 |
import os
|
10 |
os.getenv("HF_TOKEN")
|
11 |
|
12 |
+
bottom_anchor = st.empty()
|
13 |
+
|
14 |
def get_device_map() -> str:
|
15 |
return 'cuda' if torch.cuda.is_available() else 'cpu'
|
16 |
device = get_device_map() # 'cpu'
|
|
|
22 |
with st.spinner(text):
|
23 |
yield
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
#@st.cache
|
26 |
def convert_df(df:pd.DataFrame):
|
27 |
return df.to_csv(index=False).encode('utf-8')
|
|
|
176 |
dfALL = pd.concat([dfALL, pd.DataFrame([dictA])], ignore_index=True)
|
177 |
|
178 |
st.dataframe(data=dfALL, hide_index=True)
|
179 |
+
with bottom_anchor:
|
180 |
+
st.markdown("""
|
181 |
+
<div id="bottom"></div>
|
182 |
+
<script>
|
183 |
+
window.location.href = "#bottom";
|
184 |
+
</script>
|
185 |
+
""", unsafe_allow_html=True)
|
186 |
|
187 |
display_format = "ask REASONING MODEL: Which, if any, of the following SBS descriptions corresponds best to " + INTdesc_input +"? "
|
188 |
#st.write(display_format)
|
|
|
206 |
max_new_tokens=256,
|
207 |
)
|
208 |
st.write(outputs[0]["generated_text"][-1]["content"])
|
209 |
+
with bottom_anchor:
|
210 |
+
st.markdown("""
|
211 |
+
<div id="bottom"></div>
|
212 |
+
<script>
|
213 |
+
window.location.href = "#bottom";
|
214 |
+
</script>
|
215 |
+
""", unsafe_allow_html=True)
|
216 |
|
217 |
bs, b1, b2, b3, bLast = st.columns([0.75, 1.5, 1.5, 1.5, 0.75])
|
218 |
with b1:
|