File size: 16,419 Bytes
cfe1b75
 
 
 
 
 
 
b7bce57
d43574d
b7bce57
d43574d
 
1726806
 
d43574d
cfe1b75
1726806
 
cfe1b75
 
 
 
 
b7bce57
cfe1b75
 
1726806
cfe1b75
 
 
 
 
 
0382f8f
 
cfe1b75
 
 
 
0382f8f
cfe1b75
 
1726806
5374c4d
 
0382f8f
5374c4d
0382f8f
116bfae
 
0382f8f
cfe1b75
 
116bfae
cfe1b75
 
 
 
d43574d
 
1726806
5374c4d
5400ea9
1726806
 
 
cfe1b75
d43574d
 
 
cfe1b75
 
116bfae
1726806
5400ea9
 
9195001
5400ea9
1726806
5400ea9
 
 
 
 
1726806
5400ea9
 
 
 
 
 
 
 
 
1726806
 
cfe1b75
 
 
1726806
cfe1b75
1726806
 
 
 
 
 
 
 
 
 
 
 
 
 
eaf64a8
1726806
 
 
 
 
 
 
 
 
 
 
 
 
eaf64a8
1726806
 
eaf64a8
1726806
 
 
 
 
eaf64a8
 
 
 
 
5374c4d
1726806
 
 
 
 
 
 
 
 
 
 
0382f8f
 
 
 
 
 
 
 
1726806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0382f8f
 
 
 
 
 
1726806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15ad818
1726806
15ad818
 
 
0382f8f
15ad818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5374c4d
15ad818
 
5374c4d
15ad818
5374c4d
1726806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cfe1b75
1726806
 
 
 
cfe1b75
1726806
 
 
 
116bfae
 
 
 
 
 
 
cfe1b75
1726806
 
 
 
 
 
 
 
5374c4d
1726806
 
 
 
 
 
 
 
 
cfe1b75
1726806
 
 
 
 
cfe1b75
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JUIT AI Assist</title>
    <link rel="shortcut icon" href="/static/images/juit.png" type="image/x-icon">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
      integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
      crossorigin="anonymous">

    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css"
        integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU"
        crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };
    </script>
    <script defer src="/_vercel/insights/script.js"></script>
    <link rel="stylesheet" type="text/css" href="static/style.css" />

    <style>
       
    </style>

</head>

<body>
    <div class="container-fluid h-100">
        <div class="row no-gutters h-100">
            <div class=" chat">
                <div class="card">
                    <div class="card-header msg_head">
                        <div class="d-flex bd-highlight">
                            <div class="img_cont">
                                <img src="/static/images/juit.png" class="rounded-circle user_img">
                                <span class="online_icon"></span>
                            </div>
                            
                            <div class="user_info">
                                <span>JUIT AI Assist</span>
                                <p font-size="200px">Explore College and Beyond: Ask Anything! 🎓</p>
                            </div>
                            <div class="d-flex flex-row align-items-baseline ml-auto">
                                <button id="themeToggle" class="btn btn-sm btn-light" style="position: static;">Light Mode</button>
                                <button id="clearChat" class="btn btn-danger btn-sm mt-2">Clear Chat</button>
                            </div>
                        </div>
                    </div>
                 
                    <div id="messageFormeight" class="card-body msg_card_body">
                        <!-- Chat messages will be displayed here -->
                    </div>
                    <div class="card-footer" style="position: relative;">
                        <form id="messageArea" class="input-group" style="position: relative;">
                            <!-- Predictive Text Suggestions (ADD THIS HERE) -->
                            <div class="predictive-text" style="position: absolute; display: none; z-index: 1000; width: 100%;"></div>


                        
                            <input type="text" id="text" name="msg" placeholder="Type your message..." autocomplete="off"
                                class="form-control type_msg" required />
                            <div class="input-group-append">
                                <button type="submit" id="send" class="input-group-text send_btn">
                                    <i class="fas fa-location-arrow"></i>
                                </button>
                            </div>
                        </form>
                     
                        
                        <div class="card-footer text-center">
                            <div class="d-flex justify-content-center align-items-center">
                                <span class="mr-2">Developed by:</span>
                                <span class="mr-2">Ramandeep Singh Makkar</span>
                                <a href="https://www.linkedin.com/in/ramandeep-singh-makkar/" target="_blank" class="mr-2">
                                    <i class="fab fa-linkedin"></i>
                                </a>
                                <a href="mailto:[email protected]" class="mr-3">
                                    <i class="fas fa-envelope"></i>
                                </a>
                        
                                <span class="mr-2">Aditya Singh</span>
                                <a href="https://www.linkedin.com/in/aditsg26/" target="_blank" class="mr-2">
                                    <i class="fab fa-linkedin"></i>
                                </a>
                                <a href="mailto:[email protected]">
                                    <i class="fas fa-envelope"></i>
                                </a>
                            </div>
                        </div>
                        
                    
                </div>
            </div>
        </div>
    </div>

    <script>
        $(document).ready(function() {
            let chatHistory = []; // Stores the user's input history
            let currentIndex = -1; // Tracks the current position in the history
            // Handle predictive text
            $("#text").on("input", function() {
                var input = $(this).val().toLowerCase();
                var predictions = getPredictiveText(input);
                showPredictiveText(predictions);
            });
            $(document).on("click", ".predictive-text p", function() {
                var text = $(this).text();
                $("#text").val(text);
                $(".predictive-text").hide();
            });
            function getPredictiveText(input) {
                var predictions = [];
                var patterns = {
                    "greeting": ["Hi", "Hey", "How are you", "what's up", "Is anyone there?", "Hello", "Good day"],
                    "name": ["what is your name", "name", "what's your name", "who are you", "what should I call you"]
                  
                };
                for (var tag in patterns) {
                    patterns[tag].forEach(function(pattern) {
                        if (pattern.toLowerCase().startsWith(input) && !predictions.includes(pattern)) {
                            predictions.push(pattern);
                        }
                    });
                }
                return predictions;
            }
            function showPredictiveText(predictions) {
                if (predictions.length > 0) {
                    var html = "";
                    predictions.forEach(function(prediction) {
                        html += "<p>" + prediction + "</p>";
                    });
                    $(".predictive-text").html(html).show();
                } else {
                    $(".predictive-text").hide();
                }
            }
            
            // Handle message submission and user input history
            $("#messageArea").on("submit", function(event) {
                $(".predictive-text").hide(); // Hide predictive suggestions
                const date = new Date();
                const hour = date.getHours().toString().padStart(2, '0');
                const minute = date.getMinutes().toString().padStart(2, '0');
                const str_time = hour + ":" + minute;
                var rawText = $("#text").val();
                chatHistory.push(rawText); // Store the user's message in history
                currentIndex = chatHistory.length - 1; // Update the current index
                var userHtml = `
                    <div class="d-flex justify-content-end mb-4">
                        <div class="msg_container_send">${rawText}
                            <span class="msg_time_send">${str_time}</span>
                        </div>
                        <div class="img_cont_msg">
                            <img src="/static/images/user.png" class="rounded-circle user_img_msg">
                        </div>
                    </div>`;
                $("#text").val(""); // Clear the input field
                $("#messageFormeight").append(userHtml); // Add the user message to the chat
                $(document).ready(function () {
                    let chatHistory = JSON.parse(localStorage.getItem("chatHistory")) || []; // Load stored history
                    let currentIndex = chatHistory.length; // Set index to last message
                
                    $("#messageArea").on("submit", function (event) {
                        event.preventDefault(); // Prevent form submission
                
                        let rawText = $("#text").val().trim();
                        if (rawText === "") return; // Ignore empty input
                
                        const time = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
                
                        // Append user message to chat
                        let userHtml = `
                            <div class="d-flex justify-content-end mb-4">
                                <div class="msg_container_send">${rawText}<span class="msg_time_send">${time}</span></div>
                                <div class="img_cont_msg"><img src="https://i.ibb.co/d5b84Xw/Untitled-design.png" class="rounded-circle user_img_msg"></div>
                            </div>`;
                        $("#messageFormeight").append(userHtml);
                
                        // Update chat history
                        chatHistory.push(rawText);
                        localStorage.setItem("chatHistory", JSON.stringify(chatHistory)); // Save in localStorage
                        currentIndex = chatHistory.length; // Reset index to end
                
                        // Clear input field & scroll down
                        $("#text").val("");
                        $("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
                
                        // Send message to server
                        $.ajax({
                            data: { msg: rawText },
                            type: "POST",
                            url: "/get",
                        }).done(function (response) {
                            let botHtml = `
                            <div class="d-flex justify-content-start mb-4">
                                <div class="img_cont_msg">
                                    <img src="/static/images/juit.png" class="rounded-circle user_img_msg">
                                </div>
                                <div class="msg_container">${response}<span class="msg_time">${time}</span></div>
                            </div>`;
                            $("#messageFormeight").append($.parseHTML(botHtml));
                            $("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
                        });
                    });
                
                    // Clear chat history
                    $("#clearChat").click(function () {
                        $("#messageFormeight").html(""); // Clears UI
                        chatHistory = []; // Clears array
                        localStorage.removeItem("chatHistory"); // Clears from storage
                        currentIndex = 0;
                    });
                });
              
                // Send the message to the server via AJAX
                $.ajax({
                    data: {
                        msg: rawText,
                    },
                    type: "POST",
                    url: "/get",
                }).done(function(data) {
                    // --- Typewriter effect for bot response START ---
                    var lines = data.split("**");
                    var fullText = lines.join(' ');
                    // Create the container for the bot message
                    var botContainer = $('<div class="d-flex justify-content-start mb-4"></div>');
                    var imgDiv = $('<div class="img_cont_msg"><img src="/static/images/juit.png" class="rounded-circle user_img_msg"></div>');
                    var msgDiv = $('<div class="msg_container"></div>');
                    botContainer.append(imgDiv);
                    botContainer.append(msgDiv);
                    $("#messageFormeight").append(botContainer);
                    var i = 0;
                    function typeWriter() {
                        if (i < fullText.length) {
                            var charSpan = $('<span style="opacity: 0;">' + fullText.charAt(i) + '</span>'); 
                            msgDiv.append(charSpan); // Append the character
                            
                            charSpan.animate({ opacity: 1 }, 150); // Fade-in effect
                            i++;
                            setTimeout(typeWriter, 15); // Adjust delay as needed
                        } else {
                            msgDiv.append('<span class="msg_time">' + str_time + '</span>');
                            
                            // Smooth scroll to the bottom of the chat
                            var container = $("#messageFormeight");
                            container.animate({ scrollTop: container.prop("scrollHeight") }, 500);
                        }
                    }
                    typeWriter();
                    // --- Typewriter effect for bot response END ---
                });
                event.preventDefault();
            });
        });
    </script>
   
    <script>
        document.addEventListener("DOMContentLoaded", () => {
            const themeToggle = document.getElementById("themeToggle");
            const body = document.body;
        
            // Check local storage for a saved theme, default to dark
            const savedTheme = localStorage.getItem("theme") || "dark";
            if (savedTheme === "light") {
                body.classList.add("light-mode");
                body.classList.remove("dark-mode");
            } else {
                body.classList.add("dark-mode");
                body.classList.remove("light-mode");
            }
        
            updateButton(); // Update button text on load
        
            // Toggle theme on button click
            themeToggle.addEventListener("click", () => {
                if (body.classList.contains("light-mode")) {
                    // Switch to dark mode
                    body.classList.remove("light-mode");
                    body.classList.add("dark-mode");
                    localStorage.setItem("theme", "dark");
                } else {
                    // Switch to light mode
                    body.classList.remove("dark-mode");
                    body.classList.add("light-mode");
                    localStorage.setItem("theme", "light");
                }
                updateButton();
            });
        
            function updateButton() {
                if (body.classList.contains("light-mode")) {
                    // Show sun icon when in light mode (indicating you can switch to dark)
                    themeToggle.innerHTML = '<i class="fas fa-sun"></i> Dark Mode';
                } else {
                    // Show moon icon when in dark mode (indicating you can switch to light)
                    themeToggle.innerHTML = '<i class="fas fa-moon"></i> Light Mode';
                }
            }
        });
        
        function showPredictiveText(predictions) {
            if (predictions.length > 0 && $("#text").val().trim() !== "") {
                let html = predictions.map(p => `<p>${p}</p>`).join('');
                $(".predictive-text").html(html).show();
            } else {
                $(".predictive-text").hide();
            }
        }
        function scrollToBottom() {
            $("#messageFormeight").animate({ scrollTop: $("#messageFormeight")[0].scrollHeight }, 500);
        }
                
        $(document).ready(function() {
            $("#clearChat").click(function() {
                $("#messageFormeight").html(""); // Clears the chat area
                localStorage.removeItem("chatHistory"); // Clears stored history
            });
        });
        
        
    </script>
    
</body>

</html>