main.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from workflow_agents import app
  2. from function_exctract import extract_pages, extract_pdf_path
  3. from dotenv import load_dotenv
  4. from langfuse.langchain import CallbackHandler
  5. # Initialize Langfuse CallbackHandler for Langchain (tracing)
  6. langfuse_handler = CallbackHandler()
  7. load_dotenv()
  8. INPUTS = {
  9. "Caisse Générale de Prévoyance (CGP)_2025.pdf": {
  10. #"S.02": [],
  11. "S.05": []
  12. }
  13. }
  14. if __name__ == "__main__":
  15. # 1. Boucle sur chaque entreprise (Fichier PDF)
  16. for pdf_filename, sections_input in INPUTS.items():
  17. print(f"\n DÉMARRAGE ENTREPRISE : {pdf_filename}")
  18. entreprise_clean = pdf_filename.replace(".pdf", "")
  19. # Récupère le vrai chemin du PDF
  20. pdf_path = extract_pdf_path(pdf_filename)
  21. print(f" PDF trouvé : {pdf_path}")
  22. # Récupère les pages depuis Excel
  23. sections_with_pages = extract_pages(pdf_filename)
  24. # Fusionne : garde seulement les sections choisies dans INPUTS
  25. # et remplit les pages depuis Excel
  26. sections = {
  27. s: sections_with_pages.get(s, [])
  28. for s in sections_input.keys()
  29. }
  30. # 2. Boucle sur chaque section
  31. for section_name, pages in sections.items():
  32. print(f" Section : {section_name} — pages : {pages}")
  33. initial_state = {
  34. "messages": [],
  35. "pdf_path": pdf_path,
  36. "pages": pages,
  37. "entreprise_name": entreprise_clean,
  38. "section_name": section_name
  39. }
  40. try:
  41. final_state = app.invoke(initial_state, config={"callbacks": [langfuse_handler]})
  42. print(f" Section {section_name} terminée.")
  43. except Exception as e:
  44. print(f" ❌ Erreur section {section_name}: {e}")
  45. #print("\n✨ TOUTES LES ENTREPRISES ET SECTIONS ONT ÉTÉ TRAITÉES.")