Spaces:
Sleeping
Sleeping
update
Browse files- static/images/juitlogo.png +0 -0
- static/images/user.png +0 -0
- static/juitlogo.png +0 -3
- static/style.css +11 -13
- static/userlogo.png +0 -3
- templates/chat.html +223 -229
static/images/juitlogo.png
ADDED
![]() |
static/images/user.png
ADDED
![]() |
static/juitlogo.png
DELETED
Git LFS Details
|
static/style.css
CHANGED
@@ -31,12 +31,7 @@ body, html {
|
|
31 |
--input-bg: rgba(255, 255, 255, 0.85);
|
32 |
--border-color: #444; /* Slightly softer black for a modern look */
|
33 |
|
34 |
-
|
35 |
-
to bottom,
|
36 |
-
var(--gradient-start),
|
37 |
-
var(--gradient-mid),
|
38 |
-
var(--gradient-end)
|
39 |
-
) !important;
|
40 |
color: var(--text-color) !important;
|
41 |
}
|
42 |
/* Light Mode - Ensure theme toggle button is dark */
|
@@ -64,7 +59,7 @@ body, html {
|
|
64 |
--input-bg: rgba(0,0,0,0.5);
|
65 |
--border-color: #777;
|
66 |
|
67 |
-
background: linear-gradient(to
|
68 |
color: var(--text-color) !important;
|
69 |
}
|
70 |
.dark-mode .msg_container {
|
@@ -74,7 +69,7 @@ body, html {
|
|
74 |
|
75 |
.dark-mode .msg_container_send {
|
76 |
background-color: var(--msg-send-bg) !important;
|
77 |
-
color: #
|
78 |
}
|
79 |
.dark-mode .type_msg::placeholder {
|
80 |
color: rgba(255, 255, 255, 0.7) !important; /* Make it more readable */
|
@@ -135,12 +130,12 @@ body, html {
|
|
135 |
|
136 |
/* Chat Container */
|
137 |
.chat {
|
138 |
-
height:
|
139 |
max-height: 700px; /* Ensures it doesn't get too large */
|
140 |
}
|
141 |
.card {
|
142 |
-
height: calc(100%
|
143 |
-
max-height: calc(100%
|
144 |
overflow: hidden;
|
145 |
position: relative;
|
146 |
background-color: var(--card-bg) !important;
|
@@ -400,6 +395,10 @@ border-radius: 0 0 15px 15px !important;
|
|
400 |
background-color: var(--msg-send-bg);
|
401 |
padding: 10px;
|
402 |
border-radius: 25px;
|
|
|
|
|
|
|
|
|
403 |
}
|
404 |
.msg_time{
|
405 |
position: absolute;
|
@@ -469,5 +468,4 @@ border-radius: 0 0 15px 15px !important;
|
|
469 |
|
470 |
.predefined-text a:hover {
|
471 |
text-decoration: underline;
|
472 |
-
}
|
473 |
-
|
|
|
31 |
--input-bg: rgba(255, 255, 255, 0.85);
|
32 |
--border-color: #444; /* Slightly softer black for a modern look */
|
33 |
|
34 |
+
background-image: linear-gradient(to right, #74ebd5 0%, #9face6 100%)!important;
|
|
|
|
|
|
|
|
|
|
|
35 |
color: var(--text-color) !important;
|
36 |
}
|
37 |
/* Light Mode - Ensure theme toggle button is dark */
|
|
|
59 |
--input-bg: rgba(0,0,0,0.5);
|
60 |
--border-color: #777;
|
61 |
|
62 |
+
background-image: linear-gradient(to top, #09203f 0%, #537895 100%)!important;
|
63 |
color: var(--text-color) !important;
|
64 |
}
|
65 |
.dark-mode .msg_container {
|
|
|
69 |
|
70 |
.dark-mode .msg_container_send {
|
71 |
background-color: var(--msg-send-bg) !important;
|
72 |
+
color: #000000 !important;
|
73 |
}
|
74 |
.dark-mode .type_msg::placeholder {
|
75 |
color: rgba(255, 255, 255, 0.7) !important; /* Make it more readable */
|
|
|
130 |
|
131 |
/* Chat Container */
|
132 |
.chat {
|
133 |
+
height: 90vh; /* Adjust as needed */
|
134 |
max-height: 700px; /* Ensures it doesn't get too large */
|
135 |
}
|
136 |
.card {
|
137 |
+
height: calc(100% );
|
138 |
+
max-height: calc(100%);
|
139 |
overflow: hidden;
|
140 |
position: relative;
|
141 |
background-color: var(--card-bg) !important;
|
|
|
395 |
background-color: var(--msg-send-bg);
|
396 |
padding: 10px;
|
397 |
border-radius: 25px;
|
398 |
+
margin-right:10px;
|
399 |
+
padding-left: 20px;
|
400 |
+
padding-right: 20px;
|
401 |
+
|
402 |
}
|
403 |
.msg_time{
|
404 |
position: absolute;
|
|
|
468 |
|
469 |
.predefined-text a:hover {
|
470 |
text-decoration: underline;
|
471 |
+
}
|
|
static/userlogo.png
DELETED
Git LFS Details
|
templates/chat.html
CHANGED
@@ -5,16 +5,14 @@
|
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
<title>JUIT AI Assist</title>
|
8 |
-
<link rel="shortcut icon" href="/static/juitlogo.png" type="image/x-icon">
|
9 |
|
10 |
|
11 |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
12 |
-
|
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,7 +21,7 @@
|
|
23 |
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}" />
|
24 |
|
25 |
<style>
|
26 |
-
|
27 |
</style>
|
28 |
|
29 |
</head>
|
@@ -36,9 +34,18 @@
|
|
36 |
<div class="card-header msg_head">
|
37 |
<div class="d-flex bd-highlight">
|
38 |
<div class="img_cont">
|
39 |
-
<img src="/static/juitlogo.png" class="rounded-circle user_img">
|
40 |
<span class="online_icon"></span>
|
41 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
</div>
|
43 |
</div>
|
44 |
|
@@ -48,12 +55,13 @@
|
|
48 |
<div class="card-footer" style="position: relative;">
|
49 |
<form id="messageArea" class="input-group" style="position: relative;">
|
50 |
<!-- Predictive Text Suggestions (ADD THIS HERE) -->
|
51 |
-
<div class="predictive-text"
|
|
|
|
|
52 |
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
class="form-control type_msg" required />
|
57 |
<div class="input-group-append">
|
58 |
<button type="submit" id="send" class="input-group-text send_btn">
|
59 |
<i class="fas fa-location-arrow"></i>
|
@@ -61,18 +69,19 @@
|
|
61 |
</div>
|
62 |
</form>
|
63 |
<button id="clearChat" class="btn btn-danger mt-2">Clear Chat</button>
|
64 |
-
|
65 |
<div class="card-footer text-center">
|
66 |
-
<p class="mb-1">Created by</p>
|
67 |
<div class="d-flex justify-content-center align-items-center">
|
|
|
68 |
<span class="mr-2">Ramandeep Singh Makkar</span>
|
69 |
-
<a href="https://www.linkedin.com/in/ramandeep-singh-makkar/" target="_blank"
|
|
|
70 |
<i class="fab fa-linkedin"></i>
|
71 |
</a>
|
72 |
<a href="mailto:[email protected]" class="mr-3">
|
73 |
<i class="fas fa-envelope"></i>
|
74 |
</a>
|
75 |
-
|
76 |
<span class="mr-2">Aditya Singh</span>
|
77 |
<a href="https://www.linkedin.com/in/aditsg26/" target="_blank" class="mr-2">
|
78 |
<i class="fab fa-linkedin"></i>
|
@@ -82,242 +91,227 @@
|
|
82 |
</a>
|
83 |
</div>
|
84 |
</div>
|
85 |
-
|
86 |
-
|
87 |
</div>
|
88 |
</div>
|
89 |
</div>
|
90 |
-
</div>
|
91 |
-
|
92 |
-
<script>
|
93 |
-
$(document).ready(function() {
|
94 |
-
let chatHistory = []; // Stores the user's input history
|
95 |
-
let currentIndex = -1; // Tracks the current position in the history
|
96 |
-
|
97 |
-
// Handle predictive text
|
98 |
-
$("#text").on("input", function() {
|
99 |
-
var input = $(this).val().toLowerCase();
|
100 |
-
var predictions = getPredictiveText(input);
|
101 |
-
showPredictiveText(predictions);
|
102 |
-
});
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
});
|
|
|
|
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
"name": ["what is your name", "name", "what's your name", "who are you", "what should I call you"]
|
115 |
-
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
}
|
125 |
-
});
|
126 |
}
|
127 |
-
|
128 |
-
}
|
129 |
|
130 |
function showPredictiveText(predictions) {
|
131 |
-
if (predictions.length > 0) {
|
132 |
-
|
133 |
-
predictions.
|
134 |
-
html += "<p>" + prediction + "</p>";
|
135 |
-
});
|
136 |
$(".predictive-text").html(html).show();
|
137 |
} else {
|
138 |
$(".predictive-text").hide();
|
|
|
139 |
}
|
140 |
}
|
|
|
|
|
|
|
141 |
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
const date = new Date();
|
148 |
-
const hour = date.getHours().toString().padStart(2, '0');
|
149 |
-
const minute = date.getMinutes().toString().padStart(2, '0');
|
150 |
-
const str_time = hour + ":" + minute;
|
151 |
-
|
152 |
-
var rawText = $("#text").val();
|
153 |
-
chatHistory.push(rawText); // Store the user's message in history
|
154 |
-
currentIndex = chatHistory.length - 1; // Update the current index
|
155 |
-
|
156 |
-
var userHtml = `
|
157 |
-
<div class="d-flex justify-content-end mb-4">
|
158 |
-
<div class="msg_container_send">${rawText}
|
159 |
-
<span class="msg_time_send">${str_time}</span>
|
160 |
-
</div>
|
161 |
-
<div class="img_cont_msg">
|
162 |
-
<img src="/static/userlogo.png" class="rounded-circle user_img_msg">
|
163 |
-
</div>
|
164 |
-
</div>`;
|
165 |
-
|
166 |
-
$("#text").val(""); // Clear the input field
|
167 |
-
$("#messageFormeight").append(userHtml); // Add the user message to the chat
|
168 |
-
|
169 |
-
$(document).ready(function () {
|
170 |
-
let chatHistory = JSON.parse(localStorage.getItem("chatHistory")) || []; // Load stored history
|
171 |
-
let currentIndex = chatHistory.length; // Set index to last message
|
172 |
-
|
173 |
-
$("#messageArea").on("submit", function (event) {
|
174 |
-
event.preventDefault(); // Prevent form submission
|
175 |
-
|
176 |
-
let rawText = $("#text").val().trim();
|
177 |
-
if (rawText === "") return; // Ignore empty input
|
178 |
-
|
179 |
-
const time = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
180 |
-
|
181 |
-
// Append user message to chat
|
182 |
-
let userHtml = `
|
183 |
-
<div class="d-flex justify-content-end mb-4">
|
184 |
-
<div class="msg_container_send">${rawText}<span class="msg_time_send">${time}</span></div>
|
185 |
-
<div class="img_cont_msg"><img src="https://i.ibb.co/d5b84Xw/Untitled-design.png" class="rounded-circle user_img_msg"></div>
|
186 |
-
</div>`;
|
187 |
-
$("#messageFormeight").append(userHtml);
|
188 |
-
|
189 |
-
// Update chat history
|
190 |
-
chatHistory.push(rawText);
|
191 |
-
localStorage.setItem("chatHistory", JSON.stringify(chatHistory)); // Save in localStorage
|
192 |
-
currentIndex = chatHistory.length; // Reset index to end
|
193 |
-
|
194 |
-
// Clear input field & scroll down
|
195 |
-
$("#text").val("");
|
196 |
-
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
197 |
-
|
198 |
-
// Send message to server
|
199 |
-
$.ajax({
|
200 |
-
data: { msg: rawText },
|
201 |
-
type: "POST",
|
202 |
-
url: "/get",
|
203 |
-
}).done(function (response) {
|
204 |
-
let botHtml = `
|
205 |
-
<div class="d-flex justify-content-start mb-4">
|
206 |
-
<div class="img_cont_msg">
|
207 |
-
<img src="/static/juitlogo.png" class="rounded-circle user_img_msg">
|
208 |
-
</div>
|
209 |
-
<div class="msg_container">${response}<span class="msg_time">${time}</span></div>
|
210 |
-
</div>`;
|
211 |
-
|
212 |
-
$("#messageFormeight").append($.parseHTML(botHtml));
|
213 |
-
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
214 |
-
});
|
215 |
-
});
|
216 |
-
|
217 |
-
// Clear chat history
|
218 |
-
$("#clearChat").click(function () {
|
219 |
-
$("#messageFormeight").html(""); // Clears UI
|
220 |
-
chatHistory = []; // Clears array
|
221 |
-
localStorage.removeItem("chatHistory"); // Clears from storage
|
222 |
-
currentIndex = 0;
|
223 |
-
});
|
224 |
-
});
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
// Send the message to the server via AJAX
|
231 |
-
$.ajax({
|
232 |
-
data: {
|
233 |
-
msg: rawText,
|
234 |
-
},
|
235 |
-
type: "POST",
|
236 |
-
url: "/get",
|
237 |
-
}).done(function(data) {
|
238 |
-
var lines = data.split("**");
|
239 |
-
var botHtml = '<div class="d-flex justify-content-start mb-4"><div class="img_cont_msg"><img src="/static/juitlogo.png" class="rounded-circle user_img_msg"></div><div class="msg_container">';
|
240 |
-
|
241 |
-
for (var i = 0; i < lines.length; i++) {
|
242 |
-
botHtml += '<div class="msg_container">' + lines[i] + '</div>';
|
243 |
-
}
|
244 |
-
botHtml += '<span class="msg_time">' + str_time + '</span></div></div>';
|
245 |
-
$("#messageFormeight").append($.parseHTML(botHtml));
|
246 |
-
|
247 |
-
// Smooth scroll to the bottom of the chat
|
248 |
-
var container = $("#messageFormeight");
|
249 |
-
container.animate({ scrollTop: container.prop("scrollHeight") }, 500);
|
250 |
});
|
251 |
-
|
252 |
-
event.preventDefault(); // Prevent form submission
|
253 |
});
|
254 |
-
});
|
255 |
-
</script>
|
256 |
-
|
257 |
-
<script>
|
258 |
-
document.addEventListener("DOMContentLoaded", () => {
|
259 |
-
const themeToggle = document.getElementById("themeToggle");
|
260 |
-
const body = document.body;
|
261 |
-
|
262 |
-
// Check local storage for a saved theme, default to dark
|
263 |
-
const savedTheme = localStorage.getItem("theme") || "dark";
|
264 |
-
if (savedTheme === "light") {
|
265 |
-
body.classList.add("light-mode");
|
266 |
-
body.classList.remove("dark-mode");
|
267 |
-
} else {
|
268 |
-
body.classList.add("dark-mode");
|
269 |
-
body.classList.remove("light-mode");
|
270 |
-
}
|
271 |
-
|
272 |
-
updateButton(); // Update button text on load
|
273 |
-
|
274 |
-
// Toggle theme on button click
|
275 |
-
themeToggle.addEventListener("click", () => {
|
276 |
-
if (body.classList.contains("light-mode")) {
|
277 |
-
// Switch to dark mode
|
278 |
-
body.classList.remove("light-mode");
|
279 |
-
body.classList.add("dark-mode");
|
280 |
-
localStorage.setItem("theme", "dark");
|
281 |
-
} else {
|
282 |
-
// Switch to light mode
|
283 |
-
body.classList.remove("dark-mode");
|
284 |
-
body.classList.add("light-mode");
|
285 |
-
localStorage.setItem("theme", "light");
|
286 |
-
}
|
287 |
-
updateButton();
|
288 |
-
});
|
289 |
-
|
290 |
-
function updateButton() {
|
291 |
-
themeToggle.textContent = body.classList.contains("light-mode")
|
292 |
-
? "Switch to Dark Mode"
|
293 |
-
: "Switch to Light Mode";
|
294 |
-
}
|
295 |
-
});
|
296 |
-
|
297 |
-
function showPredictiveText(predictions) {
|
298 |
-
if (predictions.length > 0 && $("#text").val().trim() !== "") {
|
299 |
|
300 |
-
let html = predictions.map(p => `<p>${p}</p>`).join('');
|
301 |
-
$(".predictive-text").html(html).show();
|
302 |
-
} else {
|
303 |
-
$(".predictive-text").hide();
|
304 |
|
305 |
-
|
306 |
-
|
307 |
-
function scrollToBottom() {
|
308 |
-
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
309 |
-
}
|
310 |
-
|
311 |
-
$(document).ready(function() {
|
312 |
-
$("#clearChat").click(function() {
|
313 |
-
$("#messageFormeight").html(""); // Clears the chat area
|
314 |
-
localStorage.removeItem("chatHistory"); // Clears stored history
|
315 |
-
});
|
316 |
-
});
|
317 |
-
|
318 |
-
|
319 |
-
</script>
|
320 |
-
|
321 |
</body>
|
322 |
|
323 |
</html>
|
|
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
<title>JUIT AI Assist</title>
|
8 |
+
<link rel="shortcut icon" href="/static/images/juitlogo.png" type="image/x-icon">
|
9 |
|
10 |
|
11 |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
12 |
+
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
|
|
13 |
|
14 |
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css"
|
15 |
+
integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
|
|
|
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 |
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}" />
|
22 |
|
23 |
<style>
|
24 |
+
|
25 |
</style>
|
26 |
|
27 |
</head>
|
|
|
34 |
<div class="card-header msg_head">
|
35 |
<div class="d-flex bd-highlight">
|
36 |
<div class="img_cont">
|
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 |
+
<button id="themeToggle" class="btn btn-sm btn-light ml-auto">Light Mode</button>
|
47 |
+
|
48 |
+
</div>
|
49 |
</div>
|
50 |
</div>
|
51 |
|
|
|
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 |
+
autocomplete="off" 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"
|
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 |
</a>
|
92 |
</div>
|
93 |
</div>
|
94 |
+
</div>
|
|
|
95 |
</div>
|
96 |
</div>
|
97 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
<script>
|
100 |
+
$(document).ready(function () {
|
101 |
+
// Retrieve chat history from localStorage, or initialize an empty array.
|
102 |
+
let chatHistory = JSON.parse(localStorage.getItem("chatHistory")) || [];
|
103 |
+
let currentIndex = chatHistory.length;
|
104 |
+
|
105 |
+
/* -------------------
|
106 |
+
Predictive Text Setup
|
107 |
+
------------------- */
|
108 |
+
$("#text").on("input", function () {
|
109 |
+
const input = $(this).val().toLowerCase();
|
110 |
+
const predictions = getPredictiveText(input);
|
111 |
+
showPredictiveText(predictions);
|
112 |
+
});
|
113 |
+
|
114 |
+
$(document).on("click", ".predictive-text p", function () {
|
115 |
+
const text = $(this).text();
|
116 |
+
$("#text").val(text);
|
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 |
+
function showPredictiveText(predictions) {
|
139 |
+
if (predictions.length > 0) {
|
140 |
+
let html = "";
|
141 |
+
predictions.forEach(function (prediction) {
|
142 |
+
html += "<p>" + prediction + "</p>";
|
143 |
+
});
|
144 |
+
$(".predictive-text").html(html).show();
|
145 |
+
} else {
|
146 |
+
$(".predictive-text").hide();
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
/* ------------------------------
|
151 |
+
Message Submission and Response
|
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 |
+
Clear Chat Function
|
240 |
+
------------------- */
|
241 |
+
$("#clearChat").click(function () {
|
242 |
+
$("#messageFormeight").html("");
|
243 |
+
chatHistory = [];
|
244 |
+
localStorage.removeItem("chatHistory");
|
245 |
+
currentIndex = 0;
|
246 |
+
});
|
247 |
});
|
248 |
+
</script>
|
249 |
+
|
250 |
|
251 |
+
<script>
|
252 |
+
document.addEventListener("DOMContentLoaded", () => {
|
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 |
+
updateButton();
|
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 |
function showPredictiveText(predictions) {
|
292 |
+
if (predictions.length > 0 && $("#text").val().trim() !== "") {
|
293 |
+
|
294 |
+
let html = predictions.map(p => `<p>${p}</p>`).join('');
|
|
|
|
|
295 |
$(".predictive-text").html(html).show();
|
296 |
} else {
|
297 |
$(".predictive-text").hide();
|
298 |
+
|
299 |
}
|
300 |
}
|
301 |
+
function scrollToBottom() {
|
302 |
+
$("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
|
303 |
+
}
|
304 |
|
305 |
+
$(document).ready(function () {
|
306 |
+
$("#clearChat").click(function () {
|
307 |
+
$("#messageFormeight").html(""); // Clears the chat area
|
308 |
+
localStorage.removeItem("chatHistory"); // Clears stored history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
});
|
|
|
|
|
310 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
|
|
|
|
|
|
|
|
|
312 |
|
313 |
+
</script>
|
314 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
</body>
|
316 |
|
317 |
</html>
|