Spaces:
Sleeping
Sleeping
Commit
·
65c2f80
1
Parent(s):
8238d28
Upd less technical logs
Browse files- static/script.js +16 -16
- static/styles.css +10 -10
static/script.js
CHANGED
|
@@ -75,7 +75,7 @@
|
|
| 75 |
askBtn.addEventListener('click', handleAsk);
|
| 76 |
questionInput.addEventListener('keypress', (e) => {
|
| 77 |
if (e.key === 'Enter' && !e.shiftKey) {
|
| 78 |
-
|
| 79 |
handleAsk();
|
| 80 |
}
|
| 81 |
});
|
|
@@ -281,7 +281,7 @@
|
|
| 281 |
if (response.ok) {
|
| 282 |
updateProgressStatus('Upload successful! Processing documents...');
|
| 283 |
updateProgressFill(0);
|
| 284 |
-
|
| 285 |
logProgress('Files uploaded successfully');
|
| 286 |
|
| 287 |
// Poll backend for real progress
|
|
@@ -331,28 +331,24 @@
|
|
| 331 |
|
| 332 |
function startUploadStatusPolling(jobId, totalFiles) {
|
| 333 |
let stopped = false;
|
|
|
|
|
|
|
| 334 |
const interval = setInterval(async () => {
|
| 335 |
if (stopped) return;
|
| 336 |
try {
|
| 337 |
const res = await fetch(`/upload/status?job_id=${encodeURIComponent(jobId)}`);
|
| 338 |
-
if (!res.ok) {
|
| 339 |
-
throw new Error('Status not available');
|
| 340 |
-
}
|
| 341 |
const status = await res.json();
|
| 342 |
const percent = Math.max(0, Math.min(100, parseInt(status.percent || 0, 10)));
|
| 343 |
const completed = status.completed || 0;
|
| 344 |
const total = status.total || totalFiles || 1;
|
| 345 |
updateProgressFill(percent);
|
| 346 |
-
updateProgressStatus(`Processing documents
|
| 347 |
-
if (status.last_error) {
|
| 348 |
-
logProgress(`Warning: ${status.last_error}`);
|
| 349 |
-
}
|
| 350 |
if (status.status === 'completed' || percent >= 100) {
|
| 351 |
clearInterval(interval);
|
| 352 |
stopped = true;
|
| 353 |
updateProgressFill(100);
|
| 354 |
updateProgressStatus('Processing complete!');
|
| 355 |
-
logProgress('All documents processed successfully');
|
| 356 |
logProgress('You can now start chatting with your documents');
|
| 357 |
setTimeout(() => hideUploadProgress(), 1500);
|
| 358 |
enableChat();
|
|
@@ -360,9 +356,13 @@
|
|
| 360 |
setTimeout(loadStoredFiles, 1000);
|
| 361 |
}
|
| 362 |
} catch (e) {
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
}
|
| 367 |
}, 1200);
|
| 368 |
}
|
|
@@ -427,7 +427,7 @@
|
|
| 427 |
|
| 428 |
// Add sources if available
|
| 429 |
if (data.sources && data.sources.length > 0) {
|
| 430 |
-
|
| 431 |
}
|
| 432 |
} else {
|
| 433 |
throw new Error(data.detail || 'Failed to get answer');
|
|
@@ -460,7 +460,7 @@
|
|
| 460 |
console.error('Failed to save chat message:', error);
|
| 461 |
}
|
| 462 |
}
|
| 463 |
-
|
| 464 |
function appendMessage(role, text) {
|
| 465 |
const messageDiv = document.createElement('div');
|
| 466 |
messageDiv.className = `msg ${role}`;
|
|
@@ -475,7 +475,7 @@
|
|
| 475 |
|
| 476 |
return messageDiv;
|
| 477 |
}
|
| 478 |
-
|
| 479 |
function appendSources(sources) {
|
| 480 |
const sourcesDiv = document.createElement('div');
|
| 481 |
sourcesDiv.className = 'sources';
|
|
|
|
| 75 |
askBtn.addEventListener('click', handleAsk);
|
| 76 |
questionInput.addEventListener('keypress', (e) => {
|
| 77 |
if (e.key === 'Enter' && !e.shiftKey) {
|
| 78 |
+
e.preventDefault();
|
| 79 |
handleAsk();
|
| 80 |
}
|
| 81 |
});
|
|
|
|
| 281 |
if (response.ok) {
|
| 282 |
updateProgressStatus('Upload successful! Processing documents...');
|
| 283 |
updateProgressFill(0);
|
| 284 |
+
// Friendly, non-technical messages only
|
| 285 |
logProgress('Files uploaded successfully');
|
| 286 |
|
| 287 |
// Poll backend for real progress
|
|
|
|
| 331 |
|
| 332 |
function startUploadStatusPolling(jobId, totalFiles) {
|
| 333 |
let stopped = false;
|
| 334 |
+
let failCount = 0;
|
| 335 |
+
const maxFailsBeforeSilentStop = 30; // ~36s at 1200ms
|
| 336 |
const interval = setInterval(async () => {
|
| 337 |
if (stopped) return;
|
| 338 |
try {
|
| 339 |
const res = await fetch(`/upload/status?job_id=${encodeURIComponent(jobId)}`);
|
| 340 |
+
if (!res.ok) { failCount++; return; }
|
|
|
|
|
|
|
| 341 |
const status = await res.json();
|
| 342 |
const percent = Math.max(0, Math.min(100, parseInt(status.percent || 0, 10)));
|
| 343 |
const completed = status.completed || 0;
|
| 344 |
const total = status.total || totalFiles || 1;
|
| 345 |
updateProgressFill(percent);
|
| 346 |
+
updateProgressStatus(percent >= 100 ? 'Finalizing...' : `Processing documents (${completed}/${total}) · ${percent}%`);
|
|
|
|
|
|
|
|
|
|
| 347 |
if (status.status === 'completed' || percent >= 100) {
|
| 348 |
clearInterval(interval);
|
| 349 |
stopped = true;
|
| 350 |
updateProgressFill(100);
|
| 351 |
updateProgressStatus('Processing complete!');
|
|
|
|
| 352 |
logProgress('You can now start chatting with your documents');
|
| 353 |
setTimeout(() => hideUploadProgress(), 1500);
|
| 354 |
enableChat();
|
|
|
|
| 356 |
setTimeout(loadStoredFiles, 1000);
|
| 357 |
}
|
| 358 |
} catch (e) {
|
| 359 |
+
// Swallow transient errors; update a friendly spinner-like status
|
| 360 |
+
failCount++;
|
| 361 |
+
if (failCount >= maxFailsBeforeSilentStop) {
|
| 362 |
+
clearInterval(interval);
|
| 363 |
+
stopped = true;
|
| 364 |
+
updateProgressStatus('Still working...');
|
| 365 |
+
}
|
| 366 |
}
|
| 367 |
}, 1200);
|
| 368 |
}
|
|
|
|
| 427 |
|
| 428 |
// Add sources if available
|
| 429 |
if (data.sources && data.sources.length > 0) {
|
| 430 |
+
appendSources(data.sources);
|
| 431 |
}
|
| 432 |
} else {
|
| 433 |
throw new Error(data.detail || 'Failed to get answer');
|
|
|
|
| 460 |
console.error('Failed to save chat message:', error);
|
| 461 |
}
|
| 462 |
}
|
| 463 |
+
|
| 464 |
function appendMessage(role, text) {
|
| 465 |
const messageDiv = document.createElement('div');
|
| 466 |
messageDiv.className = `msg ${role}`;
|
|
|
|
| 475 |
|
| 476 |
return messageDiv;
|
| 477 |
}
|
| 478 |
+
|
| 479 |
function appendSources(sources) {
|
| 480 |
const sourcesDiv = document.createElement('div');
|
| 481 |
sourcesDiv.className = 'sources';
|
static/styles.css
CHANGED
|
@@ -51,8 +51,8 @@
|
|
| 51 |
margin: 0;
|
| 52 |
padding: 0;
|
| 53 |
}
|
| 54 |
-
|
| 55 |
-
body {
|
| 56 |
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 57 |
color: var(--text);
|
| 58 |
background: var(--bg);
|
|
@@ -113,7 +113,7 @@ body {
|
|
| 113 |
-webkit-background-clip: text;
|
| 114 |
-webkit-text-fill-color: transparent;
|
| 115 |
background-clip: text;
|
| 116 |
-
|
| 117 |
}
|
| 118 |
|
| 119 |
.logo-text p {
|
|
@@ -349,7 +349,7 @@ body {
|
|
| 349 |
.top-bar-title h2 {
|
| 350 |
font-size: 20px;
|
| 351 |
font-weight: 600;
|
| 352 |
-
|
| 353 |
margin: 0;
|
| 354 |
}
|
| 355 |
|
|
@@ -368,10 +368,10 @@ body {
|
|
| 368 |
|
| 369 |
.content-container {
|
| 370 |
max-width: 1200px;
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
}
|
| 374 |
-
|
| 375 |
/* Project Header */
|
| 376 |
.project-header {
|
| 377 |
display: flex;
|
|
@@ -491,8 +491,8 @@ body {
|
|
| 491 |
}
|
| 492 |
|
| 493 |
/* Cards */
|
| 494 |
-
.card {
|
| 495 |
-
|
| 496 |
border: 1px solid var(--border);
|
| 497 |
border-radius: var(--radius-xl);
|
| 498 |
padding: 32px;
|
|
|
|
| 51 |
margin: 0;
|
| 52 |
padding: 0;
|
| 53 |
}
|
| 54 |
+
|
| 55 |
+
body {
|
| 56 |
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 57 |
color: var(--text);
|
| 58 |
background: var(--bg);
|
|
|
|
| 113 |
-webkit-background-clip: text;
|
| 114 |
-webkit-text-fill-color: transparent;
|
| 115 |
background-clip: text;
|
| 116 |
+
margin: 0;
|
| 117 |
}
|
| 118 |
|
| 119 |
.logo-text p {
|
|
|
|
| 349 |
.top-bar-title h2 {
|
| 350 |
font-size: 20px;
|
| 351 |
font-weight: 600;
|
| 352 |
+
color: var(--text);
|
| 353 |
margin: 0;
|
| 354 |
}
|
| 355 |
|
|
|
|
| 368 |
|
| 369 |
.content-container {
|
| 370 |
max-width: 1200px;
|
| 371 |
+
margin: 0 auto;
|
| 372 |
+
padding: 24px;
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
/* Project Header */
|
| 376 |
.project-header {
|
| 377 |
display: flex;
|
|
|
|
| 491 |
}
|
| 492 |
|
| 493 |
/* Cards */
|
| 494 |
+
.card {
|
| 495 |
+
background: var(--card);
|
| 496 |
border: 1px solid var(--border);
|
| 497 |
border-radius: var(--radius-xl);
|
| 498 |
padding: 32px;
|