Spaces:
Build error
Build error
Update static/script.js
Browse files- static/script.js +29 -7
static/script.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
}
|
|
|
|
| 1 |
+
let state = null;
|
| 2 |
+
|
| 3 |
+
async function sendMessage() {
|
| 4 |
+
let inputText = document.getElementById("user-input").value;
|
| 5 |
+
document.getElementById("user-input").value = "";
|
| 6 |
+
let chatBox = document.getElementById("chat-box");
|
| 7 |
+
|
| 8 |
+
// Display the user's message
|
| 9 |
+
chatBox.innerHTML += `<div>User: ${inputText}</div>`;
|
| 10 |
+
|
| 11 |
+
// Send the message to the Gradio backend (via your Gradio app)
|
| 12 |
+
let response = await fetch("http://localhost:7860/api/predict/", {
|
| 13 |
+
method: "POST",
|
| 14 |
+
headers: {
|
| 15 |
+
"Content-Type": "application/json"
|
| 16 |
+
},
|
| 17 |
+
body: JSON.stringify({
|
| 18 |
+
data: [inputText, state],
|
| 19 |
+
}),
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
let result = await response.json();
|
| 23 |
+
let botMessage = result.data[0];
|
| 24 |
+
|
| 25 |
+
// Display the bot's response
|
| 26 |
+
chatBox.innerHTML += `<div>Bot: ${botMessage}</div>`;
|
| 27 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
| 28 |
+
|
| 29 |
+
state = result.data[1]; // Update the state for next round
|
| 30 |
}
|