Finish-him commited on
Commit
208c09c
·
verified ·
1 Parent(s): 6e9d77b

a parte de anexar o arquivo e fazer ele analizar o pdf

Browse files
Files changed (1) hide show
  1. index.html +54 -9
index.html CHANGED
@@ -66,7 +66,13 @@
66
  Selecionar Arquivos
67
  </span>
68
  </label>
69
- </form>
 
 
 
 
 
 
70
  </div>
71
  </div>
72
  <div class="bg-gray-50 px-8 py-4 border-t border-gray-200">
@@ -245,6 +251,33 @@
245
  </footer>
246
 
247
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  // Initialize Vanta.js background
249
  VANTA.NET({
250
  el: "#vanta-bg",
@@ -271,10 +304,15 @@ el: "#vanta-bg",
271
  if (e.target.files.length > 0) {
272
  const files = Array.from(e.target.files);
273
  console.log('Files selected:', files);
274
- // Here you would typically handle the file upload
275
- // Example: uploadFiles(files);
276
- alert(`${files.length} arquivo(s) selecionado(s)!`);
277
- }
 
 
 
 
 
278
  });
279
 
280
  // Drag and drop support
@@ -294,10 +332,17 @@ el: "#vanta-bg",
294
  uploadArea.classList.remove('bg-blue-50');
295
 
296
  if (e.dataTransfer.files.length) {
297
- fileInput.files = e.dataTransfer.files;
298
- const event = new Event('change');
299
- fileInput.dispatchEvent(event);
300
- }
 
 
 
 
 
 
 
301
  });
302
  });
303
  </script>
 
66
  Selecionar Arquivos
67
  </span>
68
  </label>
69
+ <div id="loadingIndicator" class="hidden mt-4">
70
+ <div class="flex items-center space-x-2">
71
+ <div class="animate-spin rounded-full h-5 w-5 border-b-2 border-blue-600"></div>
72
+ <span class="text-gray-600">Analisando documento...</span>
73
+ </div>
74
+ </div>
75
+ </form>
76
  </div>
77
  </div>
78
  <div class="bg-gray-50 px-8 py-4 border-t border-gray-200">
 
251
  </footer>
252
 
253
  <script>
254
+ // PDF Analysis Function
255
+ async function analyzePDF(file) {
256
+ const formData = new FormData();
257
+ formData.append('file', file);
258
+
259
+ try {
260
+ document.getElementById('loadingIndicator').classList.remove('hidden');
261
+
262
+ // Using a mock API endpoint - replace with your actual backend endpoint
263
+ const response = await fetch('https://api.example.com/analyze-pdf', {
264
+ method: 'POST',
265
+ body: formData
266
+ });
267
+
268
+ const result = await response.json();
269
+
270
+ // Show analysis results (you can modify this part to show the results in your UI)
271
+ alert(`Análise concluída!\nDocumento: ${file.name}\nPáginas: ${result.pageCount}\nEntidades encontradas: ${result.entities.length}`);
272
+
273
+ } catch (error) {
274
+ console.error('Error analyzing PDF:', error);
275
+ alert('Erro ao analisar o documento. Por favor, tente novamente.');
276
+ } finally {
277
+ document.getElementById('loadingIndicator').classList.add('hidden');
278
+ }
279
+ }
280
+
281
  // Initialize Vanta.js background
282
  VANTA.NET({
283
  el: "#vanta-bg",
 
304
  if (e.target.files.length > 0) {
305
  const files = Array.from(e.target.files);
306
  console.log('Files selected:', files);
307
+ // Analyze each PDF file
308
+ files.forEach(file => {
309
+ if (file.type === 'application/pdf') {
310
+ analyzePDF(file);
311
+ } else {
312
+ alert('Por favor, selecione apenas arquivos PDF.');
313
+ }
314
+ });
315
+ }
316
  });
317
 
318
  // Drag and drop support
 
332
  uploadArea.classList.remove('bg-blue-50');
333
 
334
  if (e.dataTransfer.files.length) {
335
+ const files = Array.from(e.dataTransfer.files);
336
+ const pdfFiles = files.filter(file => file.type === 'application/pdf');
337
+
338
+ if (pdfFiles.length > 0) {
339
+ fileInput.files = e.dataTransfer.files;
340
+ const event = new Event('change');
341
+ fileInput.dispatchEvent(event);
342
+ } else {
343
+ alert('Por favor, solte apenas arquivos PDF.');
344
+ }
345
+ }
346
  });
347
  });
348
  </script>