forked from prajwalcordiero/SoftWizz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex2.html
More file actions
79 lines (65 loc) · 2.7 KB
/
index2.html
File metadata and controls
79 lines (65 loc) · 2.7 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VNS - Workforce Query</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h2>Soft_Wizz: Workforce Query</h2>
<div id="chat-container">
<div id="output"></div>
<textarea id="prompt" placeholder="Ask something like 'Show all employees in HR' or 'Update status of employee 2'"></textarea><br>
<button onclick="sendPrompt()">Send</button>
</div>
<script>
async function sendPrompt() {
const prompt = document.getElementById('prompt').value;
const outputDiv = document.getElementById('output');
// Append the user's prompt as a chat bubble
outputDiv.innerHTML += `<div class="chat-bubble user">${prompt}</div>`;
document.getElementById('prompt').value = ''; // Clear input after sending
// Ensure chat container scrolls down
outputDiv.scrollTop = outputDiv.scrollHeight;
const response = await fetch('http://127.0.0.1:8000/query', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt: prompt })
});
const data = await response.json();
// Handle the response from the API
if (data.columns && data.result) {
outputDiv.innerHTML += createTable(data.columns, data.result);
}
if (data.response) {
outputDiv.innerHTML += `<div class="chat-bubble ai">${data.response}</div>`;
}
if (data.error) {
outputDiv.innerHTML += `<div class="chat-bubble ai">${data.error}</div>`;
}
if (data.query) {
outputDiv.innerHTML += `<div class="chat-bubble ai">${data.query}</div>`;
}
// Ensure chat container scrolls down after response
outputDiv.scrollTop = outputDiv.scrollHeight;
}
function createTable(columns, rows) {
let html = '<table><thead><tr>';
for (let col of columns) {
html += `<th>${col}</th>`;
}
html += '</tr></thead><tbody>';
for (let row of rows) {
html += '<tr>';
for (let cell of row) {
html += `<td>${cell !== null ? cell : ''}</td>`;
}
html += '</tr>';
}
html += '</tbody></table>';
return html;
}
</script>
</body>
</html>