Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +222 -204
templates/index.html
CHANGED
@@ -1,204 +1,222 @@
|
|
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">
|
6 |
-
<title>Agent Chat</title>
|
7 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.4/socket.io.js"></script>
|
8 |
-
<style>
|
9 |
-
/* Overall dark theme background */
|
10 |
-
body {
|
11 |
-
background-color: #1a1a2e;
|
12 |
-
color: #eaeaea;
|
13 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
14 |
-
margin: 0;
|
15 |
-
padding: 0;
|
16 |
-
}
|
17 |
-
.container {
|
18 |
-
max-width: 800px;
|
19 |
-
margin: 0 auto;
|
20 |
-
padding: 20px;
|
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 |
-
.bubble
|
72 |
-
|
73 |
-
|
74 |
-
border-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
}
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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">
|
6 |
+
<title>Agent Chat</title>
|
7 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.4/socket.io.js"></script>
|
8 |
+
<style>
|
9 |
+
/* Overall dark theme background */
|
10 |
+
body {
|
11 |
+
background-color: #1a1a2e;
|
12 |
+
color: #eaeaea;
|
13 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
14 |
+
margin: 0;
|
15 |
+
padding: 0;
|
16 |
+
}
|
17 |
+
.container {
|
18 |
+
max-width: 800px;
|
19 |
+
margin: 0 auto;
|
20 |
+
padding: 20px;
|
21 |
+
}
|
22 |
+
header {
|
23 |
+
display: flex;
|
24 |
+
justify-content: space-between;
|
25 |
+
align-items: center;
|
26 |
+
}
|
27 |
+
h1 {
|
28 |
+
margin-bottom: 20px;
|
29 |
+
color: #eaeaea;
|
30 |
+
}
|
31 |
+
.upload-btn {
|
32 |
+
background-color: #007bff;
|
33 |
+
color: #fff;
|
34 |
+
padding: 8px 12px;
|
35 |
+
text-decoration: none;
|
36 |
+
border-radius: 5px;
|
37 |
+
}
|
38 |
+
.upload-btn:hover {
|
39 |
+
background-color: #0056b3;
|
40 |
+
}
|
41 |
+
/* Chat conversation container */
|
42 |
+
.chat-container {
|
43 |
+
background-color: #16213e;
|
44 |
+
border-radius: 8px;
|
45 |
+
padding: 20px;
|
46 |
+
height: 400px;
|
47 |
+
overflow-y: auto;
|
48 |
+
margin-bottom: 20px;
|
49 |
+
}
|
50 |
+
/* Logs container */
|
51 |
+
.logs-container {
|
52 |
+
background-color: #0f3460;
|
53 |
+
border-radius: 8px;
|
54 |
+
padding: 20px;
|
55 |
+
height: 150px;
|
56 |
+
overflow-y: auto;
|
57 |
+
margin-bottom: 20px;
|
58 |
+
}
|
59 |
+
/* Message styling */
|
60 |
+
.message {
|
61 |
+
margin-bottom: 10px;
|
62 |
+
display: flex;
|
63 |
+
align-items: flex-start;
|
64 |
+
}
|
65 |
+
.message.user {
|
66 |
+
justify-content: flex-end;
|
67 |
+
}
|
68 |
+
.message.agent {
|
69 |
+
justify-content: flex-start;
|
70 |
+
}
|
71 |
+
.bubble {
|
72 |
+
max-width: 70%;
|
73 |
+
padding: 10px 15px;
|
74 |
+
border-radius: 15px;
|
75 |
+
line-height: 1.4;
|
76 |
+
word-wrap: break-word;
|
77 |
+
}
|
78 |
+
/* User message bubble style */
|
79 |
+
.bubble.user {
|
80 |
+
background-color: #007bff;
|
81 |
+
color: #fff;
|
82 |
+
border-bottom-right-radius: 0;
|
83 |
+
}
|
84 |
+
/* Agent message bubble style */
|
85 |
+
.bubble.agent {
|
86 |
+
background-color: #2d3a55;
|
87 |
+
color: #fff;
|
88 |
+
border-bottom-left-radius: 0;
|
89 |
+
}
|
90 |
+
/* Log message bubble style */
|
91 |
+
.bubble.log {
|
92 |
+
background-color: #444;
|
93 |
+
color: #ccc;
|
94 |
+
font-size: 0.85rem;
|
95 |
+
border-radius: 5px;
|
96 |
+
padding: 5px 10px;
|
97 |
+
margin: 2px 0;
|
98 |
+
}
|
99 |
+
/* Input area styling */
|
100 |
+
.input-area {
|
101 |
+
display: flex;
|
102 |
+
gap: 10px;
|
103 |
+
}
|
104 |
+
.input-area textarea {
|
105 |
+
flex: 1;
|
106 |
+
padding: 10px;
|
107 |
+
border-radius: 5px;
|
108 |
+
border: none;
|
109 |
+
resize: none;
|
110 |
+
font-size: 1rem;
|
111 |
+
}
|
112 |
+
.input-area button {
|
113 |
+
padding: 10px 20px;
|
114 |
+
border-radius: 5px;
|
115 |
+
border: none;
|
116 |
+
background-color: #007bff;
|
117 |
+
color: #fff;
|
118 |
+
cursor: pointer;
|
119 |
+
}
|
120 |
+
.input-area button:hover {
|
121 |
+
background-color: #0056b3;
|
122 |
+
}
|
123 |
+
</style>
|
124 |
+
</head>
|
125 |
+
<body>
|
126 |
+
<div class="container">
|
127 |
+
<header>
|
128 |
+
<h1>Agent Chat</h1>
|
129 |
+
<!-- Link to the upload page -->
|
130 |
+
<a href="/upload" class="upload-btn">Upload DB</a>
|
131 |
+
</header>
|
132 |
+
<!-- Chat conversation container -->
|
133 |
+
<div class="chat-container" id="chat">
|
134 |
+
<!-- Conversation messages will appear here -->
|
135 |
+
</div>
|
136 |
+
<!-- Logs container -->
|
137 |
+
<div class="logs-container" id="logs">
|
138 |
+
<!-- Log messages will appear here -->
|
139 |
+
</div>
|
140 |
+
<!-- Input area -->
|
141 |
+
<div class="input-area">
|
142 |
+
<textarea id="prompt" rows="2" placeholder="Type your message here..."></textarea>
|
143 |
+
<button id="send">Send</button>
|
144 |
+
</div>
|
145 |
+
</div>
|
146 |
+
|
147 |
+
<script>
|
148 |
+
const socket = io();
|
149 |
+
const chatContainer = document.getElementById("chat");
|
150 |
+
const logsContainer = document.getElementById("logs");
|
151 |
+
const sendButton = document.getElementById("send");
|
152 |
+
const promptTextarea = document.getElementById("prompt");
|
153 |
+
|
154 |
+
// Function to add a chat message bubble
|
155 |
+
function addMessage(sender, text) {
|
156 |
+
const messageDiv = document.createElement("div");
|
157 |
+
messageDiv.classList.add("message", sender);
|
158 |
+
const bubbleDiv = document.createElement("div");
|
159 |
+
bubbleDiv.classList.add("bubble", sender);
|
160 |
+
bubbleDiv.textContent = text;
|
161 |
+
messageDiv.appendChild(bubbleDiv);
|
162 |
+
chatContainer.appendChild(messageDiv);
|
163 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
164 |
+
}
|
165 |
+
|
166 |
+
// Function to add a log message bubble
|
167 |
+
function addLogMessage(text) {
|
168 |
+
const logDiv = document.createElement("div");
|
169 |
+
logDiv.classList.add("bubble", "log");
|
170 |
+
logDiv.textContent = text;
|
171 |
+
logsContainer.appendChild(logDiv);
|
172 |
+
logsContainer.scrollTop = logsContainer.scrollHeight;
|
173 |
+
}
|
174 |
+
|
175 |
+
// Send user's message when "Send" button is clicked
|
176 |
+
sendButton.addEventListener("click", () => {
|
177 |
+
const prompt = promptTextarea.value.trim();
|
178 |
+
if (!prompt) return;
|
179 |
+
addMessage("user", prompt);
|
180 |
+
promptTextarea.value = "";
|
181 |
+
// Send prompt to the server
|
182 |
+
fetch("/generate", {
|
183 |
+
method: "POST",
|
184 |
+
headers: { "Content-Type": "application/json" },
|
185 |
+
body: JSON.stringify({ prompt: prompt })
|
186 |
+
});
|
187 |
+
});
|
188 |
+
|
189 |
+
// Handle streaming tokens for the agent's reply.
|
190 |
+
let agentMessageBubble = null;
|
191 |
+
socket.on("final_stream", (data) => {
|
192 |
+
if (!agentMessageBubble) {
|
193 |
+
// Create agent message bubble if it doesn't exist.
|
194 |
+
const messageDiv = document.createElement("div");
|
195 |
+
messageDiv.classList.add("message", "agent");
|
196 |
+
agentMessageBubble = document.createElement("div");
|
197 |
+
agentMessageBubble.classList.add("bubble", "agent");
|
198 |
+
messageDiv.appendChild(agentMessageBubble);
|
199 |
+
chatContainer.appendChild(messageDiv);
|
200 |
+
}
|
201 |
+
// Append the token to the agent's bubble.
|
202 |
+
agentMessageBubble.textContent += data.message;
|
203 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
204 |
+
});
|
205 |
+
|
206 |
+
// When final answer is complete, ensure the bubble is finalized.
|
207 |
+
socket.on("final", (data) => {
|
208 |
+
if (!agentMessageBubble) {
|
209 |
+
addMessage("agent", data.message);
|
210 |
+
} else {
|
211 |
+
agentMessageBubble.textContent = data.message;
|
212 |
+
agentMessageBubble = null;
|
213 |
+
}
|
214 |
+
});
|
215 |
+
|
216 |
+
// Append log messages as they arrive.
|
217 |
+
socket.on("log", (data) => {
|
218 |
+
addLogMessage(data.message);
|
219 |
+
});
|
220 |
+
</script>
|
221 |
+
</body>
|
222 |
+
</html>
|