ruchi
commited on
Commit
·
fce0fda
1
Parent(s):
53b791b
Init commit
Browse files- index.html +19 -18
- index.js +44 -0
- style.css +90 -24
index.html
CHANGED
|
@@ -1,19 +1,20 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
</html>
|
|
|
|
| 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 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div class="header">
|
| 11 |
+
<h1>Super Lazy BOT</h1>
|
| 12 |
+
</div>
|
| 13 |
+
<div class="chat-container">
|
| 14 |
+
<div class="chat-box" id="chat-box"></div>
|
| 15 |
+
<input type="text" id="user-input" placeholder="Type your message...">
|
| 16 |
+
<button id="send-btn" onclick="sendMessage()">Send</button>
|
| 17 |
+
</div>
|
| 18 |
+
<script type="module" src="index.js"></script>
|
| 19 |
+
</body>
|
| 20 |
</html>
|
index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
|
| 2 |
+
|
| 3 |
+
const answerer = await pipeline('question-answering', 'Xenova/distilbert-base-uncased-distilled-squad');
|
| 4 |
+
var chatBox = document.getElementById("chat-box");
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
// Function to handle sending message
|
| 8 |
+
function sendMessage() {
|
| 9 |
+
var userInput = document.getElementById("user-input").value;
|
| 10 |
+
sendMessageAndUpdateChat(userInput);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
// Detect objects in the image
|
| 15 |
+
async function getAnswer(question) {
|
| 16 |
+
const context = 'As of December 2022, MrBeast is the most-subscribed YouTuber, with 116 million subscribers. PewDiePie is the second most popular with 111 million subscribers. To celebrate reaching 100 million subscribers, MrBeast gave away a private island which is probably a part of the reason he took the top position from PewDiePie.';
|
| 17 |
+
const output = await answerer(question, context);
|
| 18 |
+
setTimeout(function() {
|
| 19 |
+
chatBox.innerHTML += "<p class='bot-message'><strong>Chatbot:</strong> " + output.answer + "</p>";
|
| 20 |
+
// Scroll to bottom of chat box
|
| 21 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
| 22 |
+
}, 500);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
// Function to send message and update chat
|
| 26 |
+
function sendMessageAndUpdateChat(message) {
|
| 27 |
+
|
| 28 |
+
// Display user message
|
| 29 |
+
chatBox.innerHTML += "<p class='user-message'><strong>You:</strong> " + message + "</p>";
|
| 30 |
+
getAnswer(message)
|
| 31 |
+
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// Event listener for Enter key press
|
| 35 |
+
document.getElementById("user-input").addEventListener("keypress", function(event) {
|
| 36 |
+
if (event.key === "Enter") {
|
| 37 |
+
var userInput = document.getElementById("user-input").value;
|
| 38 |
+
sendMessageAndUpdateChat(userInput);
|
| 39 |
+
document.getElementById("user-input").value = ""; // Clear input field after sending message
|
| 40 |
+
}
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
style.css
CHANGED
|
@@ -1,28 +1,94 @@
|
|
| 1 |
body {
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
font-size: 16px;
|
| 8 |
-
margin-top: 0;
|
| 9 |
-
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
-
.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
.
|
| 27 |
-
|
| 28 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
body {
|
| 2 |
+
font-family: Arial, sans-serif;
|
| 3 |
+
margin: 0;
|
| 4 |
+
padding: 0;
|
| 5 |
+
background-color: #f4f4f4;
|
| 6 |
+
}
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
.header {
|
| 9 |
+
background: linear-gradient(135deg, #FFA500, #FF6347); /* Gradient from orange to coral */
|
| 10 |
+
color: #fff;
|
| 11 |
+
text-align: center;
|
| 12 |
+
padding: 20px 0;
|
| 13 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* Add a subtle shadow */
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
.header h1 {
|
| 18 |
+
margin: 0;
|
| 19 |
+
font-size: 24px;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/* Rest of the CSS for the chat-container, chat-box, input-container, and send button remains the same */
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
.chat-container {
|
| 26 |
+
max-width: 500px; /* Increased width */
|
| 27 |
+
margin: 20px auto;
|
| 28 |
+
background-color: #fff;
|
| 29 |
+
border-radius: 20px; /* Increased border radius */
|
| 30 |
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
| 31 |
+
overflow: hidden;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.chat-box {
|
| 35 |
+
height: 300px;
|
| 36 |
+
overflow-y: auto;
|
| 37 |
+
padding: 20px; /* Increased padding */
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.user-message,
|
| 41 |
+
.bot-message {
|
| 42 |
+
background-color: #f2f2f2;
|
| 43 |
+
padding: 10px;
|
| 44 |
+
border-radius: 15px;
|
| 45 |
+
margin-bottom: 10px;
|
| 46 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* Add a subtle shadow */
|
| 47 |
}
|
| 48 |
|
| 49 |
+
.chat-message {
|
| 50 |
+
margin-bottom: 20px; /* Increased margin */
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.user-message {
|
| 54 |
+
text-align: right;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.bot-message {
|
| 58 |
+
text-align: left;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
.input-container {
|
| 62 |
+
display: flex;
|
| 63 |
+
align-items: center; /* Center vertically */
|
| 64 |
+
padding: 20px; /* Increased padding */
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
#user-input {
|
| 68 |
+
flex: 1;
|
| 69 |
+
padding: 15px; /* Increased padding */
|
| 70 |
+
margin: 10px; /* Margin added */
|
| 71 |
+
border: none;
|
| 72 |
+
border-radius: 20px;
|
| 73 |
+
background-color: #f2f2f2;
|
| 74 |
+
outline: none;
|
| 75 |
+
width: 100%; /* Ensure input takes up all available space */
|
| 76 |
+
max-width: 70%; /* Limit maximum width to avoid stretching too much */
|
| 77 |
+
}
|
| 78 |
+
#send-btn {
|
| 79 |
+
padding: 15px 25px; /* Increased padding */
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 25px; /* Rounded borders */
|
| 82 |
+
background-color: #4CAF50; /* Green color */
|
| 83 |
+
color: white;
|
| 84 |
+
font-weight: bold;
|
| 85 |
+
cursor: pointer;
|
| 86 |
+
outline: none;
|
| 87 |
+
transition: background-color 0.3s ease; /* Smooth transition effect */
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
#send-btn:hover {
|
| 91 |
+
background-color: #45a049; /* Darker shade on hover */
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
|