Spaces:
Sleeping
Sleeping
update
Browse files- templates/chat.html +51 -36
templates/chat.html
CHANGED
@@ -162,7 +162,7 @@
|
|
162 |
<span class="msg_time_send">${str_time}</span>
|
163 |
</div>
|
164 |
<div class="img_cont_msg">
|
165 |
-
<img src="/static/
|
166 |
</div>
|
167 |
</div>`;
|
168 |
|
@@ -204,32 +204,48 @@
|
|
204 |
type: "POST",
|
205 |
url: "/get",
|
206 |
}).done(function (response) {
|
207 |
-
// --- Typewriter effect for bot response START ---
|
208 |
-
// Create the container for the bot message
|
209 |
let botContainer = $(`
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
$("#messageFormeight").append(botContainer);
|
217 |
|
218 |
let msgDiv = botContainer.find(".msg_container");
|
219 |
let i = 0;
|
|
|
220 |
function typeWriterInner() {
|
221 |
if (i < response.length) {
|
222 |
-
|
223 |
-
i
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
} else {
|
226 |
msgDiv.append(`<span class="msg_time">${time}</span>`);
|
227 |
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
228 |
}
|
229 |
}
|
230 |
typeWriterInner();
|
231 |
-
// --- Typewriter effect for bot response END ---
|
232 |
});
|
|
|
233 |
});
|
234 |
|
235 |
// Clear chat history
|
@@ -243,39 +259,48 @@
|
|
243 |
|
244 |
// Send the message to the server via AJAX
|
245 |
$.ajax({
|
246 |
-
data: {
|
247 |
-
msg: rawText,
|
248 |
-
},
|
249 |
type: "POST",
|
250 |
url: "/get",
|
251 |
}).done(function(data) {
|
252 |
-
// --- Typewriter effect for bot response START ---
|
253 |
var lines = data.split("**");
|
254 |
var fullText = lines.join(' ');
|
|
|
255 |
// Create the container for the bot message
|
256 |
var botContainer = $('<div class="d-flex justify-content-start mb-4"></div>');
|
257 |
var imgDiv = $('<div class="img_cont_msg"><img src="/static/juitlogo.png" class="rounded-circle user_img_msg"></div>');
|
258 |
var msgDiv = $('<div class="msg_container"></div>');
|
259 |
-
botContainer.append(imgDiv);
|
260 |
-
botContainer.append(msgDiv);
|
261 |
$("#messageFormeight").append(botContainer);
|
262 |
-
|
263 |
var i = 0;
|
264 |
function typeWriter() {
|
265 |
if (i < fullText.length) {
|
266 |
-
|
267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
setTimeout(typeWriter, 30); // Adjust delay as needed
|
269 |
} else {
|
270 |
msgDiv.append('<span class="msg_time">' + str_time + '</span>');
|
271 |
-
|
272 |
-
var container = $("#messageFormeight");
|
273 |
-
container.animate({ scrollTop: container.prop("scrollHeight") }, 500);
|
274 |
}
|
275 |
}
|
276 |
typeWriter();
|
277 |
-
// --- Typewriter effect for bot response END ---
|
278 |
});
|
|
|
279 |
|
280 |
event.preventDefault(); // Prevent form submission
|
281 |
});
|
@@ -349,7 +374,6 @@
|
|
349 |
document.addEventListener("DOMContentLoaded", () => {
|
350 |
const themeToggle = document.getElementById("themeToggle");
|
351 |
const body = document.body;
|
352 |
-
|
353 |
// Check local storage for a saved theme, default to dark
|
354 |
const savedTheme = localStorage.getItem("theme") || "dark";
|
355 |
if (savedTheme === "light") {
|
@@ -359,9 +383,7 @@
|
|
359 |
body.classList.add("dark-mode");
|
360 |
body.classList.remove("light-mode");
|
361 |
}
|
362 |
-
|
363 |
updateButton(); // Update button text on load
|
364 |
-
|
365 |
// Toggle theme on button click
|
366 |
themeToggle.addEventListener("click", () => {
|
367 |
if (body.classList.contains("light-mode")) {
|
@@ -377,36 +399,29 @@
|
|
377 |
}
|
378 |
updateButton();
|
379 |
});
|
380 |
-
|
381 |
function updateButton() {
|
382 |
themeToggle.textContent = body.classList.contains("light-mode")
|
383 |
? "Switch to Dark Mode"
|
384 |
: "Switch to Light Mode";
|
385 |
}
|
386 |
});
|
387 |
-
|
388 |
function showPredictiveText(predictions) {
|
389 |
if (predictions.length > 0 && $("#text").val().trim() !== "") {
|
390 |
-
|
391 |
let html = predictions.map(p => `<p>${p}</p>`).join('');
|
392 |
$(".predictive-text").html(html).show();
|
393 |
} else {
|
394 |
$(".predictive-text").hide();
|
395 |
-
|
396 |
}
|
397 |
}
|
398 |
function scrollToBottom() {
|
399 |
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
400 |
}
|
401 |
-
|
402 |
$(document).ready(function () {
|
403 |
$("#clearChat").click(function () {
|
404 |
$("#messageFormeight").html(""); // Clears the chat area
|
405 |
localStorage.removeItem("chatHistory"); // Clears stored history
|
406 |
});
|
407 |
});
|
408 |
-
|
409 |
-
|
410 |
</script>
|
411 |
|
412 |
</body>
|
|
|
162 |
<span class="msg_time_send">${str_time}</span>
|
163 |
</div>
|
164 |
<div class="img_cont_msg">
|
165 |
+
<img src="/static/images/user.png" class="rounded-circle user_img_msg">
|
166 |
</div>
|
167 |
</div>`;
|
168 |
|
|
|
204 |
type: "POST",
|
205 |
url: "/get",
|
206 |
}).done(function (response) {
|
207 |
+
// --- Typewriter effect for bot response with HTML support START ---
|
|
|
208 |
let botContainer = $(`
|
209 |
+
<div class="d-flex justify-content-start mb-4">
|
210 |
+
<div class="img_cont_msg">
|
211 |
+
<img src="/static/juitlogo.png" class="rounded-circle user_img_msg">
|
212 |
+
</div>
|
213 |
+
<div class="msg_container"></div>
|
214 |
+
</div>`);
|
215 |
$("#messageFormeight").append(botContainer);
|
216 |
|
217 |
let msgDiv = botContainer.find(".msg_container");
|
218 |
let i = 0;
|
219 |
+
|
220 |
function typeWriterInner() {
|
221 |
if (i < response.length) {
|
222 |
+
// Check if current character starts an HTML tag
|
223 |
+
if (response.charAt(i) === '<') {
|
224 |
+
let endTag = response.indexOf('>', i);
|
225 |
+
if (endTag !== -1) {
|
226 |
+
// Append the entire tag at once (so that HTML renders)
|
227 |
+
let tag = response.substring(i, endTag + 1);
|
228 |
+
msgDiv.append(tag);
|
229 |
+
i = endTag + 1;
|
230 |
+
} else {
|
231 |
+
// Fallback: append the single character if no closing '>' is found
|
232 |
+
msgDiv.append(response.charAt(i));
|
233 |
+
i++;
|
234 |
+
}
|
235 |
+
} else {
|
236 |
+
msgDiv.append(response.charAt(i));
|
237 |
+
i++;
|
238 |
+
}
|
239 |
+
setTimeout(typeWriterInner, 30); // Adjust delay as desired
|
240 |
} else {
|
241 |
msgDiv.append(`<span class="msg_time">${time}</span>`);
|
242 |
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
243 |
}
|
244 |
}
|
245 |
typeWriterInner();
|
246 |
+
// --- Typewriter effect for bot response with HTML support END ---
|
247 |
});
|
248 |
+
|
249 |
});
|
250 |
|
251 |
// Clear chat history
|
|
|
259 |
|
260 |
// Send the message to the server via AJAX
|
261 |
$.ajax({
|
262 |
+
data: { msg: rawText },
|
|
|
|
|
263 |
type: "POST",
|
264 |
url: "/get",
|
265 |
}).done(function(data) {
|
266 |
+
// --- Typewriter effect for bot response with HTML support START ---
|
267 |
var lines = data.split("**");
|
268 |
var fullText = lines.join(' ');
|
269 |
+
|
270 |
// Create the container for the bot message
|
271 |
var botContainer = $('<div class="d-flex justify-content-start mb-4"></div>');
|
272 |
var imgDiv = $('<div class="img_cont_msg"><img src="/static/juitlogo.png" class="rounded-circle user_img_msg"></div>');
|
273 |
var msgDiv = $('<div class="msg_container"></div>');
|
274 |
+
botContainer.append(imgDiv).append(msgDiv);
|
|
|
275 |
$("#messageFormeight").append(botContainer);
|
276 |
+
|
277 |
var i = 0;
|
278 |
function typeWriter() {
|
279 |
if (i < fullText.length) {
|
280 |
+
if (fullText.charAt(i) === '<') {
|
281 |
+
var endTag = fullText.indexOf('>', i);
|
282 |
+
if (endTag !== -1) {
|
283 |
+
var tag = fullText.substring(i, endTag + 1);
|
284 |
+
msgDiv.append(tag);
|
285 |
+
i = endTag + 1;
|
286 |
+
} else {
|
287 |
+
msgDiv.append(fullText.charAt(i));
|
288 |
+
i++;
|
289 |
+
}
|
290 |
+
} else {
|
291 |
+
msgDiv.append(fullText.charAt(i));
|
292 |
+
i++;
|
293 |
+
}
|
294 |
setTimeout(typeWriter, 30); // Adjust delay as needed
|
295 |
} else {
|
296 |
msgDiv.append('<span class="msg_time">' + str_time + '</span>');
|
297 |
+
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
|
|
|
|
298 |
}
|
299 |
}
|
300 |
typeWriter();
|
301 |
+
// --- Typewriter effect for bot response with HTML support END ---
|
302 |
});
|
303 |
+
|
304 |
|
305 |
event.preventDefault(); // Prevent form submission
|
306 |
});
|
|
|
374 |
document.addEventListener("DOMContentLoaded", () => {
|
375 |
const themeToggle = document.getElementById("themeToggle");
|
376 |
const body = document.body;
|
|
|
377 |
// Check local storage for a saved theme, default to dark
|
378 |
const savedTheme = localStorage.getItem("theme") || "dark";
|
379 |
if (savedTheme === "light") {
|
|
|
383 |
body.classList.add("dark-mode");
|
384 |
body.classList.remove("light-mode");
|
385 |
}
|
|
|
386 |
updateButton(); // Update button text on load
|
|
|
387 |
// Toggle theme on button click
|
388 |
themeToggle.addEventListener("click", () => {
|
389 |
if (body.classList.contains("light-mode")) {
|
|
|
399 |
}
|
400 |
updateButton();
|
401 |
});
|
|
|
402 |
function updateButton() {
|
403 |
themeToggle.textContent = body.classList.contains("light-mode")
|
404 |
? "Switch to Dark Mode"
|
405 |
: "Switch to Light Mode";
|
406 |
}
|
407 |
});
|
|
|
408 |
function showPredictiveText(predictions) {
|
409 |
if (predictions.length > 0 && $("#text").val().trim() !== "") {
|
|
|
410 |
let html = predictions.map(p => `<p>${p}</p>`).join('');
|
411 |
$(".predictive-text").html(html).show();
|
412 |
} else {
|
413 |
$(".predictive-text").hide();
|
|
|
414 |
}
|
415 |
}
|
416 |
function scrollToBottom() {
|
417 |
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
418 |
}
|
|
|
419 |
$(document).ready(function () {
|
420 |
$("#clearChat").click(function () {
|
421 |
$("#messageFormeight").html(""); // Clears the chat area
|
422 |
localStorage.removeItem("chatHistory"); // Clears stored history
|
423 |
});
|
424 |
});
|
|
|
|
|
425 |
</script>
|
426 |
|
427 |
</body>
|