Spaces:
Sleeping
Sleeping
File size: 14,434 Bytes
d8635c9 | 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 | <script lang="ts">
import { previousRfps, nextStep } from '../stores/appStore'
import { parseDocument } from '../utils/documentParser'
let dragActive = false
let isProcessing = false
let uploadedFiles: File[] = []
let processingStatus = ''
let analysisResults: any[] = []
// For accuracy, we'll scan the local folder as well
let folderPath = 'c:\\Users\\varun\\Downloads\\RFP Svelt\\public\\previous-rfps'
async function handleFileUpload(event: Event) {
const target = event.target as HTMLInputElement
if (target.files) {
await processFiles(Array.from(target.files))
}
}
async function processFiles(files: File[]) {
isProcessing = true
processingStatus = 'Analyzing documents for accuracy...'
uploadedFiles = [...uploadedFiles, ...files]
try {
for (const file of files) {
processingStatus = `Processing ${file.name}...`
const content = await parseDocument(file)
// Enhanced analysis for accuracy
const analysis = analyzeDocumentQuality(content, file.name)
analysisResults.push(analysis)
const rfpDocument = {
id: `rfp-${Date.now()}-${Math.random()}`,
name: file.name,
content: content,
size: file.size,
uploadDate: new Date().toISOString(),
pageCount: Math.ceil(content.length / 2000), // Estimate pages
quality: analysis.quality,
keyTopics: analysis.topics,
wordCount: content.split(' ').length
}
previousRfps.update(current => [...current, rfpDocument])
}
processingStatus = 'Analysis complete! Documents ready for AI reference.'
} catch (error) {
console.error('Error processing files:', error)
processingStatus = 'Error processing some files. Please check format and try again.'
} finally {
setTimeout(() => {
isProcessing = false
processingStatus = ''
}, 2000)
}
}
function analyzeDocumentQuality(content: string, filename: string) {
const wordCount = content.split(' ').length
const hasQuestions = /\?|what|how|when|where|why|describe|explain|provide/gi.test(content)
const hasAnswers = content.length > 5000 // Substantial content
const hasStructure = /section|chapter|\d+\.|bullet|β’/gi.test(content)
let quality = 'Basic'
let score = 0
if (wordCount > 1000) score += 25
if (wordCount > 5000) score += 25
if (hasQuestions) score += 20
if (hasAnswers) score += 20
if (hasStructure) score += 10
if (score >= 80) quality = 'Excellent'
else if (score >= 60) quality = 'Good'
else if (score >= 40) quality = 'Fair'
// Extract key topics
const topics = extractKeyTopics(content)
return {
quality,
score,
topics,
wordCount,
hasQuestions,
hasAnswers,
hasStructure,
recommendations: getRecommendations(score, hasQuestions, hasAnswers)
}
}
function extractKeyTopics(content: string) {
const businessTerms = [
'security', 'compliance', 'implementation', 'timeline', 'budget', 'experience',
'methodology', 'team', 'project management', 'deliverables', 'support',
'training', 'maintenance', 'scalability', 'performance', 'integration'
]
return businessTerms.filter(term =>
content.toLowerCase().includes(term)
).slice(0, 5)
}
function getRecommendations(score: number, hasQuestions: boolean, hasAnswers: boolean) {
const recommendations = []
if (score < 40) {
recommendations.push('Consider adding more detailed RFP responses')
}
if (!hasQuestions) {
recommendations.push('Include documents with both questions and answers')
}
if (!hasAnswers) {
recommendations.push('Add more comprehensive response content')
}
if (score >= 80) {
recommendations.push('Excellent reference material for AI training')
}
return recommendations
}
function handleDrop(event: DragEvent) {
event.preventDefault()
dragActive = false
if (event.dataTransfer?.files) {
processFiles(Array.from(event.dataTransfer.files))
}
}
function handleDragOver(event: DragEvent) {
event.preventDefault()
dragActive = true
}
function handleDragLeave() {
dragActive = false
}
function removeDocument(id: string) {
previousRfps.update(current => current.filter(doc => doc.id !== id))
uploadedFiles = uploadedFiles.filter((_, index) => $previousRfps[index]?.id !== id)
}
function proceedToNextStep() {
if ($previousRfps.length > 0) {
nextStep()
}
}
function getQualityColor(quality: string) {
switch (quality) {
case 'Excellent': return 'text-green-600 bg-green-100 border-green-200'
case 'Good': return 'text-blue-600 bg-blue-100 border-blue-200'
case 'Fair': return 'text-yellow-600 bg-yellow-100 border-yellow-200'
default: return 'text-gray-600 bg-gray-100 border-gray-200'
}
}
</script>
<div class="space-y-8">
<!-- Instructions Section -->
<div class="bg-gradient-to-r from-blue-50 to-indigo-50 rounded-2xl p-6 border border-blue-200">
<div class="flex items-start space-x-4">
<div class="w-12 h-12 bg-blue-500 rounded-xl flex items-center justify-center text-white text-2xl">
π‘
</div>
<div class="flex-1">
<h3 class="text-lg font-bold text-blue-900 mb-2">For Maximum Accuracy</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm text-blue-800">
<div>
<h4 class="font-semibold mb-1">π Folder Method (Recommended)</h4>
<p>Add PDFs to: <code class="bg-blue-200 px-2 py-1 rounded text-xs">public/previous-rfps/</code></p>
</div>
<div>
<h4 class="font-semibold mb-1">π€ Upload Method</h4>
<p>Drag & drop your best RFP responses below</p>
</div>
</div>
<div class="mt-3 text-sm text-blue-700">
<strong>Best Practice:</strong> Include 3-5 complete RFP responses with both questions and detailed answers for optimal AI accuracy.
</div>
</div>
</div>
</div>
<!-- Upload Area -->
<div class="bg-white rounded-2xl border-2 border-dashed border-slate-300 hover:border-blue-400 transition-colors duration-300 overflow-hidden">
<div
class="relative p-12 text-center {dragActive ? 'bg-blue-50' : 'bg-gray-50'}"
on:drop={handleDrop}
on:dragover={handleDragOver}
on:dragleave={handleDragLeave}
>
<input
type="file"
multiple
accept=".pdf,.docx,.doc,.txt"
on:change={handleFileUpload}
class="absolute inset-0 opacity-0 cursor-pointer"
/>
{#if isProcessing}
<div class="flex flex-col items-center space-y-4">
<div class="w-16 h-16 border-4 border-blue-500 border-t-transparent rounded-full animate-spin"></div>
<p class="text-blue-600 font-semibold">{processingStatus}</p>
</div>
{:else}
<div class="flex flex-col items-center space-y-4">
<div class="w-20 h-20 bg-gradient-to-r from-blue-500 to-indigo-600 rounded-2xl flex items-center justify-center text-white text-4xl">
π
</div>
<div>
<h3 class="text-2xl font-bold text-gray-800 mb-2">Upload Previous RFPs</h3>
<p class="text-gray-600 mb-4">Drop your RFP documents here or click to browse</p>
<p class="text-sm text-gray-500">Supports PDF, DOCX, DOC, and TXT files</p>
</div>
</div>
{/if}
</div>
</div>
<!-- Folder Instructions -->
<div class="bg-gradient-to-r from-green-50 to-emerald-50 rounded-2xl p-6 border border-green-200">
<div class="flex items-center space-x-3 mb-3">
<div class="w-8 h-8 bg-green-500 rounded-lg flex items-center justify-center text-white text-lg">
π
</div>
<h3 class="text-lg font-bold text-green-900">Alternative: Use Local Folder</h3>
</div>
<p class="text-green-800 mb-3">
For better organization and accuracy, you can add your RFP documents directly to the folder:
</p>
<div class="bg-white rounded-lg p-4 border border-green-200">
<code class="text-sm text-green-700 font-mono break-all">
{folderPath}
</code>
</div>
<p class="text-sm text-green-700 mt-2">
The system will automatically detect and analyze documents in this folder for AI reference.
</p>
</div>
<!-- Document Analysis Results -->
{#if $previousRfps.length > 0}
<div class="bg-white rounded-2xl shadow-lg border border-gray-200 overflow-hidden">
<div class="bg-gradient-to-r from-gray-800 to-gray-900 p-6">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-3">
<div class="w-10 h-10 bg-white rounded-lg flex items-center justify-center text-gray-800 text-xl">
π
</div>
<div>
<h3 class="text-xl font-bold text-white">Document Analysis</h3>
<p class="text-gray-300">{$previousRfps.length} documents analyzed for AI accuracy</p>
</div>
</div>
<button
on:click={proceedToNextStep}
class="bg-gradient-to-r from-green-500 to-emerald-600 text-white px-6 py-3 rounded-xl font-semibold hover:from-green-600 hover:to-emerald-700 transition-all duration-300 shadow-lg"
>
Continue to Questions β
</button>
</div>
</div>
<div class="p-6 space-y-4">
{#each $previousRfps as doc, index}
<div class="border border-gray-200 rounded-xl p-4 hover:shadow-lg transition-shadow">
<div class="flex items-start justify-between">
<div class="flex-1">
<div class="flex items-center space-x-3 mb-3">
<div class="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center text-blue-600 text-sm font-bold">
{index + 1}
</div>
<h4 class="font-semibold text-gray-800">{doc.name}</h4>
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium border {getQualityColor(doc.quality)}">
{doc.quality} Quality
</span>
</div>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-3 text-sm">
<div>
<span class="text-gray-500">Words:</span>
<span class="font-semibold text-gray-800">{doc.wordCount?.toLocaleString()}</span>
</div>
<div>
<span class="text-gray-500">Pages:</span>
<span class="font-semibold text-gray-800">{doc.pageCount}</span>
</div>
<div>
<span class="text-gray-500">Size:</span>
<span class="font-semibold text-gray-800">{(doc.size / 1024 / 1024).toFixed(1)} MB</span>
</div>
<div>
<span class="text-gray-500">Score:</span>
<span class="font-semibold text-gray-800">{analysisResults[index]?.score || 'N/A'}/100</span>
</div>
</div>
{#if doc.keyTopics && doc.keyTopics.length > 0}
<div class="flex flex-wrap gap-2 mb-3">
<span class="text-sm text-gray-500">Topics:</span>
{#each doc.keyTopics as topic}
<span class="inline-flex items-center px-2 py-1 bg-blue-100 text-blue-800 text-xs rounded-full">
{topic}
</span>
{/each}
</div>
{/if}
{#if analysisResults[index]?.recommendations}
<div class="text-sm text-gray-600">
<strong>AI Recommendation:</strong> {analysisResults[index].recommendations[0]}
</div>
{/if}
</div>
<button
on:click={() => removeDocument(doc.id)}
class="ml-4 w-8 h-8 bg-red-100 hover:bg-red-200 rounded-lg flex items-center justify-center text-red-600 transition-colors"
title="Remove document"
>
Γ
</button>
</div>
</div>
{/each}
</div>
</div>
{/if}
<!-- Accuracy Tips -->
<div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-2xl p-6 border border-purple-200">
<div class="flex items-start space-x-4">
<div class="w-12 h-12 bg-purple-500 rounded-xl flex items-center justify-center text-white text-2xl">
π―
</div>
<div>
<h3 class="text-lg font-bold text-purple-900 mb-3">Maximizing AI Accuracy</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm text-purple-800">
<div>
<h4 class="font-semibold mb-2">β
Best Documents Include:</h4>
<ul class="space-y-1 text-purple-700">
<li>β’ Complete question-answer pairs</li>
<li>β’ Technical specifications</li>
<li>β’ Company methodologies</li>
<li>β’ Previous winning proposals</li>
</ul>
</div>
<div>
<h4 class="font-semibold mb-2">β‘ For Optimal Results:</h4>
<ul class="space-y-1 text-purple-700">
<li>β’ Upload 3-5 comprehensive RFPs</li>
<li>β’ Include recent proposals (last 2 years)</li>
<li>β’ Ensure documents are well-formatted</li>
<li>β’ Mix different industry sectors</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
|