Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>AI Chatbot</title> | |
<script> | |
async function sendMessage() { | |
let userInput = document.getElementById("user-input").value; | |
let chatBox = document.getElementById("chat-box"); | |
chatBox.innerHTML += "<p><b>You:</b> " + userInput + "</p>"; | |
let response = await fetch("/chat", { | |
method: "POST", | |
headers: { "Content-Type": "application/json" }, | |
body: JSON.stringify({ message: userInput }), | |
}); | |
let data = await response.json(); | |
chatBox.innerHTML += "<p><b>Bot:</b> " + (data.reply || "Error in response") + "</p>"; | |
document.getElementById("user-input").value = ""; | |
} | |
</script> | |
</head> | |
<body> | |
<h1>AI Chatbot</h1> | |
<div id="chat-box" style="border:1px solid #ccc; height:300px; overflow:auto;"></div> | |
<input type="text" id="user-input" placeholder="Type a message..."> | |
<button onclick="sendMessage()">Send</button> | |
</body> | |
</html> | |