Spaces:
Sleeping
Sleeping
Upload ingest.py with huggingface_hub
Browse files
ingest.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
Pipeline de
|
| 4 |
|
| 5 |
Uso:
|
| 6 |
-
python ingest.py # indexa (pula se
|
| 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 --
|
| 27 |
print("=" * 60)
|
| 28 |
|
| 29 |
if not rebuild:
|
| 30 |
count = collection_count()
|
| 31 |
if count > 0:
|
| 32 |
-
print(f"[INFO]
|
| 33 |
-
print("[INFO] Use --rebuild para
|
| 34 |
return
|
| 35 |
|
| 36 |
if not DOCS_DIR.exists():
|
| 37 |
-
print(f"[ERROR] Pasta de documentos
|
| 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)}
|
| 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]
|
| 58 |
|
| 59 |
-
print(f"\n[OK]
|
| 60 |
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
Pipeline de ingestão: lê PDFs de docs/ e indexa no ChromaDB.
|
| 4 |
|
| 5 |
Uso:
|
| 6 |
+
python ingest.py # indexa (pula se já 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 já 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__":
|