Spaces:
Sleeping
Sleeping
Create templates/index.html
Browse files- templates/index.html +42 -0
templates/index.html
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
</head>
|
| 8 |
+
<body>
|
| 9 |
+
<h1>Chatbot</h1>
|
| 10 |
+
<div id="chat"></div>
|
| 11 |
+
<input type="text" id="message" placeholder="Type your message here..." />
|
| 12 |
+
<button onclick="sendMessage()">Send</button>
|
| 13 |
+
|
| 14 |
+
<script>
|
| 15 |
+
function sendMessage() {
|
| 16 |
+
const message = document.getElementById('message').value;
|
| 17 |
+
fetch('/chat', {
|
| 18 |
+
method: 'POST',
|
| 19 |
+
headers: {
|
| 20 |
+
'Content-Type': 'application/json'
|
| 21 |
+
},
|
| 22 |
+
body: JSON.stringify({ message: message })
|
| 23 |
+
})
|
| 24 |
+
.then(response => response.json())
|
| 25 |
+
.then(data => {
|
| 26 |
+
document.getElementById('chat').innerHTML += '<p>User: ' + message + '</p>';
|
| 27 |
+
document.getElementById('chat').innerHTML += '<p>Bot: ' + data.response + '</p>';
|
| 28 |
+
if (data.follow_up) {
|
| 29 |
+
const followUp = prompt(data.follow_up);
|
| 30 |
+
if (followUp.toLowerCase() === 'yes') {
|
| 31 |
+
document.getElementById('chat').innerHTML += '<p>User: Yes</p>';
|
| 32 |
+
document.getElementById('chat').innerHTML += '<p>Bot: How can I assist further with this website?</p>';
|
| 33 |
+
} else {
|
| 34 |
+
document.getElementById('chat').innerHTML += '<p>User: No</p>';
|
| 35 |
+
document.getElementById('chat').innerHTML += '<p>Bot: Hi. How can I help you?</p>';
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
});
|
| 39 |
+
}
|
| 40 |
+
</script>
|
| 41 |
+
</body>
|
| 42 |
+
</html>
|