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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<!-- Coding By CodingNepal - www.codingnepalweb.com -->
|
3 |
+
<html lang="en" dir="ltr">
|
4 |
+
<head>
|
5 |
+
<meta charset="utf-8">
|
6 |
+
|
7 |
+
|
8 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
9 |
+
<!-- Google Fonts Link For Icons -->
|
10 |
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
|
11 |
+
|
12 |
+
<style>
|
13 |
+
/* Import Google font - Poppins */
|
14 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
|
15 |
+
* {
|
16 |
+
margin: 0;
|
17 |
+
padding: 0;
|
18 |
+
box-sizing: border-box;
|
19 |
+
font-family: "Poppins", sans-serif;
|
20 |
+
}
|
21 |
+
:root {
|
22 |
+
--text-color: #FFFFFF;
|
23 |
+
--icon-color: #ACACBE;
|
24 |
+
--icon-hover-bg: #5b5e71;
|
25 |
+
--placeholder-color: #dcdcdc;
|
26 |
+
--outgoing-chat-bg: #343541;
|
27 |
+
--incoming-chat-bg: #444654;
|
28 |
+
--outgoing-chat-border: #343541;
|
29 |
+
--incoming-chat-border: #444654;
|
30 |
+
}
|
31 |
+
.light-mode {
|
32 |
+
--text-color: #343541;
|
33 |
+
--icon-color: #a9a9bc;
|
34 |
+
--icon-hover-bg: #f1f1f3;
|
35 |
+
--placeholder-color: #6c6c6c;
|
36 |
+
--outgoing-chat-bg: #FFFFFF;
|
37 |
+
--incoming-chat-bg: #F7F7F8;
|
38 |
+
--outgoing-chat-border: #FFFFFF;
|
39 |
+
--incoming-chat-border: #D9D9E3;
|
40 |
+
}
|
41 |
+
body {
|
42 |
+
background: var(--outgoing-chat-bg);
|
43 |
+
}
|
44 |
+
|
45 |
+
/* Chats container styling */
|
46 |
+
.chat-container {
|
47 |
+
overflow-y: auto;
|
48 |
+
max-height: 100vh;
|
49 |
+
padding-bottom: 150px;
|
50 |
+
}
|
51 |
+
:where(.chat-container, textarea)::-webkit-scrollbar {
|
52 |
+
width: 6px;
|
53 |
+
}
|
54 |
+
:where(.chat-container, textarea)::-webkit-scrollbar-track {
|
55 |
+
background: var(--incoming-chat-bg);
|
56 |
+
border-radius: 25px;
|
57 |
+
}
|
58 |
+
:where(.chat-container, textarea)::-webkit-scrollbar-thumb {
|
59 |
+
background: var(--icon-color);
|
60 |
+
border-radius: 25px;
|
61 |
+
}
|
62 |
+
.default-text {
|
63 |
+
display: flex;
|
64 |
+
align-items: center;
|
65 |
+
justify-content: center;
|
66 |
+
flex-direction: column;
|
67 |
+
height: 70vh;
|
68 |
+
padding: 0 10px;
|
69 |
+
text-align: center;
|
70 |
+
color: var(--text-color);
|
71 |
+
}
|
72 |
+
.default-text h1 {
|
73 |
+
font-size: 3.3rem;
|
74 |
+
}
|
75 |
+
.default-text p {
|
76 |
+
margin-top: 10px;
|
77 |
+
font-size: 1.1rem;
|
78 |
+
}
|
79 |
+
.chat-container .chat {
|
80 |
+
padding: 25px 10px;
|
81 |
+
display: flex;
|
82 |
+
justify-content: center;
|
83 |
+
color: var(--text-color);
|
84 |
+
}
|
85 |
+
.chat-container .chat.outgoing {
|
86 |
+
background: var(--outgoing-chat-bg);
|
87 |
+
border: 1px solid var(--outgoing-chat-border);
|
88 |
+
}
|
89 |
+
.chat-container .chat.incoming {
|
90 |
+
background: var(--incoming-chat-bg);
|
91 |
+
border: 1px solid var(--incoming-chat-border);
|
92 |
+
}
|
93 |
+
.chat .chat-content {
|
94 |
+
display: flex;
|
95 |
+
max-width: 1200px;
|
96 |
+
width: 100%;
|
97 |
+
align-items: flex-start;
|
98 |
+
justify-content: space-between;
|
99 |
+
}
|
100 |
+
span.material-symbols-rounded {
|
101 |
+
user-select: none;
|
102 |
+
cursor: pointer;
|
103 |
+
}
|
104 |
+
.chat .chat-content span {
|
105 |
+
cursor: pointer;
|
106 |
+
font-size: 1.3rem;
|
107 |
+
color: var(--icon-color);
|
108 |
+
visibility: hidden;
|
109 |
+
}
|
110 |
+
.chat:hover .chat-content:not(:has(.typing-animation), :has(.error)) span {
|
111 |
+
visibility: visible;
|
112 |
+
}
|
113 |
+
.chat .chat-details {
|
114 |
+
display: flex;
|
115 |
+
align-items: center;
|
116 |
+
}
|
117 |
+
.chat .chat-details img {
|
118 |
+
width: 35px;
|
119 |
+
height: 35px;
|
120 |
+
align-self: flex-start;
|
121 |
+
object-fit: cover;
|
122 |
+
border-radius: 2px;
|
123 |
+
}
|
124 |
+
.chat .chat-details p {
|
125 |
+
white-space: pre-wrap;
|
126 |
+
font-size: 1.05rem;
|
127 |
+
padding: 0 50px 0 25px;
|
128 |
+
color: var(--text-color);
|
129 |
+
word-break: break-word;
|
130 |
+
}
|
131 |
+
.chat .chat-details p.error {
|
132 |
+
color: #e55865;
|
133 |
+
}
|
134 |
+
.chat .typing-animation {
|
135 |
+
padding-left: 25px;
|
136 |
+
display: inline-flex;
|
137 |
+
}
|
138 |
+
.typing-animation .typing-dot {
|
139 |
+
height: 7px;
|
140 |
+
width: 7px;
|
141 |
+
border-radius: 50%;
|
142 |
+
margin: 0 3px;
|
143 |
+
opacity: 0.7;
|
144 |
+
background: var(--text-color);
|
145 |
+
animation: animateDots 1.5s var(--delay) ease-in-out infinite;
|
146 |
+
}
|
147 |
+
.typing-animation .typing-dot:first-child {
|
148 |
+
margin-left: 0;
|
149 |
+
}
|
150 |
+
@keyframes animateDots {
|
151 |
+
0%,44% {
|
152 |
+
transform: translateY(0px);
|
153 |
+
}
|
154 |
+
28% {
|
155 |
+
opacity: 0.4;
|
156 |
+
transform: translateY(-6px);
|
157 |
+
}
|
158 |
+
44% {
|
159 |
+
opacity: 0.2;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
/* Typing container styling */
|
164 |
+
.typing-container {
|
165 |
+
position: fixed;
|
166 |
+
bottom: 0;
|
167 |
+
width: 100%;
|
168 |
+
display: flex;
|
169 |
+
padding: 20px 10px;
|
170 |
+
justify-content: center;
|
171 |
+
background: var(--outgoing-chat-bg);
|
172 |
+
border-top: 1px solid var(--incoming-chat-border);
|
173 |
+
}
|
174 |
+
.typing-container .typing-content {
|
175 |
+
display: flex;
|
176 |
+
max-width: 950px;
|
177 |
+
width: 100%;
|
178 |
+
align-items: flex-end;
|
179 |
+
}
|
180 |
+
.typing-container .typing-textarea {
|
181 |
+
width: 100%;
|
182 |
+
display: flex;
|
183 |
+
position: relative;
|
184 |
+
}
|
185 |
+
.typing-textarea textarea {
|
186 |
+
resize: none;
|
187 |
+
height: 55px;
|
188 |
+
width: 100%;
|
189 |
+
border: none;
|
190 |
+
padding: 15px 45px 15px 20px;
|
191 |
+
color: var(--text-color);
|
192 |
+
font-size: 1rem;
|
193 |
+
border-radius: 4px;
|
194 |
+
max-height: 250px;
|
195 |
+
overflow-y: auto;
|
196 |
+
background: var(--incoming-chat-bg);
|
197 |
+
outline: 1px solid var(--incoming-chat-border);
|
198 |
+
}
|
199 |
+
.typing-textarea textarea::placeholder {
|
200 |
+
color: var(--placeholder-color);
|
201 |
+
}
|
202 |
+
.typing-content span {
|
203 |
+
width: 55px;
|
204 |
+
height: 55px;
|
205 |
+
display: flex;
|
206 |
+
border-radius: 4px;
|
207 |
+
font-size: 1.35rem;
|
208 |
+
align-items: center;
|
209 |
+
justify-content: center;
|
210 |
+
color: var(--icon-color);
|
211 |
+
}
|
212 |
+
.typing-textarea span {
|
213 |
+
position: absolute;
|
214 |
+
right: 0;
|
215 |
+
bottom: 0;
|
216 |
+
visibility: hidden;
|
217 |
+
}
|
218 |
+
.typing-textarea textarea:valid ~ span {
|
219 |
+
visibility: visible;
|
220 |
+
}
|
221 |
+
.typing-controls {
|
222 |
+
display: flex;
|
223 |
+
}
|
224 |
+
.typing-controls span {
|
225 |
+
margin-left: 7px;
|
226 |
+
font-size: 1.4rem;
|
227 |
+
background: var(--incoming-chat-bg);
|
228 |
+
outline: 1px solid var(--incoming-chat-border);
|
229 |
+
}
|
230 |
+
.typing-controls span:hover {
|
231 |
+
background: var(--icon-hover-bg);
|
232 |
+
}
|
233 |
+
|
234 |
+
/* Reponsive Media Query */
|
235 |
+
@media screen and (max-width: 600px) {
|
236 |
+
.default-text h1 {
|
237 |
+
font-size: 2.3rem;
|
238 |
+
}
|
239 |
+
:where(.default-text p, textarea, .chat p) {
|
240 |
+
font-size: 0.95rem!important;
|
241 |
+
}
|
242 |
+
.chat-container .chat {
|
243 |
+
padding: 20px 10px;
|
244 |
+
}
|
245 |
+
.chat-container .chat img {
|
246 |
+
height: 32px;
|
247 |
+
width: 32px;
|
248 |
+
}
|
249 |
+
.chat-container .chat p {
|
250 |
+
padding: 0 20px;
|
251 |
+
}
|
252 |
+
.chat .chat-content:not(:has(.typing-animation), :has(.error)) span {
|
253 |
+
visibility: visible;
|
254 |
+
}
|
255 |
+
.typing-container {
|
256 |
+
padding: 15px 10px;
|
257 |
+
}
|
258 |
+
.typing-textarea textarea {
|
259 |
+
height: 45px;
|
260 |
+
padding: 10px 40px 10px 10px;
|
261 |
+
}
|
262 |
+
.typing-content span {
|
263 |
+
height: 45px;
|
264 |
+
width: 45px;
|
265 |
+
margin-left: 5px;
|
266 |
+
}
|
267 |
+
span.material-symbols-rounded {
|
268 |
+
font-size: 1.25rem!important;
|
269 |
+
}
|
270 |
+
}
|
271 |
+
</style>
|
272 |
+
</head>
|
273 |
+
<body>
|
274 |
+
<!-- Chats container -->
|
275 |
+
<div class="chat-container"></div>
|
276 |
+
|
277 |
+
<!-- Typing container -->
|
278 |
+
<div class="typing-container">
|
279 |
+
<div class="typing-content">
|
280 |
+
<div class="typing-textarea">
|
281 |
+
<textarea id="chat-input" spellcheck="false" placeholder="Enter a prompt here" required></textarea>
|
282 |
+
<span id="send-btn" class="material-symbols-rounded">send</span>
|
283 |
+
</div>
|
284 |
+
<div class="typing-controls">
|
285 |
+
<span id="theme-btn" class="material-symbols-rounded">light_mode</span>
|
286 |
+
<span id="delete-btn" class="material-symbols-rounded">delete</span>
|
287 |
+
</div>
|
288 |
+
</div>
|
289 |
+
<script>
|
290 |
+
// Selecting DOM elements
|
291 |
+
const chatInput = document.querySelector("#chat-input");
|
292 |
+
const sendButton = document.querySelector("#send-btn");
|
293 |
+
const chatContainer = document.querySelector(".chat-container");
|
294 |
+
const themeButton = document.querySelector("#theme-btn");
|
295 |
+
const deleteButton = document.querySelector("#delete-btn");
|
296 |
+
|
297 |
+
// Endpoint for fetching bot responses (replace with your actual endpoint URL)
|
298 |
+
const API_URL = "/generate/";
|
299 |
+
|
300 |
+
// Maintain chat history locally
|
301 |
+
let chatHistory = [];
|
302 |
+
|
303 |
+
// Load data from localStorage on page load
|
304 |
+
const loadDataFromLocalStorage = () => {
|
305 |
+
const themeColor = localStorage.getItem("themeColor");
|
306 |
+
|
307 |
+
document.body.classList.toggle("light-mode", themeColor === "light_mode");
|
308 |
+
themeButton.innerText = document.body.classList.contains("light-mode") ? "dark_mode" : "light_mode";
|
309 |
+
|
310 |
+
chatContainer.innerHTML = localStorage.getItem("all-chats") || '<div class="default-text"><h1>Welcome</h1><p>Start a conversation by typing a message.</p></div>';
|
311 |
+
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
312 |
+
}
|
313 |
+
|
314 |
+
// Function to create a chat message element
|
315 |
+
const createChatElement = (content, className) => {
|
316 |
+
const chatDiv = document.createElement("div");
|
317 |
+
chatDiv.classList.add("chat", className);
|
318 |
+
chatDiv.innerHTML = content;
|
319 |
+
return chatDiv;
|
320 |
+
}
|
321 |
+
|
322 |
+
// Function to fetch bot response from API
|
323 |
+
const getChatResponse = async (message) => {
|
324 |
+
try {
|
325 |
+
const response = await fetch(API_URL, {
|
326 |
+
method: "POST",
|
327 |
+
headers: {
|
328 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
329 |
+
},
|
330 |
+
body: new URLSearchParams({
|
331 |
+
prompt: message,
|
332 |
+
history: "[]",
|
333 |
+
temperature: "0.9",
|
334 |
+
max_new_tokens: "512",
|
335 |
+
top_p: "0.95",
|
336 |
+
repetition_penalty: "1.0"
|
337 |
+
})
|
338 |
+
});
|
339 |
+
|
340 |
+
if (!response.ok) {
|
341 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
342 |
+
}
|
343 |
+
|
344 |
+
const data = await response.json();
|
345 |
+
return data.response;
|
346 |
+
} catch (error) {
|
347 |
+
console.error("Error fetching data:", error);
|
348 |
+
return "Oops! Something went wrong while fetching the response.";
|
349 |
+
}
|
350 |
+
}
|
351 |
+
|
352 |
+
// Function to display user message and bot response
|
353 |
+
const showResponse = async (userMessage) => {
|
354 |
+
const userHtml = `<div class="chat-content">
|
355 |
+
<div class="chat-details">
|
356 |
+
<img src="img/user.jpg">
|
357 |
+
<p>${userMessage}</p>
|
358 |
+
</div>
|
359 |
+
</div>`;
|
360 |
+
|
361 |
+
const outgoingChatDiv = createChatElement(userHtml, "outgoing");
|
362 |
+
chatContainer.querySelector(".default-text")?.remove();
|
363 |
+
chatContainer.appendChild(outgoingChatDiv);
|
364 |
+
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
365 |
+
|
366 |
+
const botResponse = await getChatResponse(userMessage);
|
367 |
+
|
368 |
+
const botHtml = `<div class="chat-content">
|
369 |
+
<div class="chat-details">
|
370 |
+
<img src="img/chatbot.jpg">
|
371 |
+
<p>${botResponse}</p>
|
372 |
+
</div>
|
373 |
+
</div>`;
|
374 |
+
|
375 |
+
const incomingChatDiv = createChatElement(botHtml, "incoming");
|
376 |
+
chatContainer.appendChild(incomingChatDiv);
|
377 |
+
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
378 |
+
|
379 |
+
// Update chat history
|
380 |
+
chatHistory.push([userMessage, botResponse]);
|
381 |
+
localStorage.setItem("all-chats", chatContainer.innerHTML);
|
382 |
+
}
|
383 |
+
|
384 |
+
// Event listener for sending messages
|
385 |
+
const handleOutgoingChat = () => {
|
386 |
+
const userMessage = chatInput.value.trim();
|
387 |
+
if (!userMessage) return;
|
388 |
+
|
389 |
+
chatInput.value = "";
|
390 |
+
chatInput.style.height = `${initialInputHeight}px`;
|
391 |
+
|
392 |
+
showResponse(userMessage);
|
393 |
+
}
|
394 |
+
|
395 |
+
// Event listeners
|
396 |
+
sendButton.addEventListener("click", handleOutgoingChat);
|
397 |
+
|
398 |
+
deleteButton.addEventListener("click", () => {
|
399 |
+
localStorage.removeItem("all-chats");
|
400 |
+
loadDataFromLocalStorage();
|
401 |
+
});
|
402 |
+
themeButton.addEventListener("click", () => {
|
403 |
+
document.body.classList.toggle("light-mode");
|
404 |
+
localStorage.setItem("themeColor", themeButton.innerText);
|
405 |
+
themeButton.innerText = document.body.classList.contains("light-mode") ? "dark_mode" : "light_mode";
|
406 |
+
});
|
407 |
+
|
408 |
+
chatInput.addEventListener("input", () => {
|
409 |
+
chatInput.style.height = `${initialInputHeight}px`;
|
410 |
+
chatInput.style.height = `${chatInput.scrollHeight}px`;
|
411 |
+
});
|
412 |
+
|
413 |
+
chatInput.addEventListener("keydown", (e) => {
|
414 |
+
if (e.key === "Enter" && !e.shiftKey && window.innerWidth > 800) {
|
415 |
+
e.preventDefault();
|
416 |
+
handleOutgoingChat();
|
417 |
+
}
|
418 |
+
});
|
419 |
+
|
420 |
+
// Initial input height calculation
|
421 |
+
const initialInputHeight = chatInput.scrollHeight;
|
422 |
+
|
423 |
+
// Load data from localStorage on page load
|
424 |
+
loadDataFromLocalStorage();
|
425 |
+
|
426 |
+
</script>
|
427 |
+
</body>
|
428 |
+
</html>
|