georad commited on
Commit
8cd1dac
·
verified ·
1 Parent(s): e7809e3

Update pages/type_text.py

Browse files
Files changed (1) hide show
  1. pages/type_text.py +2 -57
pages/type_text.py CHANGED
@@ -9,21 +9,6 @@ import time
9
  import os
10
  os.getenv("HF_TOKEN")
11
 
12
-
13
- #hide_streamlit_style = """
14
- # <style>
15
- # div[data-testid="stHeader"] {
16
- # visibility: visible;
17
- # position: sticky;
18
- # top: 0
19
- # }
20
- # </style>
21
- # """
22
- #st.markdown(hide_streamlit_style, unsafe_allow_html=True)
23
-
24
- #st.title("Map internal descriptions to SBS codes with Sentence Transformer + Reasoning Models")
25
- #st.subheader("Select specific Chapter for quicker results")
26
-
27
  def get_device_map() -> str:
28
  return 'cuda' if torch.cuda.is_available() else 'cpu'
29
  device = get_device_map() # 'cpu'
@@ -47,46 +32,6 @@ def convert_json(df:pd.DataFrame):
47
  #st.json(json_string, expanded=True)
48
  return json_string
49
 
50
- def scroll_to_bottom():
51
- # This script uses Streamlit's message system to ensure proper timing
52
- js_code = """
53
- <script>
54
- // Function to scroll to bottom
55
- function scrollToBottom() {
56
- // This targets Streamlit's specific structure
57
- const mainContainer = window.parent.document.querySelector('.stApp');
58
- if (mainContainer) {
59
- mainContainer.scrollTo({
60
- top: mainContainer.scrollHeight,
61
- behavior: 'smooth'
62
- });
63
- }
64
- }
65
-
66
- // Use MutationObserver to detect when content is added
67
- const observer = new MutationObserver((mutations) => {
68
- scrollToBottom();
69
- });
70
-
71
- // Start observing the document body for changes
72
- const streamlitDoc = window.parent.document;
73
- observer.observe(streamlitDoc.body, {
74
- childList: true,
75
- subtree: true
76
- });
77
-
78
- // Initial scroll and disconnect after some time
79
- scrollToBottom();
80
- setTimeout(() => {
81
- observer.disconnect();
82
- // One final scroll
83
- scrollToBottom();
84
- }, 1000);
85
- </script>
86
- """
87
-
88
- # Use unsafe_allow_html to inject JavaScript
89
- st.markdown(js_code, unsafe_allow_html=True)
90
 
91
  #df_chapters = pd.read_csv("SBS_V2_0/Chapter_Index_Rows.csv")
92
  df_chapters = pd.read_csv("SBS_V2_0/Chapter_Index_Rows_with_total.csv")
@@ -230,7 +175,7 @@ if INTdesc_input is not None and st.button("Map to SBS codes", key="run_st_model
230
  dfALL = pd.concat([dfALL, pd.DataFrame([dictA])], ignore_index=True)
231
 
232
  st.dataframe(data=dfALL, hide_index=True)
233
- scroll_to_bottom()
234
 
235
  display_format = "ask REASONING MODEL: Which, if any, of the following SBS descriptions corresponds best to " + INTdesc_input +"? "
236
  #st.write(display_format)
@@ -254,7 +199,7 @@ if INTdesc_input is not None and st.button("Map to SBS codes", key="run_st_model
254
  max_new_tokens=256,
255
  )
256
  st.write(outputs[0]["generated_text"][-1]["content"])
257
- scroll_to_bottom()
258
 
259
  bs, b1, b2, b3, bLast = st.columns([0.75, 1.5, 1.5, 1.5, 0.75])
260
  with b1:
 
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'
 
32
  #st.json(json_string, expanded=True)
33
  return json_string
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  #df_chapters = pd.read_csv("SBS_V2_0/Chapter_Index_Rows.csv")
37
  df_chapters = pd.read_csv("SBS_V2_0/Chapter_Index_Rows_with_total.csv")
 
175
  dfALL = pd.concat([dfALL, pd.DataFrame([dictA])], ignore_index=True)
176
 
177
  st.dataframe(data=dfALL, hide_index=True)
178
+ auto_scroll_to_bottom()
179
 
180
  display_format = "ask REASONING MODEL: Which, if any, of the following SBS descriptions corresponds best to " + INTdesc_input +"? "
181
  #st.write(display_format)
 
199
  max_new_tokens=256,
200
  )
201
  st.write(outputs[0]["generated_text"][-1]["content"])
202
+ auto_scroll_to_bottom()
203
 
204
  bs, b1, b2, b3, bLast = st.columns([0.75, 1.5, 1.5, 1.5, 0.75])
205
  with b1: