Spaces:
Sleeping
Sleeping
Update static/js/script.js
Browse files- static/js/script.js +44 -44
static/js/script.js
CHANGED
@@ -1,44 +1,44 @@
|
|
1 |
-
document.getElementById("send-button").addEventListener("click", function() {
|
2 |
-
sendMessage();
|
3 |
-
});
|
4 |
-
|
5 |
-
document.getElementById("user-input").addEventListener("keypress", function(event) {
|
6 |
-
if (event.key === "Enter") {
|
7 |
-
sendMessage();
|
8 |
-
}
|
9 |
-
});
|
10 |
-
|
11 |
-
const micButton = document.getElementById("mic-button");
|
12 |
-
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
13 |
-
recognition.lang = "my-MM"; // Set to Burmese
|
14 |
-
recognition.continuous = false;
|
15 |
-
|
16 |
-
micButton.addEventListener("click", () => {
|
17 |
-
recognition.start();
|
18 |
-
});
|
19 |
-
|
20 |
-
recognition.onresult = (event) => {
|
21 |
-
document.getElementById("user-input").value = event.results[0][0].transcript;
|
22 |
-
};
|
23 |
-
|
24 |
-
function sendMessage() {
|
25 |
-
let userMessage = document.getElementById("user-input").value;
|
26 |
-
let chatbox = document.getElementById("chatbox");
|
27 |
-
|
28 |
-
if (userMessage.trim() === "") return;
|
29 |
-
|
30 |
-
// Display user message
|
31 |
-
chatbox.innerHTML += `<p><strong>You:</strong> ${userMessage}</p>`;
|
32 |
-
document.getElementById("user-input").value = "";
|
33 |
-
|
34 |
-
fetch("/chat", {
|
35 |
-
method: "POST",
|
36 |
-
headers: { "Content-Type": "application/json" },
|
37 |
-
body: JSON.stringify({ message: userMessage })
|
38 |
-
})
|
39 |
-
.then(response => response.json())
|
40 |
-
.then(data => {
|
41 |
-
chatbox.innerHTML += `<p><strong>Bot:</strong> ${data.reply}</p>`;
|
42 |
-
})
|
43 |
-
.catch(error => console.error("Error:", error));
|
44 |
-
}
|
|
|
1 |
+
document.getElementById("send-button").addEventListener("click", function() {
|
2 |
+
sendMessage();
|
3 |
+
});
|
4 |
+
|
5 |
+
document.getElementById("user-input").addEventListener("keypress", function(event) {
|
6 |
+
if (event.key === "Enter") {
|
7 |
+
sendMessage();
|
8 |
+
}
|
9 |
+
});
|
10 |
+
|
11 |
+
const micButton = document.getElementById("mic-button");
|
12 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
13 |
+
recognition.lang = "my-MM"; // Set to Burmese
|
14 |
+
recognition.continuous = false;
|
15 |
+
|
16 |
+
micButton.addEventListener("click", () => {
|
17 |
+
recognition.start();
|
18 |
+
});
|
19 |
+
|
20 |
+
recognition.onresult = (event) => {
|
21 |
+
document.getElementById("user-input").value = event.results[0][0].transcript;
|
22 |
+
};
|
23 |
+
|
24 |
+
function sendMessage() {
|
25 |
+
let userMessage = document.getElementById("user-input").value;
|
26 |
+
let chatbox = document.getElementById("chatbox");
|
27 |
+
|
28 |
+
if (userMessage.trim() === "") return;
|
29 |
+
|
30 |
+
// Display user message
|
31 |
+
chatbox.innerHTML += `<p><strong>You:</strong> ${userMessage}</p>`;
|
32 |
+
document.getElementById("user-input").value = "";
|
33 |
+
|
34 |
+
fetch("https://whtet-burmese-chatbot.hf.space/chat", {
|
35 |
+
method: "POST",
|
36 |
+
headers: { "Content-Type": "application/json" },
|
37 |
+
body: JSON.stringify({ message: userMessage })
|
38 |
+
})
|
39 |
+
.then(response => response.json())
|
40 |
+
.then(data => {
|
41 |
+
chatbox.innerHTML += `<p><strong>Bot:</strong> ${data.reply}</p>`;
|
42 |
+
})
|
43 |
+
.catch(error => console.error("Error:", error));
|
44 |
+
}
|