Adieee5 commited on
Commit
116bfae
·
verified ·
1 Parent(s): c1965eb

Update templates/chat.html

Browse files
Files changed (1) hide show
  1. templates/chat.html +15 -27
templates/chat.html CHANGED
@@ -44,12 +44,16 @@
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>
51
  </div>
52
-
53
  <div id="messageFormeight" class="card-body msg_card_body">
54
  <!-- Chat messages will be displayed here -->
55
  </div>
@@ -68,7 +72,7 @@
68
  </button>
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">
@@ -101,30 +105,24 @@
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
-
105
  // Handle predictive text
106
  $("#text").on("input", function() {
107
  var input = $(this).val().toLowerCase();
108
  var predictions = getPredictiveText(input);
109
  showPredictiveText(predictions);
110
  });
111
-
112
  $(document).on("click", ".predictive-text p", function() {
113
  var text = $(this).text();
114
  $("#text").val(text);
115
  $(".predictive-text").hide();
116
  });
117
-
118
  function getPredictiveText(input) {
119
  var predictions = [];
120
  var patterns = {
121
  "greeting": ["Hi", "Hey", "How are you", "what's up", "Is anyone there?", "Hello", "Good day"],
122
  "name": ["what is your name", "name", "what's your name", "who are you", "what should I call you"]
123
 
124
-
125
-
126
  };
127
-
128
  for (var tag in patterns) {
129
  patterns[tag].forEach(function(pattern) {
130
  if (pattern.toLowerCase().startsWith(input) && !predictions.includes(pattern)) {
@@ -134,7 +132,6 @@
134
  }
135
  return predictions;
136
  }
137
-
138
  function showPredictiveText(predictions) {
139
  if (predictions.length > 0) {
140
  var html = "";
@@ -146,21 +143,17 @@
146
  $(".predictive-text").hide();
147
  }
148
  }
149
-
150
 
151
  // Handle message submission and user input history
152
  $("#messageArea").on("submit", function(event) {
153
  $(".predictive-text").hide(); // Hide predictive suggestions
154
-
155
  const date = new Date();
156
  const hour = date.getHours().toString().padStart(2, '0');
157
  const minute = date.getMinutes().toString().padStart(2, '0');
158
  const str_time = hour + ":" + minute;
159
-
160
  var rawText = $("#text").val();
161
  chatHistory.push(rawText); // Store the user's message in history
162
  currentIndex = chatHistory.length - 1; // Update the current index
163
-
164
  var userHtml = `
165
  <div class="d-flex justify-content-end mb-4">
166
  <div class="msg_container_send">${rawText}
@@ -170,10 +163,8 @@
170
  <img src="/static/images/user.png" class="rounded-circle user_img_msg">
171
  </div>
172
  </div>`;
173
-
174
  $("#text").val(""); // Clear the input field
175
  $("#messageFormeight").append(userHtml); // Add the user message to the chat
176
-
177
  $(document).ready(function () {
178
  let chatHistory = JSON.parse(localStorage.getItem("chatHistory")) || []; // Load stored history
179
  let currentIndex = chatHistory.length; // Set index to last message
@@ -216,7 +207,6 @@
216
  </div>
217
  <div class="msg_container">${response}<span class="msg_time">${time}</span></div>
218
  </div>`;
219
-
220
  $("#messageFormeight").append($.parseHTML(botHtml));
221
  $("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
222
  });
@@ -234,7 +224,6 @@
234
 
235
 
236
 
237
-
238
  // Send the message to the server via AJAX
239
  $.ajax({
240
  data: {
@@ -245,18 +234,15 @@
245
  }).done(function(data) {
246
  var lines = data.split("**");
247
  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">';
248
-
249
  for (var i = 0; i < lines.length; i++) {
250
  botHtml += '<div class="msg_container">' + lines[i] + '</div>';
251
  }
252
  botHtml += '<span class="msg_time">' + str_time + '</span></div></div>';
253
  $("#messageFormeight").append($.parseHTML(botHtml));
254
-
255
  // Smooth scroll to the bottom of the chat
256
  var container = $("#messageFormeight");
257
  container.animate({ scrollTop: container.prop("scrollHeight") }, 500);
258
  });
259
-
260
  event.preventDefault(); // Prevent form submission
261
  });
262
  });
@@ -296,20 +282,22 @@
296
  });
297
 
298
  function updateButton() {
299
- themeToggle.textContent = body.classList.contains("light-mode")
300
- ? "Switch to Dark Mode"
301
- : "Switch to Light Mode";
 
 
 
 
302
  }
303
  });
304
 
305
  function showPredictiveText(predictions) {
306
  if (predictions.length > 0 && $("#text").val().trim() !== "") {
307
-
308
  let html = predictions.map(p => `<p>${p}</p>`).join('');
309
  $(".predictive-text").html(html).show();
310
  } else {
311
  $(".predictive-text").hide();
312
-
313
  }
314
  }
315
  function scrollToBottom() {
 
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
+
 
48
  </div>
49
+ <div class="d-flex flex-column align-items-end ml-auto">
50
+ <button id="themeToggle" class="btn btn-sm btn-light" style="position: static;">Light Mode</button>
51
+
52
+ <button id="clearChat" class="btn btn-danger btn-sm mt-2">Clear Chat</button>
53
+ </div>
54
  </div>
55
  </div>
56
+
57
  <div id="messageFormeight" class="card-body msg_card_body">
58
  <!-- Chat messages will be displayed here -->
59
  </div>
 
72
  </button>
73
  </div>
74
  </form>
75
+
76
 
77
  <div class="card-footer text-center">
78
  <div class="d-flex justify-content-center align-items-center">
 
105
  $(document).ready(function() {
106
  let chatHistory = []; // Stores the user's input history
107
  let currentIndex = -1; // Tracks the current position in the history
 
108
  // Handle predictive text
109
  $("#text").on("input", function() {
110
  var input = $(this).val().toLowerCase();
111
  var predictions = getPredictiveText(input);
112
  showPredictiveText(predictions);
113
  });
 
114
  $(document).on("click", ".predictive-text p", function() {
115
  var text = $(this).text();
116
  $("#text").val(text);
117
  $(".predictive-text").hide();
118
  });
 
119
  function getPredictiveText(input) {
120
  var predictions = [];
121
  var patterns = {
122
  "greeting": ["Hi", "Hey", "How are you", "what's up", "Is anyone there?", "Hello", "Good day"],
123
  "name": ["what is your name", "name", "what's your name", "who are you", "what should I call you"]
124
 
 
 
125
  };
 
126
  for (var tag in patterns) {
127
  patterns[tag].forEach(function(pattern) {
128
  if (pattern.toLowerCase().startsWith(input) && !predictions.includes(pattern)) {
 
132
  }
133
  return predictions;
134
  }
 
135
  function showPredictiveText(predictions) {
136
  if (predictions.length > 0) {
137
  var html = "";
 
143
  $(".predictive-text").hide();
144
  }
145
  }
 
146
 
147
  // Handle message submission and user input history
148
  $("#messageArea").on("submit", function(event) {
149
  $(".predictive-text").hide(); // Hide predictive suggestions
 
150
  const date = new Date();
151
  const hour = date.getHours().toString().padStart(2, '0');
152
  const minute = date.getMinutes().toString().padStart(2, '0');
153
  const str_time = hour + ":" + minute;
 
154
  var rawText = $("#text").val();
155
  chatHistory.push(rawText); // Store the user's message in history
156
  currentIndex = chatHistory.length - 1; // Update the current index
 
157
  var userHtml = `
158
  <div class="d-flex justify-content-end mb-4">
159
  <div class="msg_container_send">${rawText}
 
163
  <img src="/static/images/user.png" class="rounded-circle user_img_msg">
164
  </div>
165
  </div>`;
 
166
  $("#text").val(""); // Clear the input field
167
  $("#messageFormeight").append(userHtml); // Add the user message to the chat
 
168
  $(document).ready(function () {
169
  let chatHistory = JSON.parse(localStorage.getItem("chatHistory")) || []; // Load stored history
170
  let currentIndex = chatHistory.length; // Set index to last message
 
207
  </div>
208
  <div class="msg_container">${response}<span class="msg_time">${time}</span></div>
209
  </div>`;
 
210
  $("#messageFormeight").append($.parseHTML(botHtml));
211
  $("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
212
  });
 
224
 
225
 
226
 
 
227
  // Send the message to the server via AJAX
228
  $.ajax({
229
  data: {
 
234
  }).done(function(data) {
235
  var lines = data.split("**");
236
  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">';
 
237
  for (var i = 0; i < lines.length; i++) {
238
  botHtml += '<div class="msg_container">' + lines[i] + '</div>';
239
  }
240
  botHtml += '<span class="msg_time">' + str_time + '</span></div></div>';
241
  $("#messageFormeight").append($.parseHTML(botHtml));
 
242
  // Smooth scroll to the bottom of the chat
243
  var container = $("#messageFormeight");
244
  container.animate({ scrollTop: container.prop("scrollHeight") }, 500);
245
  });
 
246
  event.preventDefault(); // Prevent form submission
247
  });
248
  });
 
282
  });
283
 
284
  function updateButton() {
285
+ if (body.classList.contains("light-mode")) {
286
+ // Show sun icon when in light mode (indicating you can switch to dark)
287
+ themeToggle.innerHTML = '<i class="fas fa-sun"></i> Dark Mode';
288
+ } else {
289
+ // Show moon icon when in dark mode (indicating you can switch to light)
290
+ themeToggle.innerHTML = '<i class="fas fa-moon"></i> Light Mode';
291
+ }
292
  }
293
  });
294
 
295
  function showPredictiveText(predictions) {
296
  if (predictions.length > 0 && $("#text").val().trim() !== "") {
 
297
  let html = predictions.map(p => `<p>${p}</p>`).join('');
298
  $(".predictive-text").html(html).show();
299
  } else {
300
  $(".predictive-text").hide();
 
301
  }
302
  }
303
  function scrollToBottom() {