RomZay commited on
Commit
e3ea02b
·
verified ·
1 Parent(s): f2aaaa2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -129,24 +129,26 @@ def render_message(history):
129
 
130
  js = """
131
  function Scrolldown() {
132
- let targetNode = document.querySelector('#chatbox-container');
133
-
134
- if (!targetNode) {
135
- console.log("no target")
136
- setTimeout(() => {
137
- console.log("Retrying")
138
- }, 3000);
 
 
 
 
 
 
 
 
 
 
139
  }
140
 
141
- const config = { childList: true, subtree: true };
142
-
143
- const callback = (mutationList, observer) => {
144
- targetNode.scrollTop = targetNode.scrollHeight;
145
- };
146
-
147
- const observer = new MutationObserver(callback);
148
-
149
- observer.observe(targetNode, config);
150
  }
151
  """
152
  with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;}", js=js) as demo:
 
129
 
130
  js = """
131
  function Scrolldown() {
132
+ function startObserver() {
133
+ let targetNode = document.getElementById('chatbox-container');
134
+
135
+ if (!targetNode) {
136
+ console.log("Chatbox container not found, retrying in 1 second...");
137
+ setTimeout(startObserver, 1000);
138
+ return;
139
+ }
140
+
141
+ console.log("Chatbox container found, starting observer");
142
+
143
+ const config = { childList: true, subtree: true };
144
+ const callback = (mutationList, observer) => {
145
+ targetNode.scrollTop = targetNode.scrollHeight;
146
+ };
147
+ const observer = new MutationObserver(callback);
148
+ observer.observe(targetNode, config);
149
  }
150
 
151
+ document.addEventListener("DOMContentLoaded", startObserver);
 
 
 
 
 
 
 
 
152
  }
153
  """
154
  with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;}", js=js) as demo: