georad commited on
Commit
8a08c1a
·
verified ·
1 Parent(s): 36ec921

Update pages/home.py

Browse files
Files changed (1) hide show
  1. pages/home.py +15 -120
pages/home.py CHANGED
@@ -5,126 +5,6 @@ import base64
5
 
6
  st.title("📘Named Entity Recognition")
7
 
8
- #def scroll_to_bottom():
9
- # st.write('Reached Bottom of page!')
10
- #button('Scroll_to_Bottom', 'Ctrl+End', scroll_to_bottom)
11
-
12
- #add_keyboard_shortcuts({'Ctrl+End': 'Scroll to End',})
13
- #if st.button("Scroll to End"):
14
- # st.success("Reached End of page! (You can also press Ctrl+End)")
15
-
16
- def auto_scroll_to_bottom():
17
- # JavaScript to scroll to bottom
18
- js_code = """
19
- <script>
20
- // Wait for the page to fully render
21
- const scrollToBottom = () => {
22
- // Get the main Streamlit iframe
23
- const streamlitDoc = window.parent.document;
24
- // Get the app container
25
- const appContainer = streamlitDoc.querySelector('.main');
26
- if (appContainer) {
27
- // Scroll the app container to the bottom
28
- appContainer.scrollTop = appContainer.scrollHeight;
29
- } else {
30
- // Fallback to scrolling the entire page
31
- window.parent.scrollTo(0, streamlitDoc.body.scrollHeight);
32
- }
33
- };
34
-
35
- // Try immediately
36
- scrollToBottom();
37
-
38
- // Also try after a short delay to ensure content is rendered
39
- setTimeout(scrollToBottom, 200);
40
-
41
- // And after a longer delay just to be safe
42
- setTimeout(scrollToBottom, 500);
43
- </script>
44
- """
45
-
46
- # Render the JavaScript code
47
- html = f'<div style="display:none">{js_code}</div>'
48
- st.components.v1.html(html, height=0)
49
-
50
- # Then in your button click handler, add this:
51
- if st.button("Scroll Down"):
52
- # Call the scroll function at the end
53
- auto_scroll_to_bottom()
54
-
55
-
56
- def scrollToBottom():
57
- # JavaScript to scroll to bottom
58
- JS_code = """
59
- <script>
60
- // Wrap the code in an Immediately Invoked Function Expression (IIFE)
61
- // to create a private scope and potentially avoid conflicts.
62
- (function() {
63
- // Function to scroll to the bottom of a specific container
64
- function scrollToBottom() {
65
- console.log("Attempting to scroll container to bottom."); // Log when scroll function is called
66
- // --- Identify the scrollable container ---
67
- // Streamlit often uses a main container div. We'll try to find it.
68
- // YOU NEED TO INSPECT YOUR DEPLOYED APP'S HTML TO FIND THE CORRECT SELECTOR
69
- // FOR THE ELEMENT THAT ACTUALLY HAS THE SCROLLBAR.
70
- //
71
- // Common candidates based on Streamlit versions and structure:
72
- // - '.stAppViewContainer'
73
- // - '.main'
74
- // - '.block-container'
75
- // - Look for divs with class names starting with 'st-emotion-cache-' followed by random characters.
76
- // - A div directly containing your dynamic content (check its class or ID)
77
- // *** REPLACE THE SELECTOR BELOW with the correct one you found by inspecting your app's HTML ***
78
- // Use document.querySelector('.your-class-name') for a class, or document.getElementById('your-id') for an ID.
79
- const scrollableContainer = document.querySelector('.flex flex-1 flex-col'); // <--- REPLACE THIS ENTIRE LINE IF USING getElementById
80
- // const scrollableContainer = document.getElementById('stMainBlockContainer'); // <--- REPLACE THIS ENTIRE LINE IF USING querySelector
81
- if (scrollableContainer) {
82
- console.log("Scrollable container found. Scrolling...");
83
- // Scroll the found container to its bottom
84
- scrollableContainer.scrollTo({
85
- top: scrollableContainer.scrollHeight,
86
- behavior: 'smooth'
87
- });
88
- } else {
89
- console.warn("Scrollable container not found using the specified selector. Please inspect your app's HTML to find the correct class or ID.");
90
- // Fallback to body scroll (less likely to work for Streamlit's main content area)
91
- window.scrollTo({
92
- top: document.body.scrollHeight,
93
- behavior: 'smooth'
94
- });
95
- }
96
- }
97
- // --- Logic for handling dynamically added content ---
98
- // Create a MutationObserver instance.
99
- // This observer will watch for changes in the DOM.
100
- const observer = new MutationObserver(function(mutations) {
101
- console.log("MutationObserver detected changes."); // Log when observer fires
102
- // Use requestAnimationFrame to ensure the scroll happens after the browser
103
- // has potentially rendered the new content.
104
- requestAnimationFrame(scrollToBottom);
105
- });
106
- // Configure the observer to watch for changes to the child list of the body element.
107
- // We keep observing the body because Streamlit adds content there,
108
- // even if a child element is the one that scrolls.
109
- const config = { childList: true, subtree: true };
110
- console.log("Starting MutationObserver on document.body."); // Log when observer starts
111
- // Start observing the document body for the configured mutations.
112
- observer.observe(document.body, config);
113
- // --- Initial scroll on page load ---
114
- window.addEventListener('load', function() {
115
- console.log("Window loaded. Initial scroll attempt."); // Log on window load
116
- requestAnimationFrame(scrollToBottom);
117
- });
118
- })(); // End of IIFE
119
- </script>
120
- """
121
- # Render the JavaScript code
122
- html = f'<div style="display:none">{JS_code}</div>'
123
- st.components.v1.html(html, height=0, width=0)
124
-
125
- scrollToBottom()
126
-
127
-
128
  st.header("Tags the below 41 medical entities")
129
 
130
  'ACTIVITY'
@@ -167,3 +47,18 @@ st.header("Tags the below 41 medical entities")
167
  'TIME'
168
  'VOLUME'
169
  'WEIGHT'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  st.title("📘Named Entity Recognition")
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  st.header("Tags the below 41 medical entities")
9
 
10
  'ACTIVITY'
 
47
  'TIME'
48
  'VOLUME'
49
  'WEIGHT'
50
+
51
+ # Create scrollable content
52
+ for i in range(100):
53
+ st.write(f"This is scrollable content line {i}")
54
+
55
+ # Add JavaScript to automatically scroll to the bottom
56
+ st.markdown("""
57
+ <script>
58
+ // Set a timeout to ensure the page has loaded
59
+ setTimeout(function() {
60
+ // Get the window object and scroll to the bottom
61
+ window.scrollTo(0, document.body.scrollHeight);
62
+ }, 500);
63
+ </script>
64
+ """, unsafe_allow_html=True)