WebashalarForML commited on
Commit
d7c11cc
·
verified ·
1 Parent(s): 142c7dc

Update templates/index.html

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