Spaces:
Sleeping
Sleeping
nonsense
Browse files- static/style.css +1 -1
- templates/chat.html +212 -218
static/style.css
CHANGED
@@ -64,7 +64,7 @@ body, html {
|
|
64 |
}
|
65 |
.dark-mode .msg_container {
|
66 |
background-color: var(--msg-bg) !important;
|
67 |
-
color: #
|
68 |
}
|
69 |
|
70 |
.dark-mode .msg_container_send {
|
|
|
64 |
}
|
65 |
.dark-mode .msg_container {
|
66 |
background-color: var(--msg-bg) !important;
|
67 |
+
color: #000000 !important; /* Ensure text is visible */
|
68 |
}
|
69 |
|
70 |
.dark-mode .msg_container_send {
|
templates/chat.html
CHANGED
@@ -9,10 +9,12 @@
|
|
9 |
|
10 |
|
11 |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
12 |
-
|
|
|
13 |
|
14 |
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css"
|
15 |
-
integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU"
|
|
|
16 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
17 |
<script>
|
18 |
window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };
|
@@ -21,7 +23,7 @@
|
|
21 |
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}" />
|
22 |
|
23 |
<style>
|
24 |
-
|
25 |
</style>
|
26 |
|
27 |
</head>
|
@@ -37,13 +39,12 @@
|
|
37 |
<img src="/static/images/juitlogo.png" class="rounded-circle user_img">
|
38 |
<span class="online_icon"></span>
|
39 |
</div>
|
40 |
-
|
41 |
<div class="user_info">
|
42 |
<span>JUIT AI Assist</span>
|
43 |
<p>Explore College and Beyond: Ask Anything! 🎓</p>
|
44 |
-
|
45 |
<!-- Add this inside the card-header (after user_info div) -->
|
46 |
-
|
47 |
|
48 |
</div>
|
49 |
</div>
|
@@ -55,13 +56,12 @@
|
|
55 |
<div class="card-footer" style="position: relative;">
|
56 |
<form id="messageArea" class="input-group" style="position: relative;">
|
57 |
<!-- Predictive Text Suggestions (ADD THIS HERE) -->
|
58 |
-
<div class="predictive-text"
|
59 |
-
style="position: absolute; display: none; z-index: 1000; width: 100%;"></div>
|
60 |
|
61 |
|
62 |
-
|
63 |
-
<input type="text" id="text" name="msg" placeholder="Type your message..."
|
64 |
-
|
65 |
<div class="input-group-append">
|
66 |
<button type="submit" id="send" class="input-group-text send_btn">
|
67 |
<i class="fas fa-location-arrow"></i>
|
@@ -69,19 +69,18 @@
|
|
69 |
</div>
|
70 |
</form>
|
71 |
<button id="clearChat" class="btn btn-danger mt-2">Clear Chat</button>
|
72 |
-
|
73 |
<div class="card-footer text-center">
|
74 |
<div class="d-flex justify-content-center align-items-center">
|
75 |
<span class="mr-2">Developed by:</span>
|
76 |
<span class="mr-2">Ramandeep Singh Makkar</span>
|
77 |
-
<a href="https://www.linkedin.com/in/ramandeep-singh-makkar/" target="_blank"
|
78 |
-
class="mr-2">
|
79 |
<i class="fab fa-linkedin"></i>
|
80 |
</a>
|
81 |
<a href="mailto:[email protected]" class="mr-3">
|
82 |
<i class="fas fa-envelope"></i>
|
83 |
</a>
|
84 |
-
|
85 |
<span class="mr-2">Aditya Singh</span>
|
86 |
<a href="https://www.linkedin.com/in/aditsg26/" target="_blank" class="mr-2">
|
87 |
<i class="fab fa-linkedin"></i>
|
@@ -91,227 +90,222 @@
|
|
91 |
</a>
|
92 |
</div>
|
93 |
</div>
|
94 |
-
|
|
|
95 |
</div>
|
96 |
</div>
|
97 |
</div>
|
|
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
$(".predictive-text").hide();
|
118 |
-
});
|
119 |
-
|
120 |
-
function getPredictiveText(input) {
|
121 |
-
const predictions = [];
|
122 |
-
const patterns = {
|
123 |
-
"greeting": ["Hi", "Hey", "How are you", "what's up", "Is anyone there?", "Hello", "Good day"],
|
124 |
-
"name": ["what is your name", "name", "what's your name", "who are you", "what should I call you"]
|
125 |
-
};
|
126 |
-
|
127 |
-
// Loop through each pattern group and add matching predictions.
|
128 |
-
for (let tag in patterns) {
|
129 |
-
patterns[tag].forEach(function (pattern) {
|
130 |
-
if (pattern.toLowerCase().startsWith(input) && !predictions.includes(pattern)) {
|
131 |
-
predictions.push(pattern);
|
132 |
-
}
|
133 |
-
});
|
134 |
-
}
|
135 |
-
return predictions;
|
136 |
}
|
|
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
});
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
------------------------------ */
|
153 |
-
$("#messageArea").on("submit", function (event) {
|
154 |
-
event.preventDefault();
|
155 |
-
$(".predictive-text").hide();
|
156 |
-
|
157 |
-
// Get current time for timestamp
|
158 |
-
const date = new Date();
|
159 |
-
const hour = date.getHours().toString().padStart(2, '0');
|
160 |
-
const minute = date.getMinutes().toString().padStart(2, '0');
|
161 |
-
const str_time = hour + ":" + minute;
|
162 |
-
|
163 |
-
// Get and validate user input
|
164 |
-
const rawText = $("#text").val().trim();
|
165 |
-
if(rawText === "") return;
|
166 |
-
|
167 |
-
// Update chat history and store it
|
168 |
-
chatHistory.push(rawText);
|
169 |
-
localStorage.setItem("chatHistory", JSON.stringify(chatHistory));
|
170 |
-
currentIndex = chatHistory.length;
|
171 |
-
|
172 |
-
// Build and append the user message
|
173 |
-
const userHtml = `
|
174 |
-
<div class="d-flex justify-content-end mb-4">
|
175 |
-
<div class="msg_container_send">
|
176 |
-
${rawText}
|
177 |
-
<span class="msg_time_send">${str_time}</span>
|
178 |
-
</div>
|
179 |
-
<div class="img_cont_msg">
|
180 |
-
<img src="/static/images/user.png" class="rounded-circle user_img_msg">
|
181 |
-
</div>
|
182 |
-
</div>`;
|
183 |
-
$("#messageFormeight").append(userHtml);
|
184 |
-
$("#text").val("");
|
185 |
-
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
186 |
-
|
187 |
-
// Append a typing animation for the bot
|
188 |
-
const typingHtml = `
|
189 |
-
<div id="typingIndicator" class="d-flex justify-content-start mb-4">
|
190 |
-
<div class="img_cont_msg">
|
191 |
-
<img src="/static/images/juitlogo.png" class="rounded-circle user_img_msg">
|
192 |
-
</div>
|
193 |
-
<div class="msg_container typing-animation">
|
194 |
-
<span>.</span><span>.</span><span>.</span>
|
195 |
-
</div>
|
196 |
-
</div>`;
|
197 |
-
$("#messageFormeight").append(typingHtml);
|
198 |
-
|
199 |
-
// Send user message to server and process bot's response
|
200 |
-
$.ajax({
|
201 |
-
data: { msg: rawText },
|
202 |
-
type: "POST",
|
203 |
-
url: "/get"
|
204 |
-
}).done(function (response) {
|
205 |
-
// Delay to simulate typing before showing response
|
206 |
-
setTimeout(function () {
|
207 |
-
// Remove the typing animation
|
208 |
-
$("#typingIndicator").remove();
|
209 |
-
|
210 |
-
// Append container for the bot's response
|
211 |
-
const botHtmlContainer = `
|
212 |
-
<div class="d-flex justify-content-start mb-4">
|
213 |
-
<div class="img_cont_msg">
|
214 |
-
<img src="/static/images/juitlogo.png" class="rounded-circle user_img_msg">
|
215 |
-
</div>
|
216 |
-
<div class="msg_container" id="botResponse"></div>
|
217 |
-
</div>`;
|
218 |
-
$("#messageFormeight").append(botHtmlContainer);
|
219 |
-
|
220 |
-
// Typewriter effect: append one character at a time.
|
221 |
-
let index = 0;
|
222 |
-
function typeWriter() {
|
223 |
-
if (index < response.length) {
|
224 |
-
$("#botResponse").append(response.charAt(index));
|
225 |
-
index++;
|
226 |
-
setTimeout(typeWriter, 10); // adjust delay (50ms) for speed
|
227 |
-
} else {
|
228 |
-
// After finishing, append timestamp and scroll to the bottom.
|
229 |
-
$("#botResponse").append(`<span class="msg_time">${str_time}</span>`);
|
230 |
-
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
231 |
-
}
|
232 |
-
}
|
233 |
-
typeWriter();
|
234 |
-
}, 1000);
|
235 |
});
|
236 |
});
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
const themeToggle = document.getElementById("themeToggle");
|
254 |
-
const body = document.body;
|
255 |
-
|
256 |
-
// Check local storage for a saved theme, default to dark
|
257 |
-
const savedTheme = localStorage.getItem("theme") || "dark";
|
258 |
-
if (savedTheme === "light") {
|
259 |
-
body.classList.add("light-mode");
|
260 |
-
body.classList.remove("dark-mode");
|
261 |
-
} else {
|
262 |
-
body.classList.add("dark-mode");
|
263 |
-
body.classList.remove("light-mode");
|
264 |
-
}
|
265 |
-
|
266 |
-
updateButton(); // Update button text on load
|
267 |
-
|
268 |
-
// Toggle theme on button click
|
269 |
-
themeToggle.addEventListener("click", () => {
|
270 |
-
if (body.classList.contains("light-mode")) {
|
271 |
-
// Switch to dark mode
|
272 |
-
body.classList.remove("light-mode");
|
273 |
-
body.classList.add("dark-mode");
|
274 |
-
localStorage.setItem("theme", "dark");
|
275 |
-
} else {
|
276 |
-
// Switch to light mode
|
277 |
-
body.classList.remove("dark-mode");
|
278 |
-
body.classList.add("light-mode");
|
279 |
-
localStorage.setItem("theme", "light");
|
280 |
}
|
281 |
-
|
|
|
|
|
|
|
|
|
282 |
});
|
283 |
-
|
284 |
-
function updateButton() {
|
285 |
-
themeToggle.textContent = body.classList.contains("light-mode")
|
286 |
-
? "Switch to Dark Mode"
|
287 |
-
: "Switch to Light Mode";
|
288 |
-
}
|
289 |
});
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
} else {
|
297 |
-
|
298 |
-
|
|
|
|
|
299 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
}
|
301 |
-
|
302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
}
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
|
|
|
|
|
|
310 |
});
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
|
|
315 |
</body>
|
316 |
|
317 |
</html>
|
|
|
9 |
|
10 |
|
11 |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
12 |
+
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
|
13 |
+
crossorigin="anonymous">
|
14 |
|
15 |
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css"
|
16 |
+
integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU"
|
17 |
+
crossorigin="anonymous">
|
18 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
19 |
<script>
|
20 |
window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };
|
|
|
23 |
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}" />
|
24 |
|
25 |
<style>
|
26 |
+
|
27 |
</style>
|
28 |
|
29 |
</head>
|
|
|
39 |
<img src="/static/images/juitlogo.png" class="rounded-circle user_img">
|
40 |
<span class="online_icon"></span>
|
41 |
</div>
|
42 |
+
|
43 |
<div class="user_info">
|
44 |
<span>JUIT AI Assist</span>
|
45 |
<p>Explore College and Beyond: Ask Anything! 🎓</p>
|
|
|
46 |
<!-- Add this inside the card-header (after user_info div) -->
|
47 |
+
<button id="themeToggle" class="btn btn-sm btn-light ml-auto">Light Mode</button>
|
48 |
|
49 |
</div>
|
50 |
</div>
|
|
|
56 |
<div class="card-footer" style="position: relative;">
|
57 |
<form id="messageArea" class="input-group" style="position: relative;">
|
58 |
<!-- Predictive Text Suggestions (ADD THIS HERE) -->
|
59 |
+
<div class="predictive-text" style="position: absolute; display: none; z-index: 1000; width: 100%;"></div>
|
|
|
60 |
|
61 |
|
62 |
+
|
63 |
+
<input type="text" id="text" name="msg" placeholder="Type your message..." autocomplete="off"
|
64 |
+
class="form-control type_msg" required />
|
65 |
<div class="input-group-append">
|
66 |
<button type="submit" id="send" class="input-group-text send_btn">
|
67 |
<i class="fas fa-location-arrow"></i>
|
|
|
69 |
</div>
|
70 |
</form>
|
71 |
<button id="clearChat" class="btn btn-danger mt-2">Clear Chat</button>
|
72 |
+
|
73 |
<div class="card-footer text-center">
|
74 |
<div class="d-flex justify-content-center align-items-center">
|
75 |
<span class="mr-2">Developed by:</span>
|
76 |
<span class="mr-2">Ramandeep Singh Makkar</span>
|
77 |
+
<a href="https://www.linkedin.com/in/ramandeep-singh-makkar/" target="_blank" class="mr-2">
|
|
|
78 |
<i class="fab fa-linkedin"></i>
|
79 |
</a>
|
80 |
<a href="mailto:[email protected]" class="mr-3">
|
81 |
<i class="fas fa-envelope"></i>
|
82 |
</a>
|
83 |
+
|
84 |
<span class="mr-2">Aditya Singh</span>
|
85 |
<a href="https://www.linkedin.com/in/aditsg26/" target="_blank" class="mr-2">
|
86 |
<i class="fab fa-linkedin"></i>
|
|
|
90 |
</a>
|
91 |
</div>
|
92 |
</div>
|
93 |
+
|
94 |
+
|
95 |
</div>
|
96 |
</div>
|
97 |
</div>
|
98 |
+
</div>
|
99 |
|
100 |
+
<script>
|
101 |
+
$(document).ready(function() {
|
102 |
+
let chatHistory = []; // Stores the user's input history
|
103 |
+
let currentIndex = -1; // Tracks the current position in the history
|
104 |
+
// Handle predictive text
|
105 |
+
$("#text").on("input", function() {
|
106 |
+
var input = $(this).val().toLowerCase();
|
107 |
+
var predictions = getPredictiveText(input);
|
108 |
+
showPredictiveText(predictions);
|
109 |
+
});
|
110 |
+
$(document).on("click", ".predictive-text p", function() {
|
111 |
+
var text = $(this).text();
|
112 |
+
$("#text").val(text);
|
113 |
+
$(".predictive-text").hide();
|
114 |
+
});
|
115 |
+
function getPredictiveText(input) {
|
116 |
+
var predictions = [];
|
117 |
+
var patterns = {
|
118 |
+
"greeting": ["Hi", "Hey", "How are you", "what's up", "Is anyone there?", "Hello", "Good day"],
|
119 |
+
"name": ["what is your name", "name", "what's your name", "who are you", "what should I call you"]
|
120 |
+
|
121 |
+
};
|
122 |
+
for (var tag in patterns) {
|
123 |
+
patterns[tag].forEach(function(pattern) {
|
124 |
+
if (pattern.toLowerCase().startsWith(input) && !predictions.includes(pattern)) {
|
125 |
+
predictions.push(pattern);
|
126 |
+
}
|
127 |
+
});
|
128 |
+
}
|
129 |
+
return predictions;
|
130 |
+
}
|
131 |
+
function showPredictiveText(predictions) {
|
132 |
+
if (predictions.length > 0) {
|
133 |
+
var html = "";
|
134 |
+
predictions.forEach(function(prediction) {
|
135 |
+
html += "<p>" + prediction + "</p>";
|
136 |
+
});
|
137 |
+
$(".predictive-text").html(html).show();
|
138 |
+
} else {
|
139 |
$(".predictive-text").hide();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
}
|
141 |
+
}
|
142 |
|
143 |
+
// Handle message submission and user input history
|
144 |
+
$("#messageArea").on("submit", function(event) {
|
145 |
+
$(".predictive-text").hide(); // Hide predictive suggestions
|
146 |
+
const date = new Date();
|
147 |
+
const hour = date.getHours().toString().padStart(2, '0');
|
148 |
+
const minute = date.getMinutes().toString().padStart(2, '0');
|
149 |
+
const str_time = hour + ":" + minute;
|
150 |
+
var rawText = $("#text").val();
|
151 |
+
chatHistory.push(rawText); // Store the user's message in history
|
152 |
+
currentIndex = chatHistory.length - 1; // Update the current index
|
153 |
+
var userHtml = `
|
154 |
+
<div class="d-flex justify-content-end mb-4">
|
155 |
+
<div class="msg_container_send">${rawText}
|
156 |
+
<span class="msg_time_send">${str_time}</span>
|
157 |
+
</div>
|
158 |
+
<div class="img_cont_msg">
|
159 |
+
<img src="/static/images/user.png" class="rounded-circle user_img_msg">
|
160 |
+
</div>
|
161 |
+
</div>`;
|
162 |
+
$("#text").val(""); // Clear the input field
|
163 |
+
$("#messageFormeight").append(userHtml); // Add the user message to the chat
|
164 |
+
$(document).ready(function () {
|
165 |
+
let chatHistory = JSON.parse(localStorage.getItem("chatHistory")) || []; // Load stored history
|
166 |
+
let currentIndex = chatHistory.length; // Set index to last message
|
167 |
+
|
168 |
+
$("#messageArea").on("submit", function (event) {
|
169 |
+
event.preventDefault(); // Prevent form submission
|
170 |
+
|
171 |
+
let rawText = $("#text").val().trim();
|
172 |
+
if (rawText === "") return; // Ignore empty input
|
173 |
+
|
174 |
+
const time = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
175 |
+
|
176 |
+
// Append user message to chat
|
177 |
+
let userHtml = `
|
178 |
+
<div class="d-flex justify-content-end mb-4">
|
179 |
+
<div class="msg_container_send">${rawText}<span class="msg_time_send">${time}</span></div>
|
180 |
+
<div class="img_cont_msg"><img src="https://i.ibb.co/d5b84Xw/Untitled-design.png" class="rounded-circle user_img_msg"></div>
|
181 |
+
</div>`;
|
182 |
+
$("#messageFormeight").append(userHtml);
|
183 |
+
|
184 |
+
// Update chat history
|
185 |
+
chatHistory.push(rawText);
|
186 |
+
localStorage.setItem("chatHistory", JSON.stringify(chatHistory)); // Save in localStorage
|
187 |
+
currentIndex = chatHistory.length; // Reset index to end
|
188 |
+
|
189 |
+
// Clear input field & scroll down
|
190 |
+
$("#text").val("");
|
191 |
+
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
192 |
+
|
193 |
+
// Send message to server
|
194 |
+
$.ajax({
|
195 |
+
data: { msg: rawText },
|
196 |
+
type: "POST",
|
197 |
+
url: "/get",
|
198 |
+
}).done(function (response) {
|
199 |
+
let botHtml = `
|
200 |
+
<div class="d-flex justify-content-start mb-4">
|
201 |
+
<div class="img_cont_msg">
|
202 |
+
<img src="/static/images/juitlogo.png" class="rounded-circle user_img_msg">
|
203 |
+
</div>
|
204 |
+
<div class="msg_container">${response}<span class="msg_time">${time}</span></div>
|
205 |
+
</div>`;
|
206 |
+
$("#messageFormeight").append($.parseHTML(botHtml));
|
207 |
+
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
208 |
});
|
209 |
+
});
|
210 |
+
|
211 |
+
// Clear chat history
|
212 |
+
$("#clearChat").click(function () {
|
213 |
+
$("#messageFormeight").html(""); // Clears UI
|
214 |
+
chatHistory = []; // Clears array
|
215 |
+
localStorage.removeItem("chatHistory"); // Clears from storage
|
216 |
+
currentIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
});
|
218 |
});
|
219 |
+
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
// Send the message to the server via AJAX
|
224 |
+
$.ajax({
|
225 |
+
data: {
|
226 |
+
msg: rawText,
|
227 |
+
},
|
228 |
+
type: "POST",
|
229 |
+
url: "/get",
|
230 |
+
}).done(function(data) {
|
231 |
+
var lines = data.split("**");
|
232 |
+
var botHtml = '<div class="d-flex justify-content-start mb-4"><div class="img_cont_msg"><img src="/static/images/juitlogo.png" class="rounded-circle user_img_msg"></div><div class="msg_container">';
|
233 |
+
for (var i = 0; i < lines.length; i++) {
|
234 |
+
botHtml += '<div class="msg_container">' + lines[i] + '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
}
|
236 |
+
botHtml += '<span class="msg_time">' + str_time + '</span></div></div>';
|
237 |
+
$("#messageFormeight").append($.parseHTML(botHtml));
|
238 |
+
// Smooth scroll to the bottom of the chat
|
239 |
+
var container = $("#messageFormeight");
|
240 |
+
container.animate({ scrollTop: container.prop("scrollHeight") }, 500);
|
241 |
});
|
242 |
+
event.preventDefault(); // Prevent form submission
|
|
|
|
|
|
|
|
|
|
|
243 |
});
|
244 |
+
});
|
245 |
+
</script>
|
246 |
+
|
247 |
+
<script>
|
248 |
+
document.addEventListener("DOMContentLoaded", () => {
|
249 |
+
const themeToggle = document.getElementById("themeToggle");
|
250 |
+
const body = document.body;
|
251 |
+
|
252 |
+
// Check local storage for a saved theme, default to dark
|
253 |
+
const savedTheme = localStorage.getItem("theme") || "dark";
|
254 |
+
if (savedTheme === "light") {
|
255 |
+
body.classList.add("light-mode");
|
256 |
+
body.classList.remove("dark-mode");
|
257 |
+
} else {
|
258 |
+
body.classList.add("dark-mode");
|
259 |
+
body.classList.remove("light-mode");
|
260 |
+
}
|
261 |
+
|
262 |
+
updateButton(); // Update button text on load
|
263 |
+
|
264 |
+
// Toggle theme on button click
|
265 |
+
themeToggle.addEventListener("click", () => {
|
266 |
+
if (body.classList.contains("light-mode")) {
|
267 |
+
// Switch to dark mode
|
268 |
+
body.classList.remove("light-mode");
|
269 |
+
body.classList.add("dark-mode");
|
270 |
+
localStorage.setItem("theme", "dark");
|
271 |
} else {
|
272 |
+
// Switch to light mode
|
273 |
+
body.classList.remove("dark-mode");
|
274 |
+
body.classList.add("light-mode");
|
275 |
+
localStorage.setItem("theme", "light");
|
276 |
}
|
277 |
+
updateButton();
|
278 |
+
});
|
279 |
+
|
280 |
+
function updateButton() {
|
281 |
+
themeToggle.textContent = body.classList.contains("light-mode")
|
282 |
+
? "Switch to Dark Mode"
|
283 |
+
: "Switch to Light Mode";
|
284 |
}
|
285 |
+
});
|
286 |
+
|
287 |
+
function showPredictiveText(predictions) {
|
288 |
+
if (predictions.length > 0 && $("#text").val().trim() !== "") {
|
289 |
+
let html = predictions.map(p => `<p>${p}</p>`).join('');
|
290 |
+
$(".predictive-text").html(html).show();
|
291 |
+
} else {
|
292 |
+
$(".predictive-text").hide();
|
293 |
}
|
294 |
+
}
|
295 |
+
function scrollToBottom() {
|
296 |
+
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
297 |
+
}
|
298 |
+
|
299 |
+
$(document).ready(function() {
|
300 |
+
$("#clearChat").click(function() {
|
301 |
+
$("#messageFormeight").html(""); // Clears the chat area
|
302 |
+
localStorage.removeItem("chatHistory"); // Clears stored history
|
303 |
});
|
304 |
+
});
|
305 |
+
|
306 |
+
|
307 |
+
</script>
|
308 |
+
|
309 |
</body>
|
310 |
|
311 |
</html>
|