Spaces:
Running
Running
// script.js | |
async function sendMessage() { | |
const userInput = document.getElementById("user-input"); | |
const message = userInput.value; | |
if (message.trim() === "") return; | |
displayMessage("You: " + message, "user-message"); | |
userInput.value = ""; | |
// Send message to the server | |
const response = await fetch("http://127.0.0.1:5000/get_response", { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify({ message }), | |
}); | |
const data = await response.json(); | |
displayMessage("Bot: " + data.response, "bot-message"); | |
} | |
function displayMessage(text, className) { | |
const chatLog = document.getElementById("chat-log"); | |
const messageElement = document.createElement("div"); | |
messageElement.className = className; | |
messageElement.textContent = text; | |
chatLog.appendChild(messageElement); | |
chatLog.scrollTop = chatLog.scrollHeight; | |
} | |