fabianonbfilho commited on
Commit
8bb50f2
·
verified ·
1 Parent(s): e7505f8

Upload ingest.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. ingest.py +9 -9
ingest.py CHANGED
@@ -1,9 +1,9 @@
1
  #!/usr/bin/env python3
2
  """
3
- Pipeline de ingestao: le PDFs de docs/ e indexa no ChromaDB.
4
 
5
  Uso:
6
- python ingest.py # indexa (pula se ja indexado)
7
  python ingest.py --rebuild # apaga e re-indexa tudo
8
  """
9
  import sys
@@ -23,18 +23,18 @@ def main():
23
  rebuild = "--rebuild" in sys.argv
24
 
25
  print("=" * 60)
26
- print(" LABDAPS RAG -- Ingestao do Livro Sinal de Alerta")
27
  print("=" * 60)
28
 
29
  if not rebuild:
30
  count = collection_count()
31
  if count > 0:
32
- print(f"[INFO] Colecao ja contem {count} chunks. Pulando ingestao.")
33
- print("[INFO] Use --rebuild para forccar re-indexacao.")
34
  return
35
 
36
  if not DOCS_DIR.exists():
37
- print(f"[ERROR] Pasta de documentos nao encontrada: {DOCS_DIR}")
38
  sys.exit(1)
39
 
40
  pdf_files = list(DOCS_DIR.glob("*.pdf"))
@@ -43,7 +43,7 @@ def main():
43
  print("\n[1/3] Extraindo texto dos PDFs...")
44
  t0 = time.time()
45
  pages = extract_all_pdfs(DOCS_DIR)
46
- print(f"[INFO] {len(pages)} paginas extraidas em {time.time()-t0:.1f}s")
47
 
48
  print("\n[2/3] Dividindo em chunks...")
49
  t0 = time.time()
@@ -54,9 +54,9 @@ def main():
54
  embedder = Embedder()
55
  t0 = time.time()
56
  build_index(chunks, embedder, rebuild=rebuild)
57
- print(f"[INFO] Indexacao concluida em {time.time()-t0:.1f}s")
58
 
59
- print(f"\n[OK] Ingestao concluida! Total de chunks: {collection_count()}")
60
 
61
 
62
  if __name__ == "__main__":
 
1
  #!/usr/bin/env python3
2
  """
3
+ Pipeline de ingestão: PDFs de docs/ e indexa no ChromaDB.
4
 
5
  Uso:
6
+ python ingest.py # indexa (pula se indexado)
7
  python ingest.py --rebuild # apaga e re-indexa tudo
8
  """
9
  import sys
 
23
  rebuild = "--rebuild" in sys.argv
24
 
25
  print("=" * 60)
26
+ print(" LABDAPS RAG -- Ingestão do Livro Sinal de Alerta")
27
  print("=" * 60)
28
 
29
  if not rebuild:
30
  count = collection_count()
31
  if count > 0:
32
+ print(f"[INFO] Coleção contém {count} chunks. Pulando ingestão.")
33
+ print("[INFO] Use --rebuild para forçar re-indexação.")
34
  return
35
 
36
  if not DOCS_DIR.exists():
37
+ print(f"[ERROR] Pasta de documentos não encontrada: {DOCS_DIR}")
38
  sys.exit(1)
39
 
40
  pdf_files = list(DOCS_DIR.glob("*.pdf"))
 
43
  print("\n[1/3] Extraindo texto dos PDFs...")
44
  t0 = time.time()
45
  pages = extract_all_pdfs(DOCS_DIR)
46
+ print(f"[INFO] {len(pages)} páginas extraídas em {time.time()-t0:.1f}s")
47
 
48
  print("\n[2/3] Dividindo em chunks...")
49
  t0 = time.time()
 
54
  embedder = Embedder()
55
  t0 = time.time()
56
  build_index(chunks, embedder, rebuild=rebuild)
57
+ print(f"[INFO] Indexação concluída em {time.time()-t0:.1f}s")
58
 
59
+ print(f"\n[OK] Ingestão concluída! Total de chunks: {collection_count()}")
60
 
61
 
62
  if __name__ == "__main__":