Spaces:
Sleeping
Sleeping
File size: 1,438 Bytes
9840666 6105d5c 9840666 6105d5c 9840666 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | <!DOCTYPE html>
<html>
<head>
<title>Async Chatbot</title>
<script src="/static/script2.js" defer></script>
<!-- <script >
async function sendMessage() {
const inputEl = document.getElementById("userInput");
const statusEl = document.getElementById("status");
const replyEl = document.getElementById("botReply");
const message = inputEl.value.trim();
if (!message) return;
// Update status
statusEl.innerText = "Connecting to service...";
await delay(300);
statusEl.innerText = "Getting data...";
const response = await fetch("/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message })
});
const data = await response.json();
statusEl.innerText = "Operation complete.";
replyEl.innerText = data.reply;
}
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
</script> -->
</head>
<body>
<h2>Talk to the Bot</h2>
<input type="text" id="userInput" placeholder="Say something..." />
<button onclick="sendMessage()">Send</button>
<p><strong>Status:</strong> <span id="status">Idle</span></p>
<p><strong>Bot:</strong> <span id="botReply"></span></p>
</body>
</html>
|