prasanth345 commited on
Commit
4a17e5d
·
verified ·
1 Parent(s): 9da352a

Create script.js

Browse files
Files changed (1) hide show
  1. static/script.js +38 -0
static/script.js ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.addEventListener('DOMContentLoaded', () => {
2
+ const chatHistory = document.getElementById('chat-history');
3
+ const userInput = document.getElementById('user-input');
4
+ const sendButton = document.getElementById('send-button');
5
+ const voiceChatButton = document.getElementById('voice-chat');
6
+
7
+ // Function to update chat history
8
+ function updateChatHistory(message) {
9
+ const messageDiv = document.createElement('div');
10
+ messageDiv.textContent = message;
11
+ chatHistory.appendChild(messageDiv);
12
+ }
13
+
14
+ // Handle sending messages
15
+ sendButton.addEventListener('click', async () => {
16
+ const input = userInput.value.trim();
17
+ if (input) {
18
+ updateChatHistory(`You: ${input}`);
19
+ userInput.value = '';
20
+ // Call the backend API to generate response
21
+ const response = await fetch('/generate_text', {
22
+ method: 'POST',
23
+ headers: {
24
+ 'Content-Type': 'application/json',
25
+ },
26
+ body: JSON.stringify({ input_text: input }),
27
+ });
28
+ const data = await response.json();
29
+ updateChatHistory(`Assistant: ${data}`);
30
+ }
31
+ });
32
+
33
+ // Handle voice chat
34
+ voiceChatButton.addEventListener('click', () => {
35
+ // Implementation for voice chat functionality
36
+ // Example: Start recording voice and send it to the backend for processing
37
+ });
38
+ });