|
|
<!DOCTYPE html> |
|
|
<html> |
|
|
<head> |
|
|
<title>Chatbot</title> |
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
|
</head> |
|
|
<body> |
|
|
<div id="ui-panel"> |
|
|
<div id="message-box"></div> |
|
|
<form id="message-form"> |
|
|
<input id="message-input" type="text" placeholder="Type your message here..."> |
|
|
<button type="submit"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-send-fill" viewBox="0 0 16 16"> |
|
|
<path d="M15.964.686a.5.5 0 0 0-.65-.65L.767 5.855H.766l-.452.18a.5.5 0 0 0-.082.887l.41.26.001.002 4.995 3.178 3.178 4.995.002.002.26.41a.5.5 0 0 0 .886-.083l6-15Zm-1.833 1.89L6.637 10.07l-.215-.338a.5.5 0 0 0-.154-.154l-.338-.215 7.494-7.494 1.178-.471-.47 1.178Z"/> |
|
|
</svg></button> |
|
|
</form> |
|
|
</div> |
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> |
|
|
<script src="static/js/chat.js"></script> |
|
|
</body> |
|
|
</html> |
|
|
|
|
|
<style> |
|
|
@import url('https://fonts.googleapis.com/css2?family=Nunito&display=swap'); |
|
|
html { |
|
|
height: 100%; |
|
|
width: 100%; |
|
|
background: linear-gradient(to bottom right, #94e1ff, #f7ff96); |
|
|
display: table; |
|
|
margin: auto; |
|
|
} |
|
|
|
|
|
body { |
|
|
font-family: 'Nunito', sans-serif; |
|
|
display: table-cell; |
|
|
vertical-align: middle; |
|
|
height: 80%; |
|
|
} |
|
|
|
|
|
#ui-panel{ |
|
|
background-color: #f7f7f7; |
|
|
border: 2px solid #ccc; |
|
|
border-radius: 20px; |
|
|
margin: auto; |
|
|
vertical-align: middle; |
|
|
word-wrap: break-word; |
|
|
overflow-wrap: break-word; |
|
|
width: 80%; |
|
|
max-width: 40em; |
|
|
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2); |
|
|
} |
|
|
|
|
|
#message-box { |
|
|
overflow-y: scroll; |
|
|
height: auto; |
|
|
margin: 0.5em; |
|
|
padding: 0em 1.5em; |
|
|
height: 500px; |
|
|
} |
|
|
|
|
|
#message-form { |
|
|
margin: 1em auto; |
|
|
width: 90%; |
|
|
height: 50px; |
|
|
display: flex; |
|
|
} |
|
|
|
|
|
#message-form button { |
|
|
border-radius: 50%; |
|
|
width: 60px; |
|
|
height: 50px; |
|
|
color: white; |
|
|
background-color: #239ecd; |
|
|
border: none; |
|
|
} |
|
|
|
|
|
#message-input { |
|
|
width: 100%; |
|
|
font-size: 16px; |
|
|
padding: 10px; |
|
|
border-radius: 10px; |
|
|
margin-right: 10px; |
|
|
border-color: #ccc; |
|
|
} |
|
|
|
|
|
#message-box .chatbot-message { |
|
|
background-color: #239ecd; |
|
|
color: white; |
|
|
border-radius: 20px 20px 20px 0; |
|
|
margin-bottom: 10px; |
|
|
margin-right: 80px; |
|
|
padding: 15px; |
|
|
position: relative; |
|
|
display: flex; |
|
|
align-items: center; |
|
|
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); |
|
|
} |
|
|
|
|
|
#message-box p.you { |
|
|
background-color: #8c8c8c; |
|
|
color: white; |
|
|
margin-bottom: 10px; |
|
|
border-radius: 20px 20px 0 20px; |
|
|
margin-left: 80px; |
|
|
padding: 10px 20px; |
|
|
position: relative; |
|
|
display: flex; |
|
|
align-items: center; |
|
|
justify-content: flex-end; |
|
|
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); |
|
|
overflow-wrap: break-word; |
|
|
} |
|
|
|
|
|
#message-box .chatbot-message img.circle-icon { |
|
|
width: 40px; |
|
|
height: 40px; |
|
|
margin-right: 10px; |
|
|
border-radius: 50%; |
|
|
} |
|
|
|
|
|
#message-box .chatbot-message span { |
|
|
font-size: 14px; |
|
|
font-weight: bold; |
|
|
} |
|
|
|
|
|
#message-box .chatbot-message p { |
|
|
margin: 5px 0 0 0; |
|
|
} |
|
|
|
|
|
#message-box .chatbot-message .message-time { |
|
|
position: absolute; |
|
|
bottom: 0; |
|
|
right: 0; |
|
|
font-size: 12px; |
|
|
margin-bottom: 5px; |
|
|
margin-right: 5px; |
|
|
} |
|
|
|
|
|
#message-box .you-message { |
|
|
text-align: right; |
|
|
} |
|
|
|
|
|
#message-box .you-message span { |
|
|
font-size: 14px; |
|
|
font-weight: bold; |
|
|
} |
|
|
|
|
|
#message-box .you-message p { |
|
|
margin: 5px 0 0 0; |
|
|
} |
|
|
#message-box .you-div { |
|
|
text-align: right; |
|
|
} |
|
|
|
|
|
#message-box .you-message .message-time { |
|
|
position: absolute; |
|
|
bottom: 0; |
|
|
left: 0; |
|
|
font-size: 12px; |
|
|
margin-bottom: 5px; |
|
|
margin-left: 5px; |
|
|
} |
|
|
|
|
|
#message-box .labelText { |
|
|
color: grey; |
|
|
font-size: 14px; |
|
|
} |
|
|
|
|
|
#you-div { |
|
|
text-align: right; |
|
|
} |
|
|
</style> |
|
|
|
|
|
<script> |
|
|
$(document).ready(function() { |
|
|
|
|
|
var messageBox = $('#message-box'); |
|
|
let user_id = ""; |
|
|
|
|
|
function brainyMessage(message) { |
|
|
messageBox.append('<p class="chatbot-message"><img class="circle-icon" src="static/images/mascot_fc7a89.jpg"><span class="chatbot-text">'+message+'</span></p><span class="labelText">Brainy</span></div>'); |
|
|
messageBox.scrollTop(messageBox.prop("scrollHeight")); |
|
|
} |
|
|
|
|
|
function userMessage(message) { |
|
|
messageBox.append('<div id="you-div"><p class="you">'+message+'</p><span class="labelText">You</span></div>'); |
|
|
} |
|
|
|
|
|
$.ajax({ |
|
|
url: '/get_initial', |
|
|
data: {query: ''}, |
|
|
type: 'GET', |
|
|
success: function(response) { |
|
|
brainyMessage(response.response); |
|
|
user_id = response.user_id; |
|
|
} |
|
|
}); |
|
|
|
|
|
$('#message-form').on('submit', function(event) { |
|
|
event.preventDefault(); |
|
|
var message = $('#message-input').val(); |
|
|
userMessage(message); |
|
|
$('#message-input').val(''); |
|
|
$.ajax({ |
|
|
url: '/get_response', |
|
|
data: {"message": message, "user_id": user_id}, |
|
|
type: 'GET', |
|
|
success: function(response) { |
|
|
brainyMessage(response.response); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
</script> |
|
|
|