| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- INPUTS = {
- "Groupama Gan Vie_2025.pdf": {
- "S.12": []
- }
- }
- from workflow_agents import app
- from function_exctract import extract_pages, extract_pdf_path
- from dotenv import load_dotenv
- from langfuse.langchain import CallbackHandler
- # Initialize Langfuse CallbackHandler for Langchain (tracing)
- langfuse_handler = CallbackHandler()
- load_dotenv()
- if __name__ == "__main__":
- # 1. Boucle sur chaque entreprise (Fichier PDF)
- for pdf_filename, sections_input in INPUTS.items():
- print("----------------------------------------")
- print(f"\n DÉMARRAGE ENTREPRISE : {pdf_filename}")
- entreprise_clean = pdf_filename.replace(".pdf", "")
- # Récupère le vrai chemin du PDF
- pdf_path = extract_pdf_path(pdf_filename)
- print(f" PDF trouvé : {pdf_path}")
- # Récupère les pages depuis Excel
- sections_with_pages = extract_pages(pdf_filename)
- # Fusionne : garde seulement les sections choisies dans INPUTS
- # et remplit les pages depuis Excel
- sections = {
- s: sections_with_pages.get(s, [])
- for s in sections_input.keys()
- }
- # 2. Boucle sur chaque section
- # 2. Boucle sur chaque section
- for section_name, pages in sections.items():
-
- # S'assurer que pages est une liste (ex: [45, 46])
- list_pages = pages if isinstance(pages, list) else [pages]
- # --- NOUVELLE BOUCLE PAR PAGE ---
- for p in list_pages:
- print(f" Traitement Section : {section_name} — PAGE INDIVIDUELLE : {p}")
- initial_state = {
- "messages": [],
- "pdf_path": pdf_path,
- "page": p, # On envoie le numéro unique
- "entreprise_name": entreprise_clean,
- "section_name": f"{section_name}_page_{p}" # On change le nom pour le fichier final
- }
- try:
- # L'agent est appelé pour CHAQUE page
- print("----------------------------------------")
- final_state = app.invoke(initial_state, config={"callbacks": [langfuse_handler]})
- print(f" Page {p} de la section {section_name} terminée.")
- except Exception as e:
- print(f" Erreur sur la page {p}: {e}")
- print("----------------------------------------")
- #print("\n✨ TOUTES LES ENTREPRISES ET SECTIONS ONT ÉTÉ TRAITÉES.")
|