Chatbot1 / templates /index.html
jithenderchoudary's picture
Create templates/index.html
4276167 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FAQ Chatbot</title>
<style>
/* Basic styles for the chatbot */
#chatbot {
width: 300px;
border: 1px solid #ddd;
padding: 10px;
margin: 20px;
}
#chatbox {
height: 300px;
overflow-y: auto;
margin-bottom: 10px;
}
#user_input {
width: 100%;
padding: 10px;
}
</style>
</head>
<body>
<div id="chatbot">
<div id="chatbox"></div>
<input type="text" id="user_input" placeholder="Ask a question..." />
<button onclick="sendQuestion()">Send</button>
</div>
<script>
function sendQuestion() {
const question = document.getElementById("user_input").value;
fetch('http://localhost:5000/ask', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ 'question': question })
})
.then(response => response.json())
.then(data => {
const chatbox = document.getElementById("chatbox");
chatbox.innerHTML += "<div>User: " + question + "</div>";
chatbox.innerHTML += "<div>Bot: " + data.answer + "</div>";
});
}
</script>
</body>
</html>