-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
59 lines (58 loc) · 1.96 KB
/
index.html
File metadata and controls
59 lines (58 loc) · 1.96 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chatbot</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
padding: 20px;
}
#chat {
border: 1px solid #ccc;
padding: 10px;
max-width: 400px;
margin: auto;
background: white;
max-height: 350px;
overflow-y: auto;
}
.user-input {
width: 100%;
padding: 10px;
margin-top: 10px;
}
.button {
padding: 10px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Chat with MyBot</h1>
<div id="chat"></div>
<input class="user-input" id="user-input" type="text" placeholder="Type your message here..."/>
<button class="button" onclick="sendMessage()">Send</button>
<script>
function sendMessage() {
const userInput = document.getElementById("user-input").value;
document.getElementById("chat").innerHTML += "<p><strong>You:</strong> " + userInput + "</p>";
fetch('http://127.0.0.1:5000/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: userInput })
})
.then(response => response.json())
.then(data => {
document.getElementById("chat").innerHTML += "<p><strong>Bot:</strong> " + data.response + "</p>";
document.getElementById("user-input").value = ''; // Clear input field
document.getElementById("chat").scrollTop = document.getElementById("chat").scrollHeight; // Scroll to the bottom
});
}
</script>
</body>
</html>