Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Tannu FAQ Chatbot</title> | |
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet"> | |
<style> | |
:root { | |
--primary-color: #6c5ce7; | |
--secondary-color: #a29bfe; | |
--background-color: #f9f9f9; | |
--text-color: #333; | |
--message-bg-user: #6c5ce7; | |
--message-bg-bot: #f0f0f0; | |
} | |
* { | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
} | |
body { | |
font-family: 'Roboto', sans-serif; | |
background-color: var(--background-color); | |
color: var(--text-color); | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
min-height: 100vh; | |
} | |
.chat-container { | |
width: 100%; | |
max-width: 800px; | |
background-color: white; | |
border-radius: 20px; | |
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); | |
overflow: hidden; | |
display: flex; | |
flex-direction: column; | |
height: 90vh; | |
} | |
.chat-header { | |
background-color: var(--primary-color); | |
color: white; | |
padding: 20px; | |
text-align: center; | |
font-size: 24px; | |
font-weight: 500; | |
} | |
.chat-messages { | |
flex-grow: 1; | |
overflow-y: auto; | |
padding: 20px; | |
display: flex; | |
flex-direction: column; | |
} | |
.message { | |
max-width: 80%; | |
margin-bottom: 15px; | |
padding: 12px 18px; | |
border-radius: 20px; | |
font-size: 16px; | |
line-height: 1.4; | |
opacity: 0; | |
transform: translateY(20px); | |
animation: fadeIn 0.3s forwards; | |
} | |
@keyframes fadeIn { | |
to { | |
opacity: 1; | |
transform: translateY(0); | |
} | |
} | |
.user-message { | |
align-self: flex-end; | |
background-color: var(--message-bg-user); | |
color: white; | |
border-bottom-right-radius: 0; | |
} | |
.bot-message { | |
align-self: flex-start; | |
background-color: var(--message-bg-bot); | |
color: var(--text-color); | |
border-bottom-left-radius: 0; | |
} | |
.chat-input { | |
display: flex; | |
padding: 20px; | |
background-color: white; | |
border-top: 1px solid #e0e0e0; | |
} | |
#user-input { | |
flex-grow: 1; | |
padding: 12px 20px; | |
border: 2px solid var(--secondary-color); | |
border-radius: 30px; | |
font-size: 16px; | |
outline: none; | |
transition: border-color 0.3s; | |
} | |
#user-input:focus { | |
border-color: var(--primary-color); | |
} | |
#send-button { | |
padding: 12px 24px; | |
background-color: var(--primary-color); | |
color: white; | |
border: none; | |
border-radius: 30px; | |
margin-left: 10px; | |
cursor: pointer; | |
font-size: 16px; | |
font-weight: 500; | |
transition: background-color 0.3s; | |
} | |
#send-button:hover { | |
background-color: var(--secondary-color); | |
} | |
/* Scrollbar Styles */ | |
.chat-messages::-webkit-scrollbar { | |
width: 8px; | |
} | |
.chat-messages::-webkit-scrollbar-track { | |
background: #f1f1f1; | |
} | |
.chat-messages::-webkit-scrollbar-thumb { | |
background: var(--secondary-color); | |
border-radius: 10px; | |
} | |
.chat-messages::-webkit-scrollbar-thumb:hover { | |
background: var(--primary-color); | |
} | |
</style> | |
</head> | |
<body> | |
<div class="chat-container"> | |
<div class="chat-header"> | |
FAQ Chatbot | |
</div> | |
<div class="chat-messages" id="chat-messages"></div> | |
<div class="chat-input"> | |
<input type="text" id="user-input" placeholder="Type your question..."> | |
<button id="send-button">Send</button> | |
</div> | |
</div> | |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> | |
<script> | |
$(document).ready(function () { | |
function cleanMessage(message) { | |
// Remove </Tannu> and <user> tags | |
return message.replace(/<\/Tannu>|<user>/g, '').trim(); | |
} | |
function addMessage(message, isUser) { | |
const cleanedMessage = cleanMessage(message); | |
const messageDiv = $('<div>').addClass('message').text(cleanedMessage); | |
if (isUser) { | |
messageDiv.addClass('user-message'); | |
} else { | |
messageDiv.addClass('bot-message'); | |
} | |
$('#chat-messages').append(messageDiv); | |
$('#chat-messages').scrollTop($('#chat-messages')[0].scrollHeight); | |
} | |
$('#send-button').click(function () { | |
const userMessage = $('#user-input').val().trim(); | |
if (userMessage) { | |
addMessage(userMessage, true); | |
$('#user-input').val(''); | |
$.ajax({ | |
url: '/chat', | |
method: 'POST', | |
contentType: 'application/json', | |
data: JSON.stringify({ message: userMessage }), | |
success: function (response) { | |
addMessage(response.message, false); | |
} | |
}); | |
} | |
}); | |
$('#user-input').keypress(function (e) { | |
if (e.which == 13) { | |
$('#send-button').click(); | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |