Spaces:
Running
Running
File size: 18,801 Bytes
fc3bf2a 4e10575 fc3bf2a 4e10575 fc3bf2a 0333b18 fc3bf2a 0333b18 fc3bf2a ee1b1b5 fc3bf2a ee1b1b5 fc3bf2a 14f16a2 fc3bf2a 0333b18 0ee86b0 fc3bf2a 4e10575 fc3bf2a 14f16a2 fc3bf2a 14f16a2 fc3bf2a d0eeb77 fc3bf2a 14f16a2 fc3bf2a 14f16a2 fc3bf2a 14f16a2 fc3bf2a | 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 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Technology Transactions Assistant - Document Upload</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Rounded', 'SF Pro Display', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: #001122;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
color: #fff;
}
.header-section {
width: 100%;
max-width: 800px;
background: #333;
border-radius: 20px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
text-align: center;
}
.header-title {
color: #fff;
font-size: 2.5rem;
font-weight: 500;
text-decoration: underline;
text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
text-align: center;
margin: 10px;
}
.header-subtitle {
color: #ccc;
font-size: 0.85rem;
font-weight: 400;
font-style: italic;
margin: 5px;
}
.upload-container {
width: 100%;
max-width: 800px;
background: #333;
border-radius: 20px;
padding: 40px;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
align-items: center;
gap: 25px;
}
.upload-title {
color: #ccc;
font-size: 1.8rem;
font-weight: 500;
text-align: center;
text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
margin-bottom: 10px;
}
.upload-description {
color: #ccc;
font-size: 1rem;
text-align: center;
margin-bottom: 20px;
line-height: 1.5;
}
.upload-area {
width: 100%;
border: 3px dashed #555;
border-radius: 15px;
padding: 40px 20px;
text-align: center;
background: #222;
transition: all 0.3s ease;
cursor: pointer;
position: relative;
}
.upload-area:hover {
border-color: #7ec8ff;
background: #2a2a2a;
}
.upload-area.dragover {
border-color: #7ec8ff;
background: #2a2a2a;
transform: scale(1.02);
}
.upload-icon {
font-size: 3rem;
color: #555;
margin-bottom: 15px;
}
.upload-text {
color: #ccc;
font-size: 1rem;
margin-bottom: 10px;
}
.upload-subtext {
color: #888;
font-size: 0.9rem;
}
.file-input {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
}
.selected-file {
display: none;
background: #222;
border: 2px solid #555;
border-radius: 10px;
padding: 15px;
width: 100%;
margin-top: 20px;
}
.selected-file.visible {
display: block;
}
.file-info {
display: flex;
align-items: center;
gap: 10px;
color: #fff;
}
.file-name {
font-weight: 600;
}
.file-size {
color: #ccc;
font-size: 0.9rem;
}
.remove-file {
margin-left: auto;
background: rgba(255,102,102,0.45);
color: #fff;
border: none;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
font-size: 0.8rem;
}
.remove-file:hover {
background: rgba(255,102,102,0.60);
}
.upload-button {
background: #7ec8ff;
color: #001122;
border: none;
padding: 14px 30px;
border-radius: 10px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
letter-spacing: 1px;
margin: 10px auto 0;
display: none;
align-self: center;
}
.upload-button.visible {
display: block;
}
.upload-button:hover {
background: #6bb8ff;
transform: translateY(-2px);
box-shadow: 0 8px 18px rgba(126, 200, 255, 0.3);
}
.upload-button:active {
transform: translateY(0);
}
.upload-button:disabled {
background: #555;
color: #999;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.progress-container {
width: 100%;
background: #222;
border-radius: 10px;
overflow: hidden;
margin-top: 20px;
display: none;
}
.progress-container.visible {
display: block;
}
.progress-bar {
height: 6px;
background: #7ec8ff;
width: 0%;
transition: width 0.3s ease;
}
.progress-text {
padding: 10px;
text-align: center;
color: #ccc;
font-size: 0.9rem;
}
.upload-result {
display: none;
padding: 20px;
border-radius: 10px;
margin-top: 20px;
text-align: center;
word-break: break-word;
}
.upload-result.success {
background: rgba(72, 187, 120, 0.2);
border: 2px solid rgba(72, 187, 120, 0.5);
color: #48bb78;
}
.upload-result.error {
background: rgba(245, 101, 101, 0.2);
border: 2px solid rgba(245, 101, 101, 0.5);
color: #f56565;
}
@media (max-width: 768px) {
.upload-container {
padding: 30px 20px;
}
.header-title {
font-size: 2rem;
}
.upload-title {
font-size: 1.5rem;
}
}
</style>
</head>
<body>
<div class="header-section">
<h1 class="header-title">Technology Transactions Assistant</h1>
<p class="header-subtitle">IMPORTANT: Documents uploaded to this platform are publicly accessible. Do NOT upload any confidential information. This includes PDF documents with redactations. This service uses frontier-level AI models for plain text conversion, and redacted content can be inadvertently extracted. Plain text files are recommended for this reason.</p>
</div>
<div class="upload-container">
<h2 class="upload-title">Document Upload</h2>
<p class="upload-description">
Upload a technology transactions document (pdf, txt, or docx only; max 10MB)
</p>
<form id="uploadForm" enctype="multipart/form-data">
<div class="upload-area" id="uploadArea">
<div class="upload-icon">π</div>
<div class="upload-text">Drag and drop file here</div>
<div class="upload-subtext">or click to browse</div>
<!-- Added name="file" so the backend sees the expected field name -->
<input type="file" id="fileInput" name="file" class="file-input" accept=".pdf,.docx,.txt" />
</div>
<div style="display:flex; gap:16px; width:100%; margin-top:18px;">
<div style="flex:1; display:flex; flex-direction:column; gap:6px;">
<label for="docType" style="font-size:0.8rem; color:#ccc;">Document Type (optional)</label>
<input id="docType" name="doc_type" type="text" maxlength="128" placeholder="e.g., License Agreement" style="background:#222; border:2px solid #555; border-radius:8px; padding:10px; color:#fff; font-family:inherit; font-size:0.85rem;" />
</div>
</div>
<div class="selected-file" id="selectedFile">
<div class="file-info">
<span class="file-name" id="fileName"></span>
<span class="file-size" id="fileSize"></span>
<button type="button" class="remove-file" id="removeFile">Remove</button>
</div>
</div>
<button type="submit" class="upload-button" id="uploadButton" disabled>Upload Document</button>
</form>
<div class="progress-container" id="progressContainer">
<div class="progress-bar" id="progressBar"></div>
<div class="progress-text" id="progressText">Uploading...</div>
<div style="font-size: 0.7rem; font-style: italic; text-align: center; color: #ccc; padding: 0 10px 10px;">
Note: Generating and indexing embeddings will take several minutes. Thank you for your patience.
</div>
</div>
<div class="upload-result" id="uploadResult"></div>
</div>
<br />
<br />
<div style="text-align: center; margin-top: 20px;">
<a href="/" style="color: #87CEFA; text-decoration: none; font-size: 1rem; padding: 10px 20px; border: 1px solid #87CEFA; border-radius: 10px; transition: all 0.3s ease;" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'">
β Back to Home
</a>
</div>
<script>
const uploadArea = document.getElementById('uploadArea');
const fileInput = document.getElementById('fileInput');
const selectedFile = document.getElementById('selectedFile');
const fileName = document.getElementById('fileName');
const fileSize = document.getElementById('fileSize');
const removeFile = document.getElementById('removeFile');
const uploadButton = document.getElementById('uploadButton');
const uploadForm = document.getElementById('uploadForm');
const progressContainer = document.getElementById('progressContainer');
const progressBar = document.getElementById('progressBar');
const progressText = document.getElementById('progressText');
const uploadResult = document.getElementById('uploadResult');
let selectedFileObj = null;
// File input change handler
fileInput.addEventListener('change', handleFileSelect);
// Drag and drop handlers
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.classList.add('dragover');
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.classList.remove('dragover');
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
handleFile(files[0]);
}
});
// Remove file handler
removeFile.addEventListener('click', () => {
clearFileSelection();
uploadResult.style.display = 'none';
});
// Form submission handler β use XMLHttpRequest to support upload progress
uploadForm.addEventListener('submit', (e) => {
e.preventDefault();
if (!selectedFileObj) {
showResult('Please select a file to upload.', 'error');
return;
}
uploadButton.disabled = true;
progressContainer.classList.add('visible');
uploadResult.style.display = 'none';
progressBar.style.width = '0%';
progressText.textContent = 'Starting upload...';
const formData = new FormData();
formData.append('file', selectedFileObj);
const dt = document.getElementById('docType').value.trim();
if (dt) formData.append('doc_type', dt);
const xhr = new XMLHttpRequest();
xhr.open('POST', '/api/upload', true);
// Upload progress
xhr.upload.onprogress = function(event) {
if (event.lengthComputable) {
const percent = Math.round((event.loaded / event.total) * 100);
progressBar.style.width = percent + '%';
progressText.textContent = `Uploading... ${percent}%`;
}
};
xhr.onload = function() {
uploadButton.disabled = false;
// Attempt to parse JSON response from server
let responseJson = null;
try {
responseJson = JSON.parse(xhr.responseText || '{}');
} catch (err) {
showResult('Upload failed: invalid server response.', 'error');
progressContainer.classList.remove('visible');
return;
}
if (xhr.status >= 200 && xhr.status < 300) {
progressBar.style.width = '100%';
progressText.textContent = 'Upload complete';
// Show returned metadata if present
const docId = responseJson.doc_id ? `Doc ID: ${responseJson.doc_id}` : '';
const sha = responseJson.sha256 ? `SHA256: ${responseJson.sha256}` : '';
const title = responseJson.title ? `Title: ${responseJson.title}` : '';
const dtEcho = responseJson.doc_type ? `Type: ${responseJson.doc_type}` : '';
const msgParts = ['Document uploaded successfully.', title].filter(Boolean);
showResult(msgParts.join(' β '), 'success');
// Keep note about indexing in case embeddings are generated async
const indexingNote = document.createElement('div');
indexingNote.style.marginTop = '8px';
indexingNote.style.fontSize = '0.85rem';
indexingNote.style.color = '#ccc';
indexingNote.textContent = 'Embeddings/indexing may continue in the background.';
uploadResult.appendChild(indexingNote);
// Clear the file selection and reset form after successful upload
clearFileSelection();
document.getElementById('docType').value = '';
uploadButton.disabled = true; // Keep disabled until next file is selected
} else {
// Try to show server error message
const errMsg = responseJson && responseJson.error ? responseJson.error : xhr.statusText || 'Upload failed';
showResult(`Upload failed: ${errMsg}`, 'error');
}
progressContainer.classList.remove('visible');
};
xhr.onerror = function() {
uploadButton.disabled = false;
showResult('Upload failed: network error.', 'error');
progressContainer.classList.remove('visible');
};
xhr.ontimeout = function() {
uploadButton.disabled = false;
showResult('Upload timed out.', 'error');
progressContainer.classList.remove('visible');
};
// Optional timeout (ms) β adjust or remove as needed
xhr.timeout = 5500000; // 8 minutes
xhr.send(formData);
});
function handleFileSelect(e) {
const file = e.target.files[0];
if (file) {
handleFile(file);
}
}
function clearFileSelection() {
selectedFileObj = null;
fileInput.value = '';
selectedFile.classList.remove('visible');
uploadButton.classList.remove('visible');
uploadButton.disabled = true; // Ensure button is disabled when no file is selected
}
function handleFile(file) {
// Clear any previous upload result message when selecting a new file
uploadResult.style.display = 'none';
// Validate file type by MIME or extension fallback
const allowedTypes = [
'application/pdf',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/msword',
'text/plain'
];
const ext = (file.name || '').split('.').pop().toLowerCase();
const allowedExt = ['pdf', 'docx', 'doc', 'txt'];
if (!allowedTypes.includes(file.type) && !allowedExt.includes(ext)) {
showResult('Please select a .pdf, .txt, .doc, or .docx file.', 'error');
return;
}
const maxSize = 10 * 1024 * 1024;
if (file.size > maxSize) {
showResult('File size must be less than 10MB.', 'error');
return;
}
selectedFileObj = file;
fileName.textContent = file.name;
fileSize.textContent = formatFileSize(file.size);
selectedFile.classList.add('visible');
uploadButton.classList.add('visible');
uploadButton.disabled = false; // Enable the button when a file is selected
uploadResult.style.display = 'none';
}
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function showResult(message, type) {
uploadResult.textContent = message;
uploadResult.className = `upload-result ${type}`;
uploadResult.style.display = 'block';
}
</script>
</body> |