Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -130,7 +130,7 @@ def render_message(history):
|
|
| 130 |
js = """
|
| 131 |
function Scrolldown() {
|
| 132 |
function startObserver() {
|
| 133 |
-
let targetNode = document.
|
| 134 |
|
| 135 |
if (!targetNode) {
|
| 136 |
console.log("Chatbox container not found, retrying in 1 second...");
|
|
@@ -144,14 +144,15 @@ function Scrolldown() {
|
|
| 144 |
const callback = (mutationList, observer) => {
|
| 145 |
targetNode.scrollTop = targetNode.scrollHeight;
|
| 146 |
};
|
| 147 |
-
console.log("begun to observe")
|
| 148 |
const observer = new MutationObserver(callback);
|
| 149 |
observer.observe(targetNode, config);
|
| 150 |
}
|
| 151 |
|
| 152 |
-
|
| 153 |
-
console.log("event found")
|
| 154 |
}
|
|
|
|
|
|
|
|
|
|
| 155 |
"""
|
| 156 |
with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;}", js=js) as demo:
|
| 157 |
|
|
@@ -166,7 +167,7 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid
|
|
| 166 |
with gr.Column(visible=False) as chat_view:
|
| 167 |
gr.Markdown("## P-MSQ Chat Interface")
|
| 168 |
|
| 169 |
-
chatbot_output = gr.HTML(elem_id="chatbox")
|
| 170 |
|
| 171 |
msg_input = gr.Textbox(
|
| 172 |
show_label=False,
|
|
@@ -193,10 +194,7 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid
|
|
| 193 |
|
| 194 |
def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
|
| 195 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
| 196 |
-
|
| 197 |
-
full_history_html = render_message(history)
|
| 198 |
-
|
| 199 |
-
return full_history_html, history, "", message
|
| 200 |
|
| 201 |
|
| 202 |
|
|
@@ -213,13 +211,17 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid
|
|
| 213 |
history = session.get("history", [])
|
| 214 |
return render_message(history), history
|
| 215 |
|
| 216 |
-
msg_input.submit(
|
| 217 |
-
|
| 218 |
-
|
|
|
|
|
|
|
| 219 |
|
| 220 |
-
send_btn.click(
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
| 223 |
|
| 224 |
regen_btn.click(clear_history,
|
| 225 |
inputs=[api_key_input],
|
|
|
|
| 130 |
js = """
|
| 131 |
function Scrolldown() {
|
| 132 |
function startObserver() {
|
| 133 |
+
let targetNode = document.querySelector('#chatbox-container');
|
| 134 |
|
| 135 |
if (!targetNode) {
|
| 136 |
console.log("Chatbox container not found, retrying in 1 second...");
|
|
|
|
| 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 |
+
startObserver();
|
|
|
|
| 152 |
}
|
| 153 |
+
|
| 154 |
+
// Ensure function is available globally
|
| 155 |
+
window.Scrolldown = Scrolldown;
|
| 156 |
"""
|
| 157 |
with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;}", js=js) as demo:
|
| 158 |
|
|
|
|
| 167 |
with gr.Column(visible=False) as chat_view:
|
| 168 |
gr.Markdown("## P-MSQ Chat Interface")
|
| 169 |
|
| 170 |
+
chatbot_output = gr.HTML(elem_id="chatbox-container")
|
| 171 |
|
| 172 |
msg_input = gr.Textbox(
|
| 173 |
show_label=False,
|
|
|
|
| 194 |
|
| 195 |
def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
|
| 196 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
| 197 |
+
return render_message(history), history, "", gr.HTML("<script>Scrolldown();</script>")
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
|
| 200 |
|
|
|
|
| 211 |
history = session.get("history", [])
|
| 212 |
return render_message(history), history
|
| 213 |
|
| 214 |
+
msg_input.submit(
|
| 215 |
+
user_interaction,
|
| 216 |
+
inputs=[msg_input, history_state, api_key_input, max_tokens, top_p, temperature],
|
| 217 |
+
outputs=[chatbot_output, history_state, msg_input, gr.HTML()]
|
| 218 |
+
)
|
| 219 |
|
| 220 |
+
send_btn.click(
|
| 221 |
+
user_interaction,
|
| 222 |
+
inputs=[msg_input, history_state, api_key_input, max_tokens, top_p, temperature],
|
| 223 |
+
outputs=[chatbot_output, history_state, msg_input, gr.HTML()]
|
| 224 |
+
)
|
| 225 |
|
| 226 |
regen_btn.click(clear_history,
|
| 227 |
inputs=[api_key_input],
|