Subbu1304 commited on
Commit
6258360
·
verified ·
1 Parent(s): 910a44f

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +29 -7
static/script.js CHANGED
@@ -1,8 +1,30 @@
1
- function sendMessage() {
2
- const input = document.getElementById('user-input').value;
3
- if (input) {
4
- // Send message to Flask server (This would be integrated with Gradio's response mechanism)
5
- // Placeholder for now
6
- alert('Message sent: ' + input);
7
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  }
 
1
+ let state = null;
2
+
3
+ async function sendMessage() {
4
+ let inputText = document.getElementById("user-input").value;
5
+ document.getElementById("user-input").value = "";
6
+ let chatBox = document.getElementById("chat-box");
7
+
8
+ // Display the user's message
9
+ chatBox.innerHTML += `<div>User: ${inputText}</div>`;
10
+
11
+ // Send the message to the Gradio backend (via your Gradio app)
12
+ let response = await fetch("http://localhost:7860/api/predict/", {
13
+ method: "POST",
14
+ headers: {
15
+ "Content-Type": "application/json"
16
+ },
17
+ body: JSON.stringify({
18
+ data: [inputText, state],
19
+ }),
20
+ });
21
+
22
+ let result = await response.json();
23
+ let botMessage = result.data[0];
24
+
25
+ // Display the bot's response
26
+ chatBox.innerHTML += `<div>Bot: ${botMessage}</div>`;
27
+ chatBox.scrollTop = chatBox.scrollHeight;
28
+
29
+ state = result.data[1]; // Update the state for next round
30
  }