Updated index.html
Browse files- index.html +94 -16
index.html
CHANGED
|
@@ -1,19 +1,97 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<link rel="stylesheet" href="style.css">
|
| 5 |
+
<script src="client.js" type="module"></script>
|
| 6 |
+
</head>
|
| 7 |
+
<body>
|
| 8 |
+
|
| 9 |
+
<div class="ai-assistant-container" id="aiAssistant">
|
| 10 |
+
<img src="bP.png" alt="AI Assistant Avatar" class="assistant-avatar" id="net-ai">
|
| 11 |
+
|
| 12 |
+
<!-- Chat Bubble (Text Area) -->
|
| 13 |
+
<div class="chat-bubble" id="net">
|
| 14 |
+
<p>Hello! I am your plnb assistant, how may I help you?
|
| 15 |
+
<ol><li>Please dblclick to clear the contents!</li></ol>
|
| 16 |
+
</p>
|
| 17 |
+
<textarea rows="3" cols="35" id="console" style="display:none" >
|
| 18 |
+
</textarea>
|
| 19 |
+
</div>
|
| 20 |
+
|
| 21 |
+
</div>
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
<script type="module">
|
| 26 |
+
|
| 27 |
+
import {client} from "./client.js";
|
| 28 |
+
const consoleArea = document.getElementById('console');
|
| 29 |
+
async function call_api(message){
|
| 30 |
+
//We should be hitting the api server first and get the relavant context to the question
|
| 31 |
+
let static_context="menu items for the lunch are dal and roti. menu items for breakfast are idli and dosa, menu item for dinner is pizza and pasta";
|
| 32 |
+
message="Context: " + static_context + "Question:" + message;
|
| 33 |
+
console.log("message is: " + message);
|
| 34 |
+
const result = await client.predict("/chat", {
|
| 35 |
+
message: message, // User input
|
| 36 |
+
});
|
| 37 |
+
let resp = result.data;
|
| 38 |
+
console.log(resp); // AI response
|
| 39 |
+
//let's repopulate the text box with the result
|
| 40 |
+
consoleArea.value = resp;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
//for the AI assistant
|
| 45 |
+
// Get elements by their IDs/classes
|
| 46 |
+
//const assistantAvatar = document.querySelector('.assistant-avatar');
|
| 47 |
+
//const chatBubble = document.querySelector('.chat-bubble');
|
| 48 |
+
const assistantAvatar = document.getElementById('net-ai');
|
| 49 |
+
const chatBubble = document.getElementById('net');
|
| 50 |
+
const aiChatArea = document.getElementById("console");
|
| 51 |
+
// Add a click event listener to the avatar
|
| 52 |
+
assistantAvatar.addEventListener('click', () => {
|
| 53 |
+
// Toggle the display style to show or hide the chat bubble
|
| 54 |
+
if (chatBubble.style.display === 'none' || chatBubble.style.display === '') {
|
| 55 |
+
chatBubble.style.display = 'block';
|
| 56 |
+
aiChatArea.style.display = "block";
|
| 57 |
+
//AiResults.style.display = "block";
|
| 58 |
+
} else {
|
| 59 |
+
chatBubble.style.display = 'none';
|
| 60 |
+
aiChatArea.style.display = "none";
|
| 61 |
+
//AiResults.style.display = "none";
|
| 62 |
+
}
|
| 63 |
+
console.log("Is the button clicked!! net-ai");
|
| 64 |
+
//we have to call the language model from this chat
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
});
|
| 68 |
+
|
| 69 |
+
// Add a keydown event listener to the chat console area of the chat bublle
|
| 70 |
+
consoleArea.addEventListener('keydown', function(event) {
|
| 71 |
+
//clear the existing text
|
| 72 |
+
|
| 73 |
+
// Check if the key pressed is the 'Enter' key
|
| 74 |
+
if (event.key === 'Enter') {
|
| 75 |
+
//not sure if we need below to prevent the default behaviour
|
| 76 |
+
event.preventDefault();
|
| 77 |
+
console.log('Enter key pressed! Perform action.');
|
| 78 |
+
//get the entered value
|
| 79 |
+
let command = consoleArea.value;
|
| 80 |
+
call_api(command);
|
| 81 |
+
consoleArea.value = "";//null the value
|
| 82 |
+
}
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
//adding a double click event to clear the contents for next question
|
| 86 |
+
consoleArea.addEventListener('dblclick', function(event) {
|
| 87 |
+
console.log("am i double clicked!!");
|
| 88 |
+
consoleArea.value = ""; //clearning for next question
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
</script>
|
| 92 |
+
|
| 93 |
+
</body>
|
| 94 |
</html>
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|