-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
320 lines (279 loc) · 10.5 KB
/
index.html
File metadata and controls
320 lines (279 loc) · 10.5 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DeepSearch AI</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg-color: #212121;
--input-bg: #2f2f2f;
--user-msg-bg: #3d3d3d;
--bot-msg-bg: #2f2f2f; /* Box background for bot */
--text-color: #ececec;
--accent-color: #E1A400; /* NEW: Golden/Mustard Yellow */
--border-color: #444;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
font-family: 'Inter', sans-serif;
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
overflow: hidden;
}
/* Chat Layout */
.chat-wrapper {
flex: 1;
overflow-y: auto;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
scroll-behavior: smooth;
}
.chat-container {
width: 100%;
max-width: 768px;
display: flex;
flex-direction: column;
gap: 24px;
padding-bottom: 120px;
}
/* Message Rows */
.message-row {
display: flex;
gap: 16px;
width: 100%;
}
.message-row.user {
justify-content: flex-end;
}
/* Avatar */
.avatar {
width: 32px;
height: 32px;
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 13px;
flex-shrink: 0;
margin-top: 2px; /* Align with text */
}
/* Bot Avatar: Yellow */
.avatar.ai {
background-color: var(--accent-color);
color: #1a1a1a; /* Dark text on yellow background */
}
/* Message Bubbles */
.message-content {
line-height: 1.6;
font-size: 16px;
color: #ececec;
max-width: 100%;
word-wrap: break-word;
}
/* User Message Style */
.user .message-content {
background-color: var(--user-msg-bg);
padding: 12px 18px;
border-radius: 12px;
border-bottom-right-radius: 2px;
max-width: 85%;
}
/* --- BOT STYLES (Dynamic) --- */
/* 1. Default (Thinking State): Faded, no box */
.bot .message-content {
background: none;
padding: 6px 0;
color: #888; /* Faded gray text */
}
/* 2. Final Answer State (Class added via JS): Box style, white text */
.bot .message-content.final-answer {
background-color: var(--bot-msg-bg);
padding: 12px 18px;
border-radius: 12px;
border-top-left-radius: 2px;
color: #ffffff; /* White text */
border: 1px solid #3a3a3a;
}
/* Links */
a { color: #68b5e9; text-decoration: none; border-bottom: 1px solid rgba(104, 181, 233, 0.3); transition: all 0.2s; }
a:hover { border-bottom-color: #68b5e9; }
/* Input Area */
.input-area-wrapper {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: linear-gradient(to top, var(--bg-color) 85%, transparent);
padding: 20px 0 40px 0;
display: flex;
justify-content: center;
}
.input-container {
width: 100%;
max-width: 768px;
background-color: var(--input-bg);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 8px 12px;
display: flex;
align-items: center;
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
margin: 0 20px;
}
.input-container:focus-within { border-color: #666; }
input {
flex: 1;
background: transparent;
border: none;
color: white;
font-size: 16px;
padding: 12px;
outline: none;
font-family: 'Inter', sans-serif;
}
button {
background-color: #ececec;
color: black;
border: none;
padding: 8px 16px;
border-radius: 8px;
cursor: pointer;
font-weight: 600;
transition: opacity 0.2s;
}
button:hover { opacity: 0.8; }
/* Searching Animation UI */
.searching-indicator {
display: flex;
align-items: center;
gap: 12px;
color: #4dabf7; /* Blue text for search state */
font-style: italic;
font-size: 15px;
margin-top: 5px;
}
.pulse-icon {
width: 10px;
height: 10px;
background-color: #4dabf7;
border-radius: 50%;
animation: pulse-animation 1.5s infinite;
}
@keyframes pulse-animation {
0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(77, 171, 247, 0.7); }
70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(77, 171, 247, 0); }
100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(77, 171, 247, 0); }
}
/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
</style>
</head>
<body>
<div class="chat-wrapper" id="scrollContainer">
<div class="chat-container" id="chatBox">
<!-- Welcome Message -->
<div class="message-row bot">
<div class="avatar ai">AI</div>
<!-- Adding 'final-answer' class here so the welcome message looks like a box -->
<div class="message-content final-answer">
Hello! I am <strong>DeepSearch AI</strong>.<br><br>
To search the web, start your message with <code>search</code>.<br>
Example: <em>"search iPhone 16 price"</em>
</div>
</div>
</div>
</div>
<div class="input-area-wrapper">
<div class="input-container">
<input type="text" id="userInput" placeholder="Ask DeepSearch..." autocomplete="off" onkeypress="if(event.key==='Enter') send()">
<button onclick="send()">Send</button>
</div>
</div>
<script>
function scrollToBottom() {
const container = document.getElementById("scrollContainer");
container.scrollTop = container.scrollHeight;
}
async function send() {
const input = document.getElementById("userInput");
const chatBox = document.getElementById("chatBox");
const msg = input.value.trim();
if (!msg) return;
// 1. Add User Message
chatBox.innerHTML += `
<div class="message-row user">
<div class="message-content">${msg}</div>
</div>`;
input.value = "";
scrollToBottom();
// 2. Check for Search Command
const isSearch = msg.toLowerCase().startsWith("search");
const loadingId = "loading-" + Date.now();
// 3. Add "Thinking/Searching" Placeholder
// Note: We DO NOT add the 'final-answer' class yet. It stays faded/transparent.
let loadingHTML = "";
if (isSearch) {
// Special Search UI (User liked this)
loadingHTML = `
<div class="message-row bot" id="${loadingId}">
<div class="avatar ai">AI</div>
<div class="message-content">
<div class="searching-indicator">
<div class="pulse-icon"></div>
<span>Searching the internet...</span>
</div>
</div>
</div>`;
} else {
// Standard Thinking UI (Faded text, no box yet)
loadingHTML = `
<div class="message-row bot" id="${loadingId}">
<div class="avatar ai">AI</div>
<div class="message-content" style="color:#666;">Thinking...</div>
</div>`;
}
chatBox.innerHTML += loadingHTML;
scrollToBottom();
try {
// 4. Fetch from API
const res = await fetch("http://127.0.0.1:8000/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: msg })
});
const data = await res.json();
// 5. Process Response
let botReply = data.reply;
botReply = botReply.replace(/(https?:\/\/[^\s]+)/g, '<a href="$1" target="_blank">$1</a>');
botReply = botReply.replace(/\n/g, '<br>');
// 6. Update UI: Transform "Thinking" to "Box"
const messageRow = document.getElementById(loadingId);
const contentDiv = messageRow.querySelector(".message-content");
// Inject the text
contentDiv.innerHTML = botReply;
// MAGIC STEP: Add the class that turns it into a white box
// This removes the faded styling and applies the box styling
contentDiv.classList.add("final-answer");
// Remove inline style (color: #666) if it exists
contentDiv.style.color = "";
} catch (e) {
const errDiv = document.getElementById(loadingId);
const contentDiv = errDiv.querySelector(".message-content");
contentDiv.innerHTML = "Connection Error: Check backend.";
contentDiv.style.color = "#ff4444";
}
scrollToBottom();
}
</script>
</body>
</html>