Spaces:
Running
Running
Add frontend modification
Browse files- static/search.js +27 -27
- static/styles.css +22 -15
static/search.js
CHANGED
@@ -321,18 +321,15 @@ async function sendMessage() {
|
|
321 |
|
322 |
if (!question || !currentPaperState.pdfUrl) return;
|
323 |
|
324 |
-
const chatMessages = document.getElementById('chatMessages');
|
325 |
-
|
326 |
// Add user message
|
327 |
addMessage(question, true);
|
328 |
|
329 |
-
// Add AI thinking message with
|
330 |
-
const
|
331 |
-
|
332 |
|
333 |
chatInput.value = '';
|
334 |
-
|
335 |
-
|
336 |
try {
|
337 |
const response = await fetch('/chat-with-paper', {
|
338 |
method: 'POST',
|
@@ -348,29 +345,20 @@ async function sendMessage() {
|
|
348 |
|
349 |
const data = await response.json();
|
350 |
|
|
|
|
|
|
|
351 |
if (data.error) {
|
352 |
throw new Error(data.error);
|
353 |
}
|
354 |
|
355 |
-
// Remove thinking message
|
356 |
-
const thinkingMessage = document.getElementById(thinkingMessageId);
|
357 |
-
if (thinkingMessage) {
|
358 |
-
thinkingMessage.remove();
|
359 |
-
}
|
360 |
-
|
361 |
// Add AI response
|
362 |
addMessage(data.response, false);
|
363 |
|
364 |
-
chatMessages.scrollTop = chatMessages.scrollHeight;
|
365 |
-
|
366 |
} catch (error) {
|
367 |
console.error('Chat error:', error);
|
368 |
-
// Remove thinking
|
369 |
-
|
370 |
-
if (thinkingMessage) {
|
371 |
-
thinkingMessage.remove();
|
372 |
-
}
|
373 |
-
|
374 |
addMessage(`Error: ${error.message}`, false);
|
375 |
}
|
376 |
}
|
@@ -763,18 +751,30 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
763 |
});
|
764 |
});
|
765 |
|
766 |
-
function addThinkingMessage() {
|
767 |
const chatMessages = document.getElementById('chatMessages');
|
768 |
const thinkingDiv = document.createElement('div');
|
769 |
-
thinkingDiv.
|
|
|
770 |
thinkingDiv.innerHTML = `
|
771 |
-
<div class="ai-
|
772 |
-
|
773 |
-
<div class="ai-thinking-
|
774 |
-
|
|
|
|
|
|
|
775 |
</div>
|
776 |
`;
|
777 |
chatMessages.appendChild(thinkingDiv);
|
778 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
779 |
return thinkingDiv;
|
780 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
|
322 |
if (!question || !currentPaperState.pdfUrl) return;
|
323 |
|
|
|
|
|
324 |
// Add user message
|
325 |
addMessage(question, true);
|
326 |
|
327 |
+
// Add AI thinking message with unique ID
|
328 |
+
const thinkingId = `thinking-${Date.now()}`;
|
329 |
+
const thinkingDiv = addThinkingMessage(thinkingId);
|
330 |
|
331 |
chatInput.value = '';
|
332 |
+
|
|
|
333 |
try {
|
334 |
const response = await fetch('/chat-with-paper', {
|
335 |
method: 'POST',
|
|
|
345 |
|
346 |
const data = await response.json();
|
347 |
|
348 |
+
// Remove thinking indicator before adding response
|
349 |
+
removeThinkingMessage(thinkingId);
|
350 |
+
|
351 |
if (data.error) {
|
352 |
throw new Error(data.error);
|
353 |
}
|
354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
// Add AI response
|
356 |
addMessage(data.response, false);
|
357 |
|
|
|
|
|
358 |
} catch (error) {
|
359 |
console.error('Chat error:', error);
|
360 |
+
// Remove thinking indicator
|
361 |
+
removeThinkingMessage(thinkingId);
|
|
|
|
|
|
|
|
|
362 |
addMessage(`Error: ${error.message}`, false);
|
363 |
}
|
364 |
}
|
|
|
751 |
});
|
752 |
});
|
753 |
|
754 |
+
function addThinkingMessage(id) {
|
755 |
const chatMessages = document.getElementById('chatMessages');
|
756 |
const thinkingDiv = document.createElement('div');
|
757 |
+
thinkingDiv.id = id;
|
758 |
+
thinkingDiv.className = 'message-wrapper thinking-indicator';
|
759 |
thinkingDiv.innerHTML = `
|
760 |
+
<div class="message-avatar ai-avatar">AI</div>
|
761 |
+
<div class="message ai-message ai-thinking">
|
762 |
+
<div class="ai-thinking-dots">
|
763 |
+
<div class="ai-thinking-dot"></div>
|
764 |
+
<div class="ai-thinking-dot"></div>
|
765 |
+
<div class="ai-thinking-dot"></div>
|
766 |
+
</div>
|
767 |
</div>
|
768 |
`;
|
769 |
chatMessages.appendChild(thinkingDiv);
|
770 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
771 |
return thinkingDiv;
|
772 |
}
|
773 |
+
|
774 |
+
// Add new function to remove thinking message
|
775 |
+
function removeThinkingMessage(id) {
|
776 |
+
const thinkingDiv = document.getElementById(id);
|
777 |
+
if (thinkingDiv) {
|
778 |
+
thinkingDiv.remove();
|
779 |
+
}
|
780 |
+
}
|
static/styles.css
CHANGED
@@ -725,14 +725,17 @@ body {
|
|
725 |
display: flex;
|
726 |
align-items: center;
|
727 |
padding: 0.8rem 1.2rem;
|
728 |
-
background:
|
729 |
border-radius: 12px;
|
730 |
-
|
731 |
}
|
732 |
|
733 |
.ai-thinking-dots {
|
734 |
display: flex;
|
735 |
gap: 4px;
|
|
|
|
|
|
|
736 |
}
|
737 |
|
738 |
.ai-thinking-dot {
|
@@ -741,20 +744,18 @@ body {
|
|
741 |
background: var(--primary-color);
|
742 |
border-radius: 50%;
|
743 |
animation: thinking 1.4s infinite ease-in-out;
|
|
|
744 |
}
|
745 |
|
746 |
-
|
747 |
-
.ai-thinking-dot:nth-child(2) { animation-delay: 0.2s; }
|
748 |
-
.ai-thinking-dot:nth-child(3) { animation-delay: 0.4s; }
|
749 |
-
|
750 |
@keyframes thinking {
|
751 |
0%, 80%, 100% {
|
752 |
-
transform: scale(0.
|
753 |
opacity: 0.3;
|
754 |
}
|
755 |
40% {
|
756 |
transform: scale(1);
|
757 |
-
opacity:
|
758 |
}
|
759 |
}
|
760 |
|
@@ -2233,18 +2234,26 @@ body {
|
|
2233 |
}
|
2234 |
|
2235 |
/* AI Thinking Indicator */
|
|
|
|
|
|
|
|
|
|
|
2236 |
.ai-thinking {
|
2237 |
display: flex;
|
2238 |
align-items: center;
|
2239 |
padding: 0.8rem 1.2rem;
|
2240 |
background: rgba(30, 27, 46, 0.4);
|
2241 |
border-radius: 12px;
|
2242 |
-
|
2243 |
}
|
2244 |
|
2245 |
.ai-thinking-dots {
|
2246 |
display: flex;
|
2247 |
gap: 4px;
|
|
|
|
|
|
|
2248 |
}
|
2249 |
|
2250 |
.ai-thinking-dot {
|
@@ -2253,19 +2262,17 @@ body {
|
|
2253 |
background: var(--primary-color);
|
2254 |
border-radius: 50%;
|
2255 |
animation: thinking 1.4s infinite ease-in-out;
|
|
|
2256 |
}
|
2257 |
|
2258 |
-
|
2259 |
-
.ai-thinking-dot:nth-child(2) { animation-delay: 0.2s; }
|
2260 |
-
.ai-thinking-dot:nth-child(3) { animation-delay: 0.4s; }
|
2261 |
-
|
2262 |
@keyframes thinking {
|
2263 |
0%, 80%, 100% {
|
2264 |
-
transform: scale(0.
|
2265 |
opacity: 0.3;
|
2266 |
}
|
2267 |
40% {
|
2268 |
transform: scale(1);
|
2269 |
-
opacity:
|
2270 |
}
|
2271 |
}
|
|
|
725 |
display: flex;
|
726 |
align-items: center;
|
727 |
padding: 0.8rem 1.2rem;
|
728 |
+
background: rgba(30, 27, 46, 0.4);
|
729 |
border-radius: 12px;
|
730 |
+
min-width: 80px;
|
731 |
}
|
732 |
|
733 |
.ai-thinking-dots {
|
734 |
display: flex;
|
735 |
gap: 4px;
|
736 |
+
justify-content: center;
|
737 |
+
align-items: center;
|
738 |
+
height: 24px;
|
739 |
}
|
740 |
|
741 |
.ai-thinking-dot {
|
|
|
744 |
background: var(--primary-color);
|
745 |
border-radius: 50%;
|
746 |
animation: thinking 1.4s infinite ease-in-out;
|
747 |
+
opacity: 0.7;
|
748 |
}
|
749 |
|
750 |
+
/* Smoother animation for dots */
|
|
|
|
|
|
|
751 |
@keyframes thinking {
|
752 |
0%, 80%, 100% {
|
753 |
+
transform: scale(0.6);
|
754 |
opacity: 0.3;
|
755 |
}
|
756 |
40% {
|
757 |
transform: scale(1);
|
758 |
+
opacity: 0.8;
|
759 |
}
|
760 |
}
|
761 |
|
|
|
2234 |
}
|
2235 |
|
2236 |
/* AI Thinking Indicator */
|
2237 |
+
.thinking-indicator {
|
2238 |
+
opacity: 0.7;
|
2239 |
+
transition: all 0.3s ease;
|
2240 |
+
}
|
2241 |
+
|
2242 |
.ai-thinking {
|
2243 |
display: flex;
|
2244 |
align-items: center;
|
2245 |
padding: 0.8rem 1.2rem;
|
2246 |
background: rgba(30, 27, 46, 0.4);
|
2247 |
border-radius: 12px;
|
2248 |
+
min-width: 80px;
|
2249 |
}
|
2250 |
|
2251 |
.ai-thinking-dots {
|
2252 |
display: flex;
|
2253 |
gap: 4px;
|
2254 |
+
justify-content: center;
|
2255 |
+
align-items: center;
|
2256 |
+
height: 24px;
|
2257 |
}
|
2258 |
|
2259 |
.ai-thinking-dot {
|
|
|
2262 |
background: var(--primary-color);
|
2263 |
border-radius: 50%;
|
2264 |
animation: thinking 1.4s infinite ease-in-out;
|
2265 |
+
opacity: 0.7;
|
2266 |
}
|
2267 |
|
2268 |
+
/* Smoother animation for dots */
|
|
|
|
|
|
|
2269 |
@keyframes thinking {
|
2270 |
0%, 80%, 100% {
|
2271 |
+
transform: scale(0.6);
|
2272 |
opacity: 0.3;
|
2273 |
}
|
2274 |
40% {
|
2275 |
transform: scale(1);
|
2276 |
+
opacity: 0.8;
|
2277 |
}
|
2278 |
}
|