Spaces:
Runtime error
Runtime error
DeathDaDev
commited on
Commit
•
dfd6c0b
1
Parent(s):
0686433
feat: create chat interface with live console output section
Browse files- templates/index.html +70 -30
templates/index.html
CHANGED
@@ -1,36 +1,76 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
<head>
|
4 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
</head>
|
6 |
<body>
|
7 |
-
<h1>
|
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 |
</body>
|
36 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Chat Interface</title>
|
7 |
+
<style>
|
8 |
+
#chat-container {
|
9 |
+
display: flex;
|
10 |
+
flex-direction: column;
|
11 |
+
width: 300px;
|
12 |
+
margin: 0 auto;
|
13 |
+
}
|
14 |
+
#chat-box {
|
15 |
+
border: 1px solid #ccc;
|
16 |
+
padding: 10px;
|
17 |
+
height: 200px;
|
18 |
+
overflow-y: scroll;
|
19 |
+
margin-bottom: 10px;
|
20 |
+
}
|
21 |
+
#console-output {
|
22 |
+
border: 1px solid #ccc;
|
23 |
+
padding: 10px;
|
24 |
+
height: 200px;
|
25 |
+
overflow-y: scroll;
|
26 |
+
margin-top: 20px;
|
27 |
+
}
|
28 |
+
</style>
|
29 |
</head>
|
30 |
<body>
|
31 |
+
<h1>Chat Interface</h1>
|
32 |
+
<div id="chat-container">
|
33 |
+
<div id="chat-box"></div>
|
34 |
+
<input type="text" id="chat-input" placeholder="Type your message here...">
|
35 |
+
<button id="send-button">Send</button>
|
36 |
+
</div>
|
37 |
+
<h2>Console Output</h2>
|
38 |
+
<div id="console-output"></div>
|
39 |
+
<script>
|
40 |
+
const chatBox = document.getElementById('chat-box');
|
41 |
+
const chatInput = document.getElementById('chat-input');
|
42 |
+
const sendButton = document.getElementById('send-button');
|
43 |
+
const consoleOutput = document.getElementById('console-output');
|
44 |
+
|
45 |
+
sendButton.addEventListener('click', () => {
|
46 |
+
const message = chatInput.value;
|
47 |
+
if (message) {
|
48 |
+
fetch('/api/generate', {
|
49 |
+
method: 'POST',
|
50 |
+
headers: {
|
51 |
+
'Content-Type': 'application/json'
|
52 |
+
},
|
53 |
+
body: JSON.stringify({ prompt: message })
|
54 |
+
})
|
55 |
+
.then(response => response.json())
|
56 |
+
.then(data => {
|
57 |
+
const responseMessage = document.createElement('div');
|
58 |
+
responseMessage.textContent = `Bot: ${data.response}`;
|
59 |
+
chatBox.appendChild(responseMessage);
|
60 |
+
});
|
61 |
+
const userMessage = document.createElement('div');
|
62 |
+
userMessage.textContent = `You: ${message}`;
|
63 |
+
chatBox.appendChild(userMessage);
|
64 |
+
chatInput.value = '';
|
65 |
+
}
|
66 |
+
});
|
67 |
+
|
68 |
+
const eventSource = new EventSource('/logs');
|
69 |
+
eventSource.onmessage = function(event) {
|
70 |
+
const logMessage = document.createElement('div');
|
71 |
+
logMessage.textContent = event.data;
|
72 |
+
consoleOutput.appendChild(logMessage);
|
73 |
+
};
|
74 |
+
</script>
|
75 |
</body>
|
76 |
</html>
|