Ashrafb commited on
Commit
d365f4d
1 Parent(s): 8dc40a8

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +378 -487
static/index.html CHANGED
@@ -1,533 +1,424 @@
1
  <!DOCTYPE html>
2
- <!-- Coding By CodingNepal - www.codingnepalweb.com -->
3
  <html lang="en" dir="ltr">
4
- <head>
5
- <meta charset="utf-8">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <!-- Google Fonts Link For Icons -->
8
- <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" />
9
- <style>
10
- /* Import Google font - Poppins */
11
- @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
12
- * {
13
- margin: 0;
14
- padding: 0;
15
- box-sizing: border-box;
16
- font-family: "Poppins", sans-serif;
17
- }
18
- :root {
19
- --text-color: #FFFFFF;
20
- --icon-color: #ACACBE;
21
- --icon-hover-bg: #5b5e71;
22
- --placeholder-color: #dcdcdc;
23
- --outgoing-chat-bg: #343541;
24
- --incoming-chat-bg: #444654;
25
- --outgoing-chat-border: #343541;
26
- --incoming-chat-border: #444654;
27
- }
28
- .light-mode {
29
- --text-color: #343541;
30
- --icon-color: #a9a9bc;
31
- --icon-hover-bg: #f1f1f3;
32
- --placeholder-color: #6c6c6c;
33
- --outgoing-chat-bg: #FFFFFF;
34
- --incoming-chat-bg: #F7F7F8;
35
- --outgoing-chat-border: #FFFFFF;
36
- --incoming-chat-border: #D9D9E3;
37
- }
38
- body {
39
- background: var(--outgoing-chat-bg);
40
- }
41
-
42
- /* Chats container styling */
43
- .chat-container {
44
- overflow-y: auto;
45
- max-height: 100vh;
46
- padding-bottom: 150px;
47
- }
48
- :where(.chat-container, textarea)::-webkit-scrollbar {
49
- width: 6px;
50
- }
51
- :where(.chat-container, textarea)::-webkit-scrollbar-track {
52
- background: var(--incoming-chat-bg);
53
- border-radius: 25px;
54
- }
55
- :where(.chat-container, textarea)::-webkit-scrollbar-thumb {
56
- background: var(--icon-color);
57
- border-radius: 25px;
58
- }
59
- .default-text {
60
- display: flex;
61
- align-items: center;
62
- justify-content: center;
63
- flex-direction: column;
64
- height: 70vh;
65
- padding: 0 10px;
66
- text-align: center;
67
- color: var(--text-color);
68
- }
69
- .default-text h1 {
70
- font-size: 3.3rem;
71
- }
72
- .default-text p {
73
- margin-top: 10px;
74
- font-size: 1.1rem;
75
- }
76
- .chat-container .chat {
77
- padding: 25px 10px;
78
- display: flex;
79
- justify-content: center;
80
- color: var(--text-color);
81
- }
82
- .chat-container .chat.outgoing {
83
- background: var(--outgoing-chat-bg);
84
- border: 1px solid var(--outgoing-chat-border);
85
- }
86
- .chat-container .chat.incoming {
87
- background: var(--incoming-chat-bg);
88
- border: 1px solid var(--incoming-chat-border);
89
- }
90
- .chat .chat-content {
91
- display: flex;
92
- max-width: 1200px;
93
- width: 100%;
94
- align-items: flex-start;
95
- justify-content: space-between;
96
- }
97
- span.material-symbols-rounded {
98
- user-select: none;
99
- cursor: pointer;
100
- }
101
- .chat .chat-content span {
102
- cursor: pointer;
103
- font-size: 1.3rem;
104
- color: var(--icon-color);
105
- visibility: hidden;
106
- }
107
- .chat:hover .chat-content:not(:has(.typing-animation), :has(.error)) span {
108
- visibility: visible;
109
- }
110
- .chat .chat-details {
111
- display: flex;
112
- align-items: center;
113
- }
114
- .chat .chat-details img {
115
- width: 35px;
116
- height: 35px;
117
- align-self: flex-start;
118
- object-fit: cover;
119
- border-radius: 2px;
120
- }
121
- .chat .chat-details p {
122
- white-space: pre-wrap;
123
- font-size: 1.05rem;
124
- padding: 0 50px 0 25px;
125
- color: var(--text-color);
126
- word-break: break-word;
127
- }
128
- .chat .chat-details p.error {
129
- color: #e55865;
130
- }
131
- .chat .typing-animation {
132
- padding-left: 25px;
133
- display: inline-flex;
134
- }
135
- .typing-animation .typing-dot {
136
- height: 7px;
137
- width: 7px;
138
- border-radius: 50%;
139
- margin: 0 3px;
140
- opacity: 0.7;
141
- background: var(--text-color);
142
- animation: animateDots 1.5s var(--delay) ease-in-out infinite;
143
- }
144
- .typing-animation .typing-dot:first-child {
145
- margin-left: 0;
146
- }
147
- @keyframes animateDots {
148
- 0%,
149
- 44% {
150
- transform: translateY(0px);
151
- }
152
- 28% {
153
- opacity: 0.4;
154
- transform: translateY(-6px);
155
- }
156
- 44% {
157
- opacity: 0.2;
158
- }
159
- }
160
-
161
- /* Typing container styling */
162
- .typing-container {
163
- position: fixed;
164
- bottom: 0;
165
- width: 100%;
166
- display: flex;
167
- padding: 20px 10px;
168
- justify-content: center;
169
- background: var(--outgoing-chat-bg);
170
- border-top: 1px solid var(--incoming-chat-border);
171
- }
172
- .typing-container .typing-content {
173
- display: flex;
174
- max-width: 950px;
175
- width: 100%;
176
- align-items: flex-end;
177
- }
178
- .typing-container .typing-textarea {
179
- width: 100%;
180
- display: flex;
181
- position: relative;
182
- }
183
- .typing-textarea textarea {
184
- resize: none;
185
- height: 55px;
186
- width: 100%;
187
- border: none;
188
- padding: 15px 45px 15px 20px;
189
- color: var(--text-color);
190
- font-size: 1rem;
191
- border-radius: 4px;
192
- max-height: 250px;
193
- overflow-y: auto;
194
- background: var(--incoming-chat-bg);
195
- outline: 1px solid var(--incoming-chat-border);
196
- }
197
- .typing-textarea textarea::placeholder {
198
- color: var(--placeholder-color);
199
- }
200
- .typing-content span {
201
- width: 55px;
202
- height: 55px;
203
- display: flex;
204
- border-radius: 4px;
205
- font-size: 1.35rem;
206
- align-items: center;
207
- justify-content: center;
208
- color: var(--icon-color);
209
- }
210
- .typing-textarea span {
211
- position: absolute;
212
- right: 0;
213
- bottom: 0;
214
- visibility: hidden;
215
- }
216
- .typing-textarea textarea:valid ~ span {
217
- visibility: visible;
218
- }
219
- .typing-controls {
220
- display: flex;
221
- }
222
- .typing-controls span {
223
- margin-left: 7px;
224
- font-size: 1.4rem;
225
- background: var(--incoming-chat-bg);
226
- outline: 1px solid var(--incoming-chat-border);
227
- }
228
- .typing-controls span:hover {
229
- background: var(--icon-hover-bg);
230
- }
231
-
232
- /* Reponsive Media Query */
233
- @media screen and (max-width: 600px) {
234
- .default-text h1 {
235
- font-size: 2.3rem;
236
- }
237
- :where(.default-text p, textarea, .chat p) {
238
- font-size: 0.95rem!important;
239
- }
240
- .chat-container .chat {
241
- padding: 20px 10px;
242
- }
243
- .chat-container .chat img {
244
- height: 32px;
245
- width: 32px;
246
- }
247
- .chat-container .chat p {
248
- padding: 0 20px;
249
- }
250
- .chat .chat-content:not(:has(.typing-animation), :has(.error)) span {
251
- visibility: visible;
252
- }
253
- .typing-container {
254
- padding: 15px 10px;
255
- }
256
- .typing-textarea textarea {
257
- height: 45px;
258
- padding: 10px 40px 10px 10px;
259
- }
260
- .typing-content span {
261
- height: 45px;
262
- width: 45px;
263
- margin-left: 5px;
264
- }
265
- span.material-symbols-rounded {
266
- font-size: 1.25rem!important;
267
- }
268
- }
269
- /* New CSS style for "Text Copied" message */
270
- .copied-message {
271
- font-size: 0.5rem;
272
- }
273
- .message-box {
274
- height: calc(50vh - 5rem);
275
  overflow-y: auto;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  }
277
-
278
- .messagebar {
 
 
 
 
279
  position: fixed;
280
  bottom: 0;
281
- height: 5rem;
282
  width: 100%;
283
  display: flex;
284
- align-items: center;
285
  justify-content: center;
286
- border-top: 1px solid #494b59;
287
- background-color: #33343f;
288
  }
289
- .messagebar .bar-wrapper {
290
- background-color: #494b59;
291
- border-radius: 5px;
292
- width: 60vw;
293
- padding: 10px;
294
  display: flex;
295
- align-items: center;
296
- justify-content: space-between;
 
 
 
 
 
 
297
  }
298
- .bar-wrapper input {
 
 
299
  width: 100%;
300
- padding: 5px;
301
  border: none;
302
- outline: none;
303
- font-size: 14px;
304
- background: none;
305
- color: #ccc;
 
 
 
 
306
  }
307
- .bar-wrapper input::placeholder {
308
- color: #ccc;
309
  }
310
- .messagebar button {
 
 
311
  display: flex;
 
 
312
  align-items: center;
313
  justify-content: center;
314
- background: none;
315
- border: none;
316
- color: #fff;
317
- cursor: pointer;
318
  }
319
- .message-box {
320
- height: calc(100vh - 5rem);
321
- overflow-y: auto;
 
 
 
 
 
322
  }
323
- .chat {
324
  display: flex;
325
- gap: 20px;
326
- padding: 25px;
327
- color: #fff;
328
- font-size: 15px;
329
- font-weight: 300;
330
  }
331
- .chat img {
332
- width: 35px;
333
- height: 35px;
 
 
 
 
 
334
  }
335
- .response {
336
- background-color: #494b59;
 
 
337
  }
338
- .chatbox-wrapper {
339
- margin-bottom: 0;
340
- }
341
- .copied-text {
342
- font-size: 0.4rem; /* Adjust this size as needed */
343
- }
344
-
345
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  </style>
347
  </head>
348
  <body>
349
- <div class="chatbox-wrapper">
350
- <div class="message-box">
351
- <div class="chat response">
352
- <img src="img/chatbot.jpg">
353
- <span>Hello there! <br> How can I help you today.</span>
 
 
 
 
 
 
 
 
 
354
  </div>
355
-
356
- <!-- Chats container -->
357
- <div class="chat-container"></div>
358
-
359
- <!-- Typing container -->
360
- <div class="typing-container">
361
- <div class="typing-content">
362
- <div class="typing-textarea">
363
- <textarea id="chat-input" spellcheck="false" placeholder="Enter a prompt here" required></textarea>
364
- <span id="send-btn" class="material-symbols-rounded">send</span>
365
- </div>
366
- <div class="typing-controls">
367
- <span id="theme-btn" class="material-symbols-rounded">light_mode</span>
368
- <span id="delete-btn" class="material-symbols-rounded">delete</span>
369
-
370
- </div>
371
  </div>
372
  </div>
373
  </div>
374
- <script>
375
- // Selecting DOM elements
376
- const chatInput = document.querySelector("#chat-input");
377
- const sendButton = document.querySelector("#send-btn");
378
- const chatContainer = document.querySelector(".chat-container");
379
- const themeButton = document.querySelector("#theme-btn");
380
- const deleteButton = document.querySelector("#delete-btn");
381
- const copyButton = document.querySelector("#copy-btn");
382
-
383
- // Endpoint for fetching bot responses (replace with your actual endpoint URL)
384
- const API_URL = "/generate/";
385
-
386
- // Maintain chat history locally
387
- let chatHistory = [];
388
-
389
- // Load data from localStorage on page load
390
- const loadDataFromLocalStorage = () => {
391
- const themeColor = localStorage.getItem("themeColor");
392
-
393
- document.body.classList.toggle("light-mode", themeColor === "light_mode");
394
- themeButton.innerText = document.body.classList.contains("light-mode") ? "dark_mode" : "light_mode";
395
-
396
- chatContainer.innerHTML = localStorage.getItem("all-chats") || '<div class="default-text"><h1>Welcome</h1><p>Start a conversation by typing a message.</p></div>';
397
- chatContainer.scrollTo(0, chatContainer.scrollHeight);
398
- }
399
-
400
- // Function to create a chat message element
401
- const createChatElement = (content, className) => {
402
- const chatDiv = document.createElement("div");
403
- chatDiv.classList.add("chat", className);
404
- chatDiv.innerHTML = content;
405
- return chatDiv;
406
- }
407
-
408
- // Function to fetch bot response from API
409
- const getChatResponse = async (message) => {
410
- try {
411
- const response = await fetch(API_URL, {
412
- method: "POST",
413
- headers: {
414
- "Content-Type": "application/x-www-form-urlencoded"
415
- },
416
- body: new URLSearchParams({
417
- prompt: message,
418
- history: "[]",
419
- temperature: "0.9",
420
- max_new_tokens: "512",
421
- top_p: "0.95",
422
- repetition_penalty: "1.0"
423
- })
424
- });
425
-
426
- if (!response.ok) {
427
- throw new Error(`HTTP error! Status: ${response.status}`);
428
- }
429
-
430
- const data = await response.json();
431
- return data.response;
432
- } catch (error) {
433
- console.error("Error fetching data:", error);
434
- return "Oops! Something went wrong while fetching the response.";
435
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  }
437
 
438
- // Function to display user message and bot response
439
- const showResponse = async (userMessage) => {
440
- const userHtml = `<div class="chat-content">
441
- <div class="chat-details">
442
- <img src="img/user.jpg">
443
- <p>${userMessage}</p>
444
- </div>
445
- </div>`;
446
 
447
- const outgoingChatDiv = createChatElement(userHtml, "outgoing");
448
- chatContainer.querySelector(".default-text")?.remove();
449
- chatContainer.appendChild(outgoingChatDiv);
450
- chatContainer.scrollTo(0, chatContainer.scrollHeight);
451
 
452
- const botResponse = await getChatResponse(userMessage);
 
 
453
 
454
- const botHtml = `<div class="chat-content">
455
- <div class="chat-details">
456
- <img src="img/chatbot.jpg"><span class="new">...</span>
457
- <p contenteditable="false" class="copy-text">${botResponse}</p>
458
- </div>
459
- <span class="material-symbols-rounded copy-icon">content_copy</span>
460
- </div>`;
461
 
462
- const incomingChatDiv = createChatElement(botHtml, "incoming");
463
- chatContainer.appendChild(incomingChatDiv);
464
- chatContainer.scrollTo(0, chatContainer.scrollHeight);
465
 
466
- // Update chat history
467
- chatHistory.push([userMessage, botResponse]);
468
- localStorage.setItem("all-chats", chatContainer.innerHTML);
469
 
470
- // Copy to clipboard functionality
471
- const copyIcons = document.querySelectorAll(".copy-icon");
472
- copyIcons.forEach(copyIcon => {
473
- copyIcon.addEventListener("click", () => {
474
- const textToCopy = copyIcon.previousElementSibling.textContent;
475
- navigator.clipboard.writeText(textToCopy);
476
- copyIcon.textContent = "Copied";
477
- copyIcon.classList.add("copied-text"); // Add the class for smaller text
478
-
479
- setTimeout(() => {
480
- copyIcon.textContent = "content_copy";
481
- }, 1000);
482
- });
483
- });
484
- }
485
 
486
- // Event listener for sending messages
487
- const handleOutgoingChat = () => {
488
- const userMessage = chatInput.value.trim();
489
- if (!userMessage) return;
490
 
491
- chatInput.value = "";
492
- chatInput.style.height = `${initialInputHeight}px`;
 
 
493
 
494
- showResponse(userMessage);
 
 
 
495
  }
 
496
 
497
- // Event listeners
498
- sendButton.addEventListener("click", handleOutgoingChat);
499
-
500
- deleteButton.addEventListener("click", () => {
501
- localStorage.removeItem("all-chats");
502
- loadDataFromLocalStorage();
503
- });
504
-
505
- themeButton.addEventListener("click", () => {
506
- document.body.classList.toggle("light-mode");
507
- localStorage.setItem("themeColor", themeButton.innerText);
508
- themeButton.innerText = document.body.classList.contains("light-mode") ? "dark_mode" : "light_mode";
509
- });
510
-
511
- // Initial input height calculation
512
- const initialInputHeight = chatInput.scrollHeight;
513
-
514
- chatInput.addEventListener("input", () => {
515
- chatInput.style.height = `${initialInputHeight}px`;
516
- chatInput.style.height = `${chatInput.scrollHeight}px`;
517
- });
518
-
519
- chatInput.addEventListener("keydown", (e) => {
520
- if (e.key === "Enter" && !e.shiftKey && window.innerWidth > 800) {
521
- e.preventDefault();
522
- handleOutgoingChat();
523
- }
524
- });
525
-
526
- // Load data from localStorage on page load
527
- loadDataFromLocalStorage();
528
- </script>
529
- </body>
530
  </html>
531
-
532
-
533
-
 
1
  <!DOCTYPE html>
 
2
  <html lang="en" dir="ltr">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <!-- Google Fonts Link For Icons -->
7
+ <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" />
8
+ <style>
9
+ /* Import Google font - Poppins */
10
+ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
11
+ * {
12
+ margin: 0;
13
+ padding: 0;
14
+ box-sizing: border-box;
15
+ font-family: "Poppins", sans-serif;
16
+ }
17
+ :root {
18
+ --text-color: #FFFFFF;
19
+ --icon-color: #ACACBE;
20
+ --icon-hover-bg: #5b5e71;
21
+ --placeholder-color: #dcdcdc;
22
+ --outgoing-chat-bg: #343541;
23
+ --incoming-chat-bg: #444654;
24
+ --outgoing-chat-border: #343541;
25
+ --incoming-chat-border: #444654;
26
+ }
27
+ .light-mode {
28
+ --text-color: #343541;
29
+ --icon-color: #a9a9bc;
30
+ --icon-hover-bg: #f1f1f3;
31
+ --placeholder-color: #6c6c6c;
32
+ --outgoing-chat-bg: #FFFFFF;
33
+ --incoming-chat-bg: #F7F7F8;
34
+ --outgoing-chat-border: #FFFFFF;
35
+ --incoming-chat-border: #D9D9E3;
36
+ }
37
+ body {
38
+ background: var(--outgoing-chat-bg);
39
+ }
40
+ .top-bar {
41
+ background: var(--outgoing-chat-bg);
42
+ border-bottom: 1px solid var(--incoming-chat-border);
43
+ padding: 10px;
44
+ text-align: center;
45
+ color: var(--text-color);
46
+ }
47
+ /* Chats container styling */
48
+ .chat-container {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  overflow-y: auto;
50
+ max-height: 100vh;
51
+ padding-bottom: 150px;
52
+ }
53
+ :where(.chat-container, textarea)::-webkit-scrollbar {
54
+ width: 6px;
55
+ }
56
+ :where(.chat-container, textarea)::-webkit-scrollbar-track {
57
+ background: var(--incoming-chat-bg);
58
+ border-radius: 25px;
59
+ }
60
+ :where(.chat-container, textarea)::-webkit-scrollbar-thumb {
61
+ background: var(--icon-color);
62
+ border-radius: 25px;
63
+ }
64
+ .default-text {
65
+ display: flex;
66
+ align-items: center;
67
+ justify-content: center;
68
+ flex-direction: column;
69
+ height: 70vh;
70
+ padding: 0 10px;
71
+ text-align: center;
72
+ color: var(--text-color);
73
+ }
74
+ .default-text h1 {
75
+ font-size: 3.3rem;
76
+ }
77
+ .default-text p {
78
+ margin-top: 10px;
79
+ font-size: 1.1rem;
80
+ }
81
+ .chat-container .chat {
82
+ padding: 25px 10px;
83
+ display: flex;
84
+ justify-content: center;
85
+ color: var(--text-color);
86
+ position: relative;
87
+ }
88
+ .chat-container .chat.outgoing {
89
+ background: var(--outgoing-chat-bg);
90
+ border: 1px solid var(--outgoing-chat-border);
91
+ }
92
+ .chat-container .chat.incoming {
93
+ background: var(--incoming-chat-bg);
94
+ border: 1px solid var(--incoming-chat-border);
95
+ }
96
+ .chat .chat-content {
97
+ display: flex;
98
+ max-width: 1200px;
99
+ width: 100%;
100
+ align-items: flex-start;
101
+ justify-content: space-between;
102
+ }
103
+ span.material-symbols-rounded {
104
+ user-select: none;
105
+ cursor: pointer;
106
+ }
107
+ .chat .chat-content span {
108
+ cursor: pointer;
109
+ font-size: 1.3rem;
110
+ color: var(--icon-color);
111
+ visibility: hidden;
112
+ }
113
+ .chat:hover .chat-content:not(:has(.typing-animation), :has(.error)) span {
114
+ visibility: visible;
115
+ }
116
+ .chat .chat-details {
117
+ display: flex;
118
+ align-items: center;
119
+ }
120
+ .chat .chat-details img {
121
+ width: 35px;
122
+ height: 35px;
123
+ align-self: flex-start;
124
+ object-fit: cover;
125
+ border-radius: 2px;
126
+ }
127
+ .chat .chat-details p {
128
+ white-space: pre-wrap;
129
+ font-size: 1.05rem;
130
+ padding: 0 50px 0 25px;
131
+ color: var(--text-color);
132
+ word-break: break-word;
133
+ }
134
+ .chat .chat-details p.error {
135
+ color: #e55865;
136
+ }
137
+ .chat .typing-animation {
138
+ padding-left: 25px;
139
+ display: inline-flex;
140
+ }
141
+ .typing-animation .typing-dot {
142
+ height: 7px;
143
+ width: 7px;
144
+ border-radius: 50%;
145
+ margin: 0 3px;
146
+ opacity: 0.7;
147
+ background: var(--text-color);
148
+ animation: animateDots 1.5s var(--delay) ease-in-out infinite;
149
+ }
150
+ .typing-animation .typing-dot:first-child {
151
+ margin-left: 0;
152
+ }
153
+ @keyframes animateDots {
154
+ 0%,
155
+ 44% {
156
+ transform: translateY(0px);
157
+ }
158
+ 28% {
159
+ opacity: 0.4;
160
+ transform: translateY(-6px);
161
  }
162
+ 44% {
163
+ opacity: 0.2;
164
+ }
165
+ }
166
+ /* Typing container styling */
167
+ .typing-container {
168
  position: fixed;
169
  bottom: 0;
 
170
  width: 100%;
171
  display: flex;
172
+ padding: 20px 10px;
173
  justify-content: center;
174
+ background: var(--outgoing-chat-bg);
175
+ border-top: 1px solid var(--incoming-chat-border);
176
  }
177
+ .typing-container .typing-content {
 
 
 
 
178
  display: flex;
179
+ max-width: 950px;
180
+ width: 100%;
181
+ align-items: flex-end;
182
+ }
183
+ .typing-container .typing-textarea {
184
+ width: 100%;
185
+ display: flex;
186
+ position: relative;
187
  }
188
+ .typing-textarea textarea {
189
+ resize: none;
190
+ height: 55px;
191
  width: 100%;
 
192
  border: none;
193
+ padding: 15px 45px 15px 20px;
194
+ color: var(--text-color);
195
+ font-size: 1rem;
196
+ border-radius: 4px;
197
+ max-height: 250px;
198
+ overflow-y: auto;
199
+ background: var(--incoming-chat-bg);
200
+ outline: 1px solid var(--incoming-chat-border);
201
  }
202
+ .typing-textarea textarea::placeholder {
203
+ color: var(--placeholder-color);
204
  }
205
+ .typing-content span {
206
+ width: 55px;
207
+ height: 55px;
208
  display: flex;
209
+ border-radius: 4px;
210
+ font-size: 1.35rem;
211
  align-items: center;
212
  justify-content: center;
213
+ color: var(--icon-color);
 
 
 
214
  }
215
+ .typing-textarea span {
216
+ position: absolute;
217
+ right: 0;
218
+ bottom: 0;
219
+ visibility: hidden;
220
+ }
221
+ .typing-textarea textarea:valid ~ span {
222
+ visibility: visible;
223
  }
224
+ .typing-controls {
225
  display: flex;
 
 
 
 
 
226
  }
227
+ .typing-controls span {
228
+ margin-left: 7px;
229
+ font-size: 1.4rem;
230
+ background: var(--incoming-chat-bg);
231
+ outline: 1px solid var(--incoming-chat-border);
232
+ }
233
+ .typing-controls span:hover {
234
+ background: var(--icon-hover-bg);
235
  }
236
+ /* Reponsive Media Query */
237
+ @media screen and (max-width: 600px) {
238
+ .default-text h1 {
239
+ font-size: 2.3rem;
240
  }
241
+ :where(.default-text p, textarea, .chat p) {
242
+ font-size: 0.95rem!important;
243
+ }
244
+ .chat-container .chat {
245
+ padding: 20px 10px;
246
+ }
247
+ .chat-container .chat img {
248
+ height: 32px;
249
+ width: 32px;
250
+ }
251
+ .chat-container .chat p {
252
+ padding: 0 20px;
253
+ }
254
+ .chat .chat-content:not(:has(.typing-animation), :has(.error)) span {
255
+ visibility: visible;
256
+ }
257
+ .typing-container {
258
+ padding: 15px 10px;
259
+ }
260
+ .typing-container .typing-content {
261
+ max-width: 100%;
262
+ }
263
+ .typing-controls span {
264
+ margin-left: 5px;
265
+ font-size: 1.2rem;
266
+ }
267
+ .typing-textarea textarea {
268
+ padding: 14px 45px 14px 15px;
269
+ font-size: 0.95rem;
270
+ }
271
+ }
272
  </style>
273
  </head>
274
  <body>
275
+ <div class="top-bar">
276
+ <h1>Chat Application</h1>
277
+ </div>
278
+ <div class="chat-container">
279
+ <div class="default-text">
280
+ <h1>ChatGPT</h1>
281
+ <p>Start a conversation with the AI assistant.</p>
282
+ </div>
283
+ </div>
284
+ <div class="typing-container">
285
+ <div class="typing-content">
286
+ <div class="typing-textarea">
287
+ <textarea spellcheck="false" placeholder="Type your message.."></textarea>
288
+ <span class="material-symbols-rounded">send</span>
289
  </div>
290
+ <div class="typing-controls">
291
+ <span class="material-symbols-rounded">dark_mode</span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  </div>
293
  </div>
294
  </div>
295
+ <script>
296
+ const textarea = document.querySelector("textarea"),
297
+ chatContainer = document.querySelector(".chat-container"),
298
+ sendChatBtn = document.querySelector("span.material-symbols-rounded"),
299
+ toggleIcon = document.querySelector(".typing-controls span"),
300
+ defaultText = document.querySelector(".default-text");
301
+
302
+ let userMessage = null;
303
+
304
+ toggleIcon.onclick = () => {
305
+ document.body.classList.toggle("light-mode");
306
+ };
307
+
308
+ const createTypingAnimation = () => {
309
+ const html = `
310
+ <div class="chat-content">
311
+ <div class="chat-details">
312
+ <img src="bot.png" alt="">
313
+ <div class="typing-animation">
314
+ <div class="typing-dot" style="--delay: 0s"></div>
315
+ <div class="typing-dot" style="--delay: 0.15s"></div>
316
+ <div class="typing-dot" style="--delay: 0.3s"></div>
317
+ </div>
318
+ </div>
319
+ </div>`;
320
+ const incomingChat = document.createElement("div");
321
+ incomingChat.classList.add("chat", "incoming");
322
+ incomingChat.innerHTML = html;
323
+ return incomingChat;
324
+ };
325
+
326
+ const generateResponse = (chatElement) => {
327
+ const API_URL = "https://api.openai.com/v1/engines/davinci-codex/completions";
328
+ const API_KEY = "YOUR_OPENAI_API_KEY";
329
+
330
+ const requestOptions = {
331
+ method: "POST",
332
+ headers: {
333
+ "Content-Type": "application/json",
334
+ "Authorization": `Bearer ${API_KEY}`
335
+ },
336
+ body: JSON.stringify({
337
+ prompt: userMessage,
338
+ max_tokens: 1000
339
+ })
340
+ };
341
+
342
+ fetch(API_URL, requestOptions).then(res => res.json()).then(data => {
343
+ chatElement.querySelector(".typing-animation").remove();
344
+ const pElement = document.createElement("p");
345
+ pElement.textContent = data.choices[0].text.trim();
346
+ chatElement.querySelector(".chat-details").appendChild(pElement);
347
+ }).catch(() => {
348
+ chatElement.querySelector(".typing-animation").remove();
349
+ const pElement = document.createElement("p");
350
+ pElement.classList.add("error");
351
+ pElement.textContent = "Oops! Something went wrong. Please try again.";
352
+ chatElement.querySelector(".chat-details").appendChild(pElement);
353
+ }).finally(() => chatContainer.scrollTo(0, chatContainer.scrollHeight));
354
+ };
355
+
356
+ const copyMessage = (element) => {
357
+ navigator.clipboard.writeText(element.innerText);
358
+ };
359
+
360
+ const createChatElement = (message, className) => {
361
+ const chatElement = document.createElement("div");
362
+ chatElement.classList.add("chat", className);
363
+
364
+ const html = `
365
+ <div class="chat-content">
366
+ <div class="chat-details">
367
+ <img src="${className === "outgoing" ? "user.png" : "bot.png"}" alt="">
368
+ <p>${message}</p>
369
+ </div>
370
+ <span class="material-symbols-rounded">content_copy</span>
371
+ ${className === "outgoing" ? '<span class="material-symbols-rounded">edit</span>' : ''}
372
+ </div>`;
373
+ chatElement.innerHTML = html;
374
+
375
+ if (className === "outgoing") {
376
+ const editIcon = chatElement.querySelector(".material-symbols-rounded:nth-child(3)");
377
+ editIcon.addEventListener("click", () => {
378
+ textarea.value = message;
379
+ chatElement.remove();
380
+ textarea.focus();
381
+ });
382
  }
383
 
384
+ const copyIcon = chatElement.querySelector(".material-symbols-rounded:nth-child(2)");
385
+ copyIcon.addEventListener("click", () => copyMessage(chatElement.querySelector("p")));
 
 
 
 
 
 
386
 
387
+ return chatElement;
388
+ };
 
 
389
 
390
+ const handleChat = () => {
391
+ userMessage = textarea.value.trim();
392
+ if (!userMessage) return;
393
 
394
+ textarea.value = "";
395
+ textarea.style.height = `${textarea.scrollHeight}px`;
 
 
 
 
 
396
 
397
+ if (!chatContainer.querySelector(".chat")) defaultText.style.display = "none";
 
 
398
 
399
+ chatContainer.appendChild(createChatElement(userMessage, "outgoing"));
400
+ chatContainer.scrollTo(0, chatContainer.scrollHeight);
 
401
 
402
+ const incomingChat = createTypingAnimation();
403
+ chatContainer.appendChild(incomingChat);
404
+ chatContainer.scrollTo(0, chatContainer.scrollHeight);
 
 
 
 
 
 
 
 
 
 
 
 
405
 
406
+ generateResponse(incomingChat);
407
+ };
 
 
408
 
409
+ textarea.addEventListener("input", () => {
410
+ textarea.style.height = "auto";
411
+ textarea.style.height = `${textarea.scrollHeight}px`;
412
+ });
413
 
414
+ textarea.addEventListener("keydown", (e) => {
415
+ if (e.key === "Enter" && !e.shiftKey) {
416
+ e.preventDefault();
417
+ handleChat();
418
  }
419
+ });
420
 
421
+ sendChatBtn.addEventListener("click", handleChat);
422
+ </script>
423
+ </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
  </html>