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() INPUTS = { "Caisse Générale de Prévoyance (CGP)_2025.pdf": { #"S.02": [], "S.05": [] } } if __name__ == "__main__": # 1. Boucle sur chaque entreprise (Fichier PDF) for pdf_filename, sections_input in INPUTS.items(): 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 for section_name, pages in sections.items(): print(f" Section : {section_name} — pages : {pages}") initial_state = { "messages": [], "pdf_path": pdf_path, "pages": pages, "entreprise_name": entreprise_clean, "section_name": section_name } try: final_state = app.invoke(initial_state, config={"callbacks": [langfuse_handler]}) print(f" Section {section_name} terminée.") except Exception as e: print(f" ❌ Erreur section {section_name}: {e}") #print("\n✨ TOUTES LES ENTREPRISES ET SECTIONS ONT ÉTÉ TRAITÉES.")