georad commited on
Commit
3e32e51
·
verified ·
1 Parent(s): 9c09742

Update pages/home.py

Browse files
Files changed (1) hide show
  1. pages/home.py +69 -1
pages/home.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
 
3
  st.title("📘Named Entity Recognition")
4
 
@@ -45,7 +46,74 @@ st.header("Tags the below 41 medical entities")
45
  'VOLUME'
46
  'WEIGHT'
47
 
48
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
 
51
 
 
1
  import streamlit as st
2
+ import streamlit.components.v1 as components
3
 
4
  st.title("📘Named Entity Recognition")
5
 
 
46
  'VOLUME'
47
  'WEIGHT'
48
 
49
+ def scrollToBottom():
50
+ # JavaScript to scroll to bottom
51
+ JS_code = """
52
+ <script>
53
+ // Wrap the code in an Immediately Invoked Function Expression (IIFE)
54
+ // to create a private scope and potentially avoid conflicts.
55
+ (function() {
56
+ // Function to scroll to the bottom of a specific container
57
+ function scrollToBottom() {
58
+ console.log("Attempting to scroll container to bottom."); // Log when scroll function is called
59
+ // --- Identify the scrollable container ---
60
+ // Streamlit often uses a main container div. We'll try to find it.
61
+ // YOU NEED TO INSPECT YOUR DEPLOYED APP'S HTML TO FIND THE CORRECT SELECTOR
62
+ // FOR THE ELEMENT THAT ACTUALLY HAS THE SCROLLBAR.
63
+ //
64
+ // Common candidates based on Streamlit versions and structure:
65
+ // - '.stAppViewContainer'
66
+ // - '.main'
67
+ // - '.block-container'
68
+ // - Look for divs with class names starting with 'st-emotion-cache-' followed by random characters.
69
+ // - A div directly containing your dynamic content (check its class or ID)
70
+ // *** REPLACE THE SELECTOR BELOW with the correct one you found by inspecting your app's HTML ***
71
+ // Use document.querySelector('.your-class-name') for a class, or document.getElementById('your-id') for an ID.
72
+ const scrollableContainer = document.querySelector('.stMain'); // <--- REPLACE THIS ENTIRE LINE IF USING getElementById
73
+ // const scrollableContainer = document.getElementById('stMainBlockContainer'); // <--- REPLACE THIS ENTIRE LINE IF USING querySelector
74
+ if (scrollableContainer) {
75
+ console.log("Scrollable container found. Scrolling...");
76
+ // Scroll the found container to its bottom
77
+ scrollableContainer.scrollTo({
78
+ top: scrollableContainer.scrollHeight,
79
+ behavior: 'smooth'
80
+ });
81
+ } else {
82
+ console.warn("Scrollable container not found using the specified selector. Please inspect your app's HTML to find the correct class or ID.");
83
+ // Fallback to body scroll (less likely to work for Streamlit's main content area)
84
+ window.scrollTo({
85
+ top: document.body.scrollHeight,
86
+ behavior: 'smooth'
87
+ });
88
+ }
89
+ }
90
+ // --- Logic for handling dynamically added content ---
91
+ // Create a MutationObserver instance.
92
+ // This observer will watch for changes in the DOM.
93
+ const observer = new MutationObserver(function(mutations) {
94
+ console.log("MutationObserver detected changes."); // Log when observer fires
95
+ // Use requestAnimationFrame to ensure the scroll happens after the browser
96
+ // has potentially rendered the new content.
97
+ requestAnimationFrame(scrollToBottom);
98
+ });
99
+ // Configure the observer to watch for changes to the child list of the body element.
100
+ // We keep observing the body because Streamlit adds content there,
101
+ // even if a child element is the one that scrolls.
102
+ const config = { childList: true, subtree: true };
103
+ console.log("Starting MutationObserver on document.body."); // Log when observer starts
104
+ // Start observing the document body for the configured mutations.
105
+ observer.observe(document.body, config);
106
+ // --- Initial scroll on page load ---
107
+ window.addEventListener('load', function() {
108
+ console.log("Window loaded. Initial scroll attempt."); // Log on window load
109
+ requestAnimationFrame(scrollToBottom);
110
+ });
111
+ })(); // End of IIFE
112
+ </script>
113
+ """
114
+ # Render the JavaScript code
115
+ html = f'<div style="display:none">{JS_code}</div>'
116
+ st.components.v1.html(html, height=0, width=0)
117
 
118
 
119