RomZay commited on
Commit
b643f37
·
verified ·
1 Parent(s): 6375f48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -122,21 +122,27 @@ def render_message(history):
122
  messages_html += """
123
  </div>
124
  </div>
125
- <script>
126
- function scrollToBottom() {
127
- var chatbox = document.getElementById('chatbox-container');
128
- var messages = document.getElementById('messages'); // Target the messages div
129
- setTimeout(function() { // Delay to ensure content is fully loaded
130
- chatbox.scrollTop = messages.scrollHeight; // Scroll to the bottom of messages div
131
- }, 100); // Delay adjusted for proper loading
132
- }
133
-
134
- window.onload = function() {
135
- scrollToBottom();
136
- };
137
-
138
- setTimeout(scrollToBottom, 100);
139
- </script>
 
 
 
 
 
 
140
  """
141
 
142
  return messages_html
 
122
  messages_html += """
123
  </div>
124
  </div>
125
+
126
+ <script>
127
+ function scrollToBottom() {
128
+ var chatbox = document.getElementById('chatbox-container');
129
+ var messages = document.getElementById('messages');
130
+ chatbox.scrollTop = messages.scrollHeight;
131
+ }
132
+
133
+ var targetNode = document.getElementById('messages');
134
+ var observerOptions = { childList: true, subtree: true };
135
+
136
+ var observer = new MutationObserver(function(mutationsList, observer) {
137
+ scrollToBottom();
138
+ });
139
+
140
+ observer.observe(targetNode, observerOptions);
141
+
142
+ window.onload = function() {
143
+ scrollToBottom();
144
+ };
145
+ </script>
146
  """
147
 
148
  return messages_html