Create templates/index.html
Browse files- templates/index.html +32 -0
templates/index.html
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Chatbot</title>
|
7 |
+
<script>
|
8 |
+
async function sendMessage() {
|
9 |
+
const message = document.getElementById("userInput").value;
|
10 |
+
if (!message) return;
|
11 |
+
|
12 |
+
document.getElementById("chatBox").innerHTML += `<p><b>You:</b> ${message}</p>`;
|
13 |
+
|
14 |
+
const response = await fetch("/chat", {
|
15 |
+
method: "POST",
|
16 |
+
headers: { "Content-Type": "application/json" },
|
17 |
+
body: JSON.stringify({ message })
|
18 |
+
});
|
19 |
+
|
20 |
+
const data = await response.json();
|
21 |
+
document.getElementById("chatBox").innerHTML += `<p><b>Bot:</b> ${data.response}</p>`;
|
22 |
+
document.getElementById("userInput").value = "";
|
23 |
+
}
|
24 |
+
</script>
|
25 |
+
</head>
|
26 |
+
<body>
|
27 |
+
<h2>Chatbot</h2>
|
28 |
+
<div id="chatBox" style="border: 1px solid #000; padding: 10px; width: 50%; height: 300px; overflow-y: scroll;"></div>
|
29 |
+
<input type="text" id="userInput" placeholder="Type a message..." />
|
30 |
+
<button onclick="sendMessage()">Send</button>
|
31 |
+
</body>
|
32 |
+
</html>
|