From b1e78f2b7dd500e963eed2cd2d847bc160dcf007 Mon Sep 17 00:00:00 2001 From: Ladebeze66 Date: Fri, 25 Apr 2025 11:47:57 +0200 Subject: [PATCH] 2504-11:47 --- agent_factory_llama.py | 21 +- agents/llama_vision/agent_image_analyser.py | 11 +- agents/llama_vision/agent_report_generator.py | 2 +- agents/llama_vision/agent_vision_ocr.py | 110 +++++++++ orchestrator_llama.log | 177 +++++++------ ...962ed21795c4e943fcb8cb84fd4d7465a.jpg.json | 2 +- ...20e0e112c46b4440cc938f74d10934e98.gif.json | 2 +- .../pipeline/ocr_traduction/image.png.json | 2 +- .../ocr_traduction/image_145435.png.json | 2 +- .../ocr_traduction/ocr_traduction.txt | 110 --------- test_image_analyse.log | 7 - test_image_processing.py | 152 ------------ test_image_sorter.py | 78 ------ test_ocr.py | 82 ------- test_ocr_image.png | Bin 1066 -> 0 bytes test_ocr_to_image_sorter.py | 232 ------------------ 16 files changed, 238 insertions(+), 752 deletions(-) create mode 100644 agents/llama_vision/agent_vision_ocr.py delete mode 100644 test_image_analyse.log delete mode 100644 test_image_processing.py delete mode 100644 test_image_sorter.py delete mode 100644 test_ocr.py delete mode 100644 test_ocr_image.png delete mode 100644 test_ocr_to_image_sorter.py diff --git a/agent_factory_llama.py b/agent_factory_llama.py index 5ae89e8..c6451d6 100644 --- a/agent_factory_llama.py +++ b/agent_factory_llama.py @@ -16,6 +16,7 @@ from agents.llama_vision.agent_ticket_analyser import AgentTicketAnalyser from agents.llama_vision.agent_image_sorter import AgentImageSorter from agents.llama_vision.agent_image_analyser import AgentImageAnalyser from agents.llama_vision.agent_report_generator import AgentReportGenerator +from agents.llama_vision.agent_vision_ocr import AgentVisionOCR from llm_classes.llama_vision import LlamaVision @@ -119,6 +120,23 @@ class AgentFactoryLlamaVision: if llm is None: llm = AgentFactoryLlamaVision.create_llm() return AgentReportGenerator(llm) + + @staticmethod + def create_vision_ocr(llm: Optional[LlamaVision] = None) -> AgentVisionOCR: + """ + Crée un agent d'OCR visuel avec sa propre instance LLM. + + Args: + llm: Instance LlamaVision existante (optionnel, une nouvelle instance sera créée si None) + + Returns: + Agent d'OCR visuel configuré + """ + logger.info("Création de l'agent d'OCR visuel (llama_vision)") + # Créer une nouvelle instance LLM spécifique à cet agent si aucune n'est fournie + if llm is None: + llm = AgentFactoryLlamaVision.create_llm() + return AgentVisionOCR(llm) @staticmethod def create_all_agents(model_name: Optional[str] = None) -> Dict[str, Any]: @@ -148,6 +166,7 @@ class AgentFactoryLlamaVision: "ticket_analyser": AgentFactoryLlamaVision.create_ticket_analyser(llm), "image_sorter": AgentFactoryLlamaVision.create_image_sorter(llm), "image_analyser": AgentFactoryLlamaVision.create_image_analyser(llm), - "report_generator": AgentFactoryLlamaVision.create_report_generator(llm) + "report_generator": AgentFactoryLlamaVision.create_report_generator(llm), + "vision_ocr": AgentFactoryLlamaVision.create_vision_ocr(llm) } \ No newline at end of file diff --git a/agents/llama_vision/agent_image_analyser.py b/agents/llama_vision/agent_image_analyser.py index 39f3375..e9f2888 100644 --- a/agents/llama_vision/agent_image_analyser.py +++ b/agents/llama_vision/agent_image_analyser.py @@ -26,7 +26,7 @@ class AgentImageAnalyser(BaseAgent): self.params = params or { "temperature": 0.2, "top_p": 0.8, - "max_tokens": 3000 + "max_tokens": 5000 } self.instructions_analyse = ( @@ -317,11 +317,10 @@ Structure your analysis clearly with headers and bullet points. print(f" Erreur: Réponse invalide du modèle pour {image_name}") return result - # Récupération du nom normalisé du modèle - model_name = getattr(self.llm, "pipeline_normalized_name", getattr(self.llm, "modele", "llama3-vision-90b-instruct")) - - # Si model_name contient des caractères spéciaux, les remplacer par des tirets - model_name = model_name.replace(".", "-").replace(":", "-").replace("_", "-") + # Nettoyer le nom du modèle pour éviter les doublons + model_name = getattr(self.llm, "modele", str(type(self.llm))) + if model_name.startswith("image_"): + model_name = model_name[6:] # Supprimer le préfixe redondant # Construction du résultat resultat = { diff --git a/agents/llama_vision/agent_report_generator.py b/agents/llama_vision/agent_report_generator.py index 803c11c..f87d21d 100644 --- a/agents/llama_vision/agent_report_generator.py +++ b/agents/llama_vision/agent_report_generator.py @@ -19,7 +19,7 @@ class AgentReportGenerator(BaseAgent): self.params = { "temperature": 0.2, "top_p": 0.8, - "max_tokens": 8000 + "max_tokens": 10000 } # System prompt in French (preserved for French-speaking models) diff --git a/agents/llama_vision/agent_vision_ocr.py b/agents/llama_vision/agent_vision_ocr.py new file mode 100644 index 0000000..ef29337 --- /dev/null +++ b/agents/llama_vision/agent_vision_ocr.py @@ -0,0 +1,110 @@ +import os +import logging +from datetime import datetime +from PIL import Image + +from ..base_agent import BaseAgent +from ..utils.pipeline_logger import sauvegarder_donnees + +logger = logging.getLogger("AgentVisionOCR") + +class AgentVisionOCR(BaseAgent): + """ + Agent LlamaVision qui extrait du texte (OCR avancé) depuis une image. + Permet une lecture plus fine pour les images conservées après tri. + """ + def __init__(self, llm): + super().__init__("AgentVisionOCR", llm) + + self.params = { + "temperature": 0.1, + "top_p": 0.85, + "max_tokens": 15000 + } + + self.system_prompt = """You are a multilingual OCR visual assistant. + +Your task is to extract all visible text from image, even if it is in French, English, or both. + +Guidelines: +1. Include partial, blurry, or stylized characters +2. Group the result by type: labels, titles, buttons, errors, URLs, etc. +3. Do NOT translate any text - just extract what is visible +4. Mention if the image contains unreadable or missing parts + +Respond in English.""" + + self._configurer_llm() + logger.info("AgentVisionOCR initialisé") + + def _configurer_llm(self): + if hasattr(self.llm, "prompt_system"): + self.llm.prompt_system = self.system_prompt + if hasattr(self.llm, "configurer"): + self.llm.configurer(**self.params) + + def _extraire_ticket_id(self, image_path): + parts = image_path.split(os.sep) + for part in parts: + if part.startswitch("T") and part[1:].isdigit(): + return part + return "UNKNOWN" + + def executer(self, image_path: str, ocr_baseline: str = "") -> dict: + """" Effectue un OCR visuel via LlamaVision sur l'imga spécifiée. + Args: + image_path: Chemin vers l'image ç analyser + ocr_baseline: Texte OCRé précédemment (pour comparaison) + + Returns: + Dictionnaire contenant le texte extrait et les métadonnées + """ + image_name = os.path.basename(image_path) + print(f" AgentVisionOCR: Extraction sur {image_name}") + + try: + if not os.path.exists(image_path): + raise FileNotFoundError(f"Image introuvable: {image_path}") + + if not hasattr(self, "interroge_avec_image"): + raise RuntimeError("Le modèle ne supporte pas l'analyse d'images") + + response = self.llm.interroger_avec_image(image_path, self.system_prompt) + + if not response or "i cannot" in response.lower(): + raise ValueError("Réponse vide invalide du modèle") + + result = { + "extracted_text": response.strip(), + "image_name": image_name, + "image_path": image_path, + "ocr_script_text": ocr_baseline.strip(), + "ticket_id": self._extraire_ticket_id(image_path), + "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + "source_agent": self.nom + } + + # Sauvegarder pour traçabilité + sauvegarder_donnees( + ticket_id=result["ticket_id"], + step_name="ocr_llm", + data=result, + base_dir=None, + is_resultat=True + ) + + logger.info(f"OCR LLM réussi pour {image_name}") + return result + + except Exception as e: + logger.error(f"Erreur lors de l'extraction OCR pour {image_name}: {e}") + return { + "extracted_text": "", + "image_name": image_name, + "image_path": image_path, + "ticket_id": self._extraire_ticket_id(image_path), + "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + "source_agent": self.nom, + "error": str(e) + } + \ No newline at end of file diff --git a/orchestrator_llama.log b/orchestrator_llama.log index 27eada2..95711d9 100644 --- a/orchestrator_llama.log +++ b/orchestrator_llama.log @@ -1,20 +1,20 @@ -2025-04-25 09:49:53,231 - MainLlamaVision - INFO - Initialisation du modèle LlamaVision: llama3.2-vision:90b-instruct-q8_0 -2025-04-25 09:49:53,231 - LlamaVision - INFO - Initializing LlamaVision with model llama3.2-vision:90b-instruct-q8_0 (English-only mode) -2025-04-25 09:49:53,231 - MainLlamaVision - INFO - Nom normalisé du modèle: llama3-2-vision-90b-instruct-q8-0 -2025-04-25 09:49:53,231 - MainLlamaVision - INFO - Création des agents avec LlamaVision -2025-04-25 09:49:53,231 - AgentFactoryLlamaVision - INFO - Création de tous les agents avec instances LLM indépendantes (modèle: llama3.2-vision:90b-instruct-q8_0) -2025-04-25 09:49:53,231 - AgentFactoryLlamaVision - INFO - Initialisation du modèle llama_vision (modèle: llama3.2-vision:90b-instruct-q8_0) -2025-04-25 09:49:53,231 - LlamaVision - INFO - Initializing LlamaVision with model llama3.2-vision:90b-instruct-q8_0 (English-only mode) -2025-04-25 09:49:53,231 - AgentFactoryLlamaVision - INFO - Création de l'agent de tickets (llama_vision) -2025-04-25 09:49:53,231 - AgentTicketAnalyser - INFO - AgentTicketAnalyser initialisé -2025-04-25 09:49:53,231 - AgentFactoryLlamaVision - INFO - Création de l'agent de tri des images (llama_vision) -2025-04-25 09:49:53,231 - AgentImageSorter - INFO - AgentImageSorter (llama_vision) initialisé -2025-04-25 09:49:53,231 - AgentFactoryLlamaVision - INFO - Création de l'agent d'analyse des images (llama_vision) -2025-04-25 09:49:53,231 - AgentImageAnalyser - INFO - AgentImageAnalyser initialized -2025-04-25 09:49:53,231 - AgentFactoryLlamaVision - INFO - Création de l'agent de génération de rapports (llama_vision) -2025-04-25 09:49:53,231 - AgentReportGenerator - INFO - LlamaVision mode detected: using English system prompt -2025-04-25 09:49:53,231 - AgentReportGenerator - INFO - AgentReportGenerator initialized -2025-04-25 09:49:53,231 - MainLlamaVision - INFO - Configuration: { +2025-04-25 11:15:43,408 - MainLlamaVision - INFO - Initialisation du modèle LlamaVision: llama3.2-vision:90b-instruct-q8_0 +2025-04-25 11:15:43,408 - LlamaVision - INFO - Initializing LlamaVision with model llama3.2-vision:90b-instruct-q8_0 (English-only mode) +2025-04-25 11:15:43,408 - MainLlamaVision - INFO - Nom normalisé du modèle: llama3-2-vision-90b-instruct-q8-0 +2025-04-25 11:15:43,408 - MainLlamaVision - INFO - Création des agents avec LlamaVision +2025-04-25 11:15:43,408 - AgentFactoryLlamaVision - INFO - Création de tous les agents avec instances LLM indépendantes (modèle: llama3.2-vision:90b-instruct-q8_0) +2025-04-25 11:15:43,408 - AgentFactoryLlamaVision - INFO - Initialisation du modèle llama_vision (modèle: llama3.2-vision:90b-instruct-q8_0) +2025-04-25 11:15:43,408 - LlamaVision - INFO - Initializing LlamaVision with model llama3.2-vision:90b-instruct-q8_0 (English-only mode) +2025-04-25 11:15:43,408 - AgentFactoryLlamaVision - INFO - Création de l'agent de tickets (llama_vision) +2025-04-25 11:15:43,408 - AgentTicketAnalyser - INFO - AgentTicketAnalyser initialisé +2025-04-25 11:15:43,408 - AgentFactoryLlamaVision - INFO - Création de l'agent de tri des images (llama_vision) +2025-04-25 11:15:43,408 - AgentImageSorter - INFO - AgentImageSorter (llama_vision) initialisé +2025-04-25 11:15:43,408 - AgentFactoryLlamaVision - INFO - Création de l'agent d'analyse des images (llama_vision) +2025-04-25 11:15:43,408 - AgentImageAnalyser - INFO - AgentImageAnalyser initialized +2025-04-25 11:15:43,408 - AgentFactoryLlamaVision - INFO - Création de l'agent de génération de rapports (llama_vision) +2025-04-25 11:15:43,408 - AgentReportGenerator - INFO - LlamaVision mode detected: using English system prompt +2025-04-25 11:15:43,408 - AgentReportGenerator - INFO - AgentReportGenerator initialized +2025-04-25 11:15:43,408 - MainLlamaVision - INFO - Configuration: { "dedup_enabled": true, "dedup_threshold": 5, "save_results": false, @@ -24,23 +24,23 @@ "english_only": true, "model_name": "llama3-2-vision-90b-instruct-q8-0" } -2025-04-25 09:49:53,231 - MainLlamaVision - INFO - Création de l'orchestrateur pour le ticket T11143 -2025-04-25 09:49:53,232 - OrchestratorLlamaVision - INFO - OrchestratorLlamaVision initialisé avec les paramètres: {'dedup_enabled': True, 'dedup_threshold': 5, 'save_results': False, 'debug_mode': False, 'reports_dir': 'reports', 'ocr_enabled': True, 'english_only': True, 'model_name': 'llama3-2-vision-90b-instruct-q8-0'} -2025-04-25 09:49:53,232 - MainLlamaVision - INFO - Démarrage de l'analyse du ticket T11143 -2025-04-25 09:49:53,232 - OrchestratorLlamaVision - INFO - Traitement du ticket T11143 -2025-04-25 09:49:53,232 - OrchestratorLlamaVision - INFO - Utilisation du modèle: llama3-2-vision-90b-instruct-q8-0 -2025-04-25 09:49:53,232 - OrchestratorLlamaVision - INFO - Données du ticket chargées depuis output/ticket_T11143/T11143_20250422_084617/T11143_rapports/T11143_rapport.json avec 3 messages -2025-04-25 09:49:53,232 - OrchestratorLlamaVision - INFO - Traduction du contenu du ticket T11143 en anglais -2025-04-25 09:49:53,450 - OrchestratorLlamaVision - INFO - Traduction terminée: 984 caractères -2025-04-25 09:49:53,451 - OrchestratorLlamaVision - INFO - Exécution de l'agent d'analyse de ticket pour T11143 -2025-04-25 09:49:53,451 - AgentTicketAnalyser - INFO - Utilisation du contenu déjà traduit pour le ticket T11143 -2025-04-25 09:51:19,575 - OrchestratorLlamaVision - INFO - Analyse du ticket terminée: 1395 caractères -2025-04-25 09:51:19,588 - OrchestratorLlamaVision - INFO - 6 images trouvées dans output/ticket_T11143/T11143_20250422_084617/attachments -2025-04-25 09:51:19,848 - OrchestratorLlamaVision - INFO - Traitement OCR de 4 images -2025-04-25 09:51:19,848 - OCR - INFO - Traitement OCR pour output/ticket_T11143/T11143_20250422_084617/attachments/image.png (langue: auto) -2025-04-25 09:51:22,557 - OCR - INFO - Langue détectée: eng -2025-04-25 09:51:23,197 - OCR - WARNING - Impossible de sauvegarder les fichiers de débogage: cannot write mode RGBA as JPEG -2025-04-25 09:51:23,197 - OCR - INFO - OCR réussi [output/ticket_T11143/T11143_20250422_084617/attachments/image.png] — 1347 caractères: Apache Tomcat x + +2025-04-25 11:15:43,408 - MainLlamaVision - INFO - Création de l'orchestrateur pour le ticket T11143 +2025-04-25 11:15:43,408 - OrchestratorLlamaVision - INFO - OrchestratorLlamaVision initialisé avec les paramètres: {'dedup_enabled': True, 'dedup_threshold': 5, 'save_results': False, 'debug_mode': False, 'reports_dir': 'reports', 'ocr_enabled': True, 'english_only': True, 'model_name': 'llama3-2-vision-90b-instruct-q8-0'} +2025-04-25 11:15:43,408 - MainLlamaVision - INFO - Démarrage de l'analyse du ticket T11143 +2025-04-25 11:15:43,408 - OrchestratorLlamaVision - INFO - Traitement du ticket T11143 +2025-04-25 11:15:43,409 - OrchestratorLlamaVision - INFO - Utilisation du modèle: llama3-2-vision-90b-instruct-q8-0 +2025-04-25 11:15:43,409 - OrchestratorLlamaVision - INFO - Données du ticket chargées depuis output/ticket_T11143/T11143_20250422_084617/T11143_rapports/T11143_rapport.json avec 3 messages +2025-04-25 11:15:43,409 - OrchestratorLlamaVision - INFO - Traduction du contenu du ticket T11143 en anglais +2025-04-25 11:15:43,646 - OrchestratorLlamaVision - INFO - Traduction terminée: 984 caractères +2025-04-25 11:15:43,646 - OrchestratorLlamaVision - INFO - Exécution de l'agent d'analyse de ticket pour T11143 +2025-04-25 11:15:43,647 - AgentTicketAnalyser - INFO - Utilisation du contenu déjà traduit pour le ticket T11143 +2025-04-25 11:17:10,701 - OrchestratorLlamaVision - INFO - Analyse du ticket terminée: 1395 caractères +2025-04-25 11:17:10,713 - OrchestratorLlamaVision - INFO - 6 images trouvées dans output/ticket_T11143/T11143_20250422_084617/attachments +2025-04-25 11:17:10,926 - OrchestratorLlamaVision - INFO - Traitement OCR de 4 images +2025-04-25 11:17:10,926 - OCR - INFO - Traitement OCR pour output/ticket_T11143/T11143_20250422_084617/attachments/image.png (langue: auto) +2025-04-25 11:17:13,663 - OCR - INFO - Langue détectée: eng +2025-04-25 11:17:14,315 - OCR - WARNING - Impossible de sauvegarder les fichiers de débogage: cannot write mode RGBA as JPEG +2025-04-25 11:17:14,315 - OCR - INFO - OCR réussi [output/ticket_T11143/T11143_20250422_084617/attachments/image.png] — 1347 caractères: Apache Tomcat x + GC @ 2 zk1.brg-lab.com @@ -49,53 +49,72 @@ GC @ 2 zk1.brg-lab.com It works ! If you're ... -2025-04-25 09:51:23,521 - Translate - INFO - Sauvegarde JSON OCR/TRAD réussie pour image.png -2025-04-25 09:51:23,522 - Translate - INFO - Ligne ajoutée dans ocr_traduction.txt pour image.png -2025-04-25 09:51:23,522 - OrchestratorLlamaVision - INFO - OCR terminé pour image.png: 1347 caractères (en) -2025-04-25 09:51:23,522 - OCR - INFO - Traitement OCR pour output/ticket_T11143/T11143_20250422_084617/attachments/image_145435.png (langue: auto) -2025-04-25 09:51:24,600 - OCR - INFO - Langue détectée: fra -2025-04-25 09:51:24,885 - OCR - INFO - Images prétraitées et résultat OCR sauvegardés dans debug_ocr -2025-04-25 09:51:24,885 - OCR - INFO - OCR réussi [output/ticket_T11143/T11143_20250422_084617/attachments/image_145435.png] — 373 caractères: C3 giraudbrg-lobicom/BRG-LAB/PAGE programmetssai/zEAAAHEVNGOAA +2025-04-25 11:17:14,626 - Translate - INFO - Sauvegarde JSON OCR/TRAD réussie pour image.png +2025-04-25 11:17:14,627 - Translate - INFO - Ligne ajoutée dans ocr_traduction.txt pour image.png +2025-04-25 11:17:14,627 - OrchestratorLlamaVision - INFO - OCR terminé pour image.png: 1347 caractères (en) +2025-04-25 11:17:14,627 - OCR - INFO - Traitement OCR pour output/ticket_T11143/T11143_20250422_084617/attachments/image_145435.png (langue: auto) +2025-04-25 11:17:15,716 - OCR - INFO - Langue détectée: fra +2025-04-25 11:17:15,992 - OCR - INFO - Images prétraitées et résultat OCR sauvegardés dans debug_ocr +2025-04-25 11:17:15,993 - OCR - INFO - OCR réussi [output/ticket_T11143/T11143_20250422_084617/attachments/image_145435.png] — 373 caractères: C3 giraudbrg-lobicom/BRG-LAB/PAGE programmetssai/zEAAAHEVNGOAA BRGLAS CD Béton CD Foumasew tubo © ... -2025-04-25 09:51:25,226 - Translate - INFO - Sauvegarde JSON OCR/TRAD réussie pour image_145435.png -2025-04-25 09:51:25,226 - Translate - INFO - Ligne ajoutée dans ocr_traduction.txt pour image_145435.png -2025-04-25 09:51:25,226 - OrchestratorLlamaVision - INFO - OCR terminé pour image_145435.png: 373 caractères (fr) -2025-04-25 09:51:25,226 - OCR - INFO - Traitement OCR pour output/ticket_T11143/T11143_20250422_084617/attachments/543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg (langue: auto) -2025-04-25 09:51:27,097 - OCR - INFO - Langue détectée: fra -2025-04-25 09:51:28,242 - OCR - WARNING - OCR vide (aucun texte détecté) pour output/ticket_T11143/T11143_20250422_084617/attachments/543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg -2025-04-25 09:51:28,243 - Translate - INFO - Sauvegarde JSON OCR/TRAD réussie pour 543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg -2025-04-25 09:51:28,243 - Translate - INFO - Ligne ajoutée dans ocr_traduction.txt pour 543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg -2025-04-25 09:51:28,243 - OrchestratorLlamaVision - INFO - OCR terminé pour 543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg: 0 caractères (unknown) -2025-04-25 09:51:28,243 - OCR - INFO - Traitement OCR pour output/ticket_T11143/T11143_20250422_084617/attachments/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif (langue: auto) -2025-04-25 09:51:28,243 - OCR - ERROR - Erreur lors du prétraitement de l'image output/ticket_T11143/T11143_20250422_084617/attachments/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif: image has wrong mode -2025-04-25 09:51:28,475 - OCR - INFO - Langue détectée: fra -2025-04-25 09:51:28,580 - OCR - WARNING - OCR vide (aucun texte détecté) pour output/ticket_T11143/T11143_20250422_084617/attachments/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif -2025-04-25 09:51:28,580 - Translate - INFO - Sauvegarde JSON OCR/TRAD réussie pour a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif -2025-04-25 09:51:28,581 - Translate - INFO - Ligne ajoutée dans ocr_traduction.txt pour a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif -2025-04-25 09:51:28,581 - OrchestratorLlamaVision - INFO - OCR terminé pour a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif: 0 caractères (unknown) -2025-04-25 09:51:28,581 - OrchestratorLlamaVision - INFO - Traitement de 4 images uniques avec l'agent de tri -2025-04-25 09:52:18,867 - AgentImageSorter - WARNING - Image trop petite: output/ticket_T11143/T11143_20250422_084617/attachments/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif (1x1) -2025-04-25 09:52:18,868 - AgentImageSorter - INFO - Sauvegarde de 4 résultats de tri d'images -2025-04-25 09:52:18,871 - OrchestratorLlamaVision - INFO - Sauvegarde groupée de 4 résultats de tri d'images effectuée -2025-04-25 09:52:18,871 - OrchestratorLlamaVision - INFO - Début de l'analyse des images avec 2 images pertinentes -2025-04-25 09:52:18,871 - OrchestratorLlamaVision - INFO - Analyse de l'image: image.png -2025-04-25 09:54:07,055 - OrchestratorLlamaVision - INFO - Analyse terminée pour image.png -2025-04-25 09:54:07,056 - OrchestratorLlamaVision - INFO - Analyse de l'image: image_145435.png -2025-04-25 09:56:18,840 - OrchestratorLlamaVision - INFO - Analyse terminée pour image_145435.png -2025-04-25 09:56:18,840 - AgentImageAnalyser - INFO - Sauvegarde de 2 résultats d'analyse d'images -2025-04-25 09:56:18,842 - OrchestratorLlamaVision - INFO - Sauvegarde des résultats d'analyse d'images via sauvegarder_resultats -2025-04-25 09:56:18,843 - AgentReportGenerator - DEBUG - Data received for T11143: {"ticket_id": "T11143", "ticket_data": {"id": "11122", "code": "T11143", "name": "BRGLAB - Essai inaccessible", "description": "*Contenu non extractible*", "project_name": "Demandes", "stage_name": "Cl\u00f4tur\u00e9", "user_id": "", "partner_id_email_from": "GIRAUD TP (JCG), Victor BOLL\u00c9E, v.bollee@labojcg.fr", "create_date": "03/04/2025 08:34:43", "write_date_last_modification": "03/04/2025 12:23:31", "date_deadline": "18/04/2025 00:00:00", "messages": [{"author_id": "Fabien LAFAY", "date... -2025-04-25 09:56:18,843 - AgentReportGenerator - INFO - Validation for T11143: OK, 2 images analyzed out of 4 images -2025-04-25 09:56:18,843 - AgentReportGenerator - INFO - Number of images to analyze: 4 -2025-04-25 09:56:18,843 - AgentReportGenerator - INFO - Adding analysis of image image.png (2 characters) -2025-04-25 09:56:18,843 - AgentReportGenerator - INFO - Adding analysis of image image_145435.png (2 characters) -2025-04-25 09:56:18,843 - AgentReportGenerator - WARNING - Image 543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg without analysis -2025-04-25 09:56:18,843 - AgentReportGenerator - WARNING - Image a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif without analysis -2025-04-25 09:56:18,843 - AgentReportGenerator - INFO - Size of ticket analysis: 6 characters -2025-04-25 09:56:18,843 - AgentReportGenerator - INFO - Size of image block: 10442 characters -2025-04-25 09:56:18,843 - AgentReportGenerator - DEBUG - Generated prompt (16633 characters): Voici les données d'analyse pour un ticket de support : +2025-04-25 11:17:16,307 - Translate - INFO - Sauvegarde JSON OCR/TRAD réussie pour image_145435.png +2025-04-25 11:17:16,307 - Translate - INFO - Ligne ajoutée dans ocr_traduction.txt pour image_145435.png +2025-04-25 11:17:16,307 - OrchestratorLlamaVision - INFO - OCR terminé pour image_145435.png: 373 caractères (fr) +2025-04-25 11:17:16,307 - OCR - INFO - Traitement OCR pour output/ticket_T11143/T11143_20250422_084617/attachments/543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg (langue: auto) +2025-04-25 11:17:18,195 - OCR - INFO - Langue détectée: fra +2025-04-25 11:17:19,352 - OCR - WARNING - OCR vide (aucun texte détecté) pour output/ticket_T11143/T11143_20250422_084617/attachments/543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg +2025-04-25 11:17:19,353 - Translate - INFO - Sauvegarde JSON OCR/TRAD réussie pour 543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg +2025-04-25 11:17:19,353 - Translate - INFO - Ligne ajoutée dans ocr_traduction.txt pour 543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg +2025-04-25 11:17:19,353 - OrchestratorLlamaVision - INFO - OCR terminé pour 543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg: 0 caractères (unknown) +2025-04-25 11:17:19,353 - OCR - INFO - Traitement OCR pour output/ticket_T11143/T11143_20250422_084617/attachments/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif (langue: auto) +2025-04-25 11:17:19,353 - OCR - ERROR - Erreur lors du prétraitement de l'image output/ticket_T11143/T11143_20250422_084617/attachments/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif: image has wrong mode +2025-04-25 11:17:19,584 - OCR - INFO - Langue détectée: fra +2025-04-25 11:17:19,698 - OCR - WARNING - OCR vide (aucun texte détecté) pour output/ticket_T11143/T11143_20250422_084617/attachments/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif +2025-04-25 11:17:19,698 - Translate - INFO - Sauvegarde JSON OCR/TRAD réussie pour a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif +2025-04-25 11:17:19,699 - Translate - INFO - Ligne ajoutée dans ocr_traduction.txt pour a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif +2025-04-25 11:17:19,699 - OrchestratorLlamaVision - INFO - OCR terminé pour a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif: 0 caractères (unknown) +2025-04-25 11:17:19,699 - OrchestratorLlamaVision - INFO - Traitement de 4 images uniques avec l'agent de tri +2025-04-25 11:18:08,970 - AgentImageSorter - WARNING - Image trop petite: output/ticket_T11143/T11143_20250422_084617/attachments/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif (1x1) +2025-04-25 11:18:08,970 - AgentImageSorter - INFO - Sauvegarde de 4 résultats de tri d'images +2025-04-25 11:18:08,971 - OrchestratorLlamaVision - INFO - Sauvegarde groupée de 4 résultats de tri d'images effectuée +2025-04-25 11:18:08,971 - OrchestratorLlamaVision - INFO - Début de l'analyse des images avec 2 images pertinentes +2025-04-25 11:18:08,971 - OrchestratorLlamaVision - INFO - Analyse de l'image: image.png +2025-04-25 11:19:56,920 - OrchestratorLlamaVision - INFO - Analyse terminée pour image.png +2025-04-25 11:19:56,921 - OrchestratorLlamaVision - INFO - Analyse de l'image: image_145435.png +2025-04-25 11:22:08,008 - OrchestratorLlamaVision - INFO - Analyse terminée pour image_145435.png +2025-04-25 11:22:08,009 - AgentImageAnalyser - INFO - Sauvegarde de 2 résultats d'analyse d'images +2025-04-25 11:22:08,010 - OrchestratorLlamaVision - INFO - Sauvegarde des résultats d'analyse d'images via sauvegarder_resultats +2025-04-25 11:22:08,010 - AgentReportGenerator - DEBUG - Data received for T11143: {"ticket_id": "T11143", "ticket_data": {"id": "11122", "code": "T11143", "name": "BRGLAB - Essai inaccessible", "description": "*Contenu non extractible*", "project_name": "Demandes", "stage_name": "Cl\u00f4tur\u00e9", "user_id": "", "partner_id_email_from": "GIRAUD TP (JCG), Victor BOLL\u00c9E, v.bollee@labojcg.fr", "create_date": "03/04/2025 08:34:43", "write_date_last_modification": "03/04/2025 12:23:31", "date_deadline": "18/04/2025 00:00:00", "messages": [{"author_id": "Fabien LAFAY", "date... +2025-04-25 11:22:08,010 - AgentReportGenerator - INFO - Validation for T11143: OK, 2 images analyzed out of 4 images +2025-04-25 11:22:08,010 - AgentReportGenerator - INFO - Number of images to analyze: 4 +2025-04-25 11:22:08,010 - AgentReportGenerator - INFO - Adding analysis of image image.png (2 characters) +2025-04-25 11:22:08,010 - AgentReportGenerator - INFO - Adding analysis of image image_145435.png (2 characters) +2025-04-25 11:22:08,010 - AgentReportGenerator - WARNING - Image 543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg without analysis +2025-04-25 11:22:08,010 - AgentReportGenerator - WARNING - Image a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif without analysis +2025-04-25 11:22:08,010 - AgentReportGenerator - INFO - Size of ticket analysis: 6 characters +2025-04-25 11:22:08,010 - AgentReportGenerator - INFO - Size of image block: 10442 characters +2025-04-25 11:22:08,011 - AgentReportGenerator - DEBUG - Generated prompt (16633 characters): Voici les données d'analyse pour un ticket de support : === ANALYSE DU TICKET === {'prompt': "TITRE: BRGLAB - Essai inaccessible\n\n[03/04/2025 08:35:20] Fabien LAFAY (Système):\nGIRAUD TP (JCG), Victor BOLLÉE\n-\nil y a 9 minutes\n;\nFabien LAFAY\n;\nRomuald GRUSON\n;\nsupport\n;\nsupport\n-\nQuentin FAIVRE\n-\nFabien LAFAY\n-\nRomuald GRUSON\nBonjour,\nJe ne parviens pas à accéder au l’essai au bleu\xa0:\nMerci par avance pour votre.\nCordialement\n![Image](https://odoo.cbao.fr/web/image/1454... -2025-04-25 09:56:20,646 - AgentReportGenerator - INFO - Translating prompt to English for LlamaVision (15932 characters) +2025-04-25 11:22:10,021 - AgentReportGenerator - INFO - Translating prompt to English for LlamaVision (15932 characters) +2025-04-25 11:23:48,505 - AgentReportGenerator - INFO - Translating response to French (1990 characters) +2025-04-25 11:23:48,506 - AgentReportGenerator - DEBUG - Response received (1990 characters): ** Rapport croisé ** + +** Description du problème: ** +Le client, Fabien Lafay, a signalé un problème à l'accès au test bleu. + +** Tableau chronologique des échanges: ** + +| Émetteur | Type | Date | Contenu | Éléments visuels | +| --- | --- | --- | --- | --- | +| Fabien Lafay (client) | Question | [Rapport initial] | "J'ai du mal à accéder au test bleu." | Capture d'écran du message d'erreur | +| Support | Réponse | [Réponse 1] | "Pouvez-vous fournir plus d'informations sur le message d'erreur?" | Dema... +2025-04-25 11:23:48,508 - OrchestratorLlamaVision - INFO - Traitement terminé pour le ticket T11143 +2025-04-25 11:23:48,508 - MainLlamaVision - INFO - Analyse du ticket T11143 terminée +2025-04-25 11:23:48,508 - MainLlamaVision - INFO - Génération des fichiers CSV pour le ticket T11143 +2025-04-25 11:23:48,508 - ReportCSVExporter - INFO - Traitement du rapport: rapport_final_llama3-2-vision-90b-instruct-q8-0_results.json +2025-04-25 11:23:48,509 - ReportCSVExporter - INFO - CSV échanges généré: /home/fgras-ca/llm-ticket3/CSV/T11143/T11143_llama3-2-vision-90b-instruct-q8-0_exchanges.csv +2025-04-25 11:23:48,509 - ReportCSVExporter - INFO - Traitement terminé. 1 modèles traités: llama3-2-vision-90b-instruct-q8-0 +2025-04-25 11:23:48,509 - MainLlamaVision - INFO - Fichiers CSV générés avec succès diff --git a/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg.json b/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg.json index c3e4384..3b5a818 100644 --- a/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg.json +++ b/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg.json @@ -5,7 +5,7 @@ "translation_en_back_fr": "", "metadata": { "ticket_id": "T11143", - "timestamp": "20250425_095128", + "timestamp": "20250425_111719", "source_module": "ocr_utils + translate_utils", "lang_detected": "fr" } diff --git a/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif.json b/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif.json index 38b0928..b19845b 100644 --- a/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif.json +++ b/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif.json @@ -5,7 +5,7 @@ "translation_en_back_fr": "", "metadata": { "ticket_id": "T11143", - "timestamp": "20250425_095128", + "timestamp": "20250425_111719", "source_module": "ocr_utils + translate_utils", "lang_detected": "fr" } diff --git a/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/image.png.json b/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/image.png.json index faa7e13..07a5b9f 100644 --- a/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/image.png.json +++ b/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/image.png.json @@ -5,7 +5,7 @@ "translation_en_back_fr": "Apache Tomcat x +\n\nGc @ 2 zk1.brg-b.com\n\n@ Andre Demo Devmat @ Modèle de base\n\nÇa marche!\n\nSi vous voyez cette page via un navigateur Web, cela signifie que vous avez configuré Tomcat avec succès. Félicitations!\n\nIl s'agit de la page d'accueil par défaut de Tomcat. Il peut être trouvé sur le système de fichiers local à: /var/lib/tomcat7/webapps/root/index.html\n\nMatou? Les vétérans pourraient être ravis de lire cette instance système de Tomcat est installé avec cataina_home dans / usr / tomcat7 et cataina_base dans / var / 1ib / tomcat7, en suivant les règles de / usr / share / doc / tomcat7-commun / running. SMS. GZ.\nVous pourriez envisager d'installer les packages suivants, si vous avez fait Alreni:\n\nTomcat7-Docs: Ce package installe une application Web qui permet de parcourir la documentation Tomcat 7 localement. Une fois installé, vous pouvez y accéder en cliquant\n\nTomcat7-Exemple: Ce package installe une application Web qui permet d'accéder aux exemples de servlet Tomcat 7 et JSP. Une fois installé, vous pouvez y accéder en cliquant\n\nTomcat7-admin: Ce package installe deux applications Web qui peuvent aider à gérer cette instance Tomcat. Une fois installé, vous pouvez accéder au et le et le et\n\nRemarque: Pour des raisons de sécurité, l'utilisation du gestionnaire WebApp est limitée aux utilisateurs avec le rôle \"Manager-Gui\". Le manager host-manager est limité aux utilisateurs avec un rôle \"Admin-Gui\". Les utilisateurs sont définis dans / et / tomcat7 / tomcta-users.xml.", "metadata": { "ticket_id": "T11143", - "timestamp": "20250425_095123", + "timestamp": "20250425_111714", "source_module": "ocr_utils + translate_utils", "lang_detected": "fr" } diff --git a/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/image_145435.png.json b/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/image_145435.png.json index 32425a5..4b27d3b 100644 --- a/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/image_145435.png.json +++ b/output/ticket_T11143/T11143_20250422_084617/T11143_rapports/pipeline/ocr_traduction/image_145435.png.json @@ -5,7 +5,7 @@ "translation_en_back_fr": "C3 Giraudbrg-Lobicom / Brg-Lab / Page Progratsai / Zeaaahevngoaaaa\n\n Brglas cd béton cd foumasew tubo © masse\n\nECHANTILLION N ° 25-0007 ECEPTIAN le 02/04/2025 PR Bollé Victor prévu le 04/04/2025 Por Bollee Victor N ° Pédéwment 25-00078\nMatériau de sable 0/20 Carriere adceg\n\n[Fai Jemmarme | [M Porrouo || onservanons] [ str: - """ - Encode une image en base64, avec optimisation de la taille si nécessaire. - Implémentation identique à celle de LlamaVision._encoder_image_base64 - """ - try: - # Vérifier la taille de l'image et la réduire si trop grande - with Image.open(image_path) as img: - # Afficher les informations de l'image originale - print(f"Image originale: {image_path}") - print(f"Format: {img.format}, Mode: {img.mode}, Taille: {img.size}") - - # Si l'image est trop grande, la redimensionner - max_dim = 800 # Dimension maximale - width, height = img.size - - if width > max_dim or height > max_dim: - # Calculer le ratio pour conserver les proportions - ratio = min(max_dim / width, max_dim / height) - new_width = int(width * ratio) - new_height = int(height * ratio) - - # Redimensionner l'image - img = img.resize((new_width, new_height), Image.Resampling.LANCZOS) - print(f"Image redimensionnée: {new_width}x{new_height}") - - # Convertir en RGB si nécessaire (pour les formats comme PNG avec canal alpha) - original_mode = img.mode - if img.mode in ("RGBA", "LA", "P"): - # Créer un fond blanc et composer l'image dessus pour gérer la transparence - background = Image.new("RGB", img.size, (255, 255, 255)) - if img.mode == "P": - img = img.convert("RGBA") - background.paste(img, mask=img.split()[3] if img.mode == "RGBA" else None) - img = background - print(f"Mode converti: {original_mode} -> RGB (avec fond blanc)") - elif img.mode != "RGB": - img = img.convert("RGB") - print(f"Mode converti: {original_mode} -> RGB") - - # Sauvegarder temporairement l'image redimensionnée - buffer = io.BytesIO() - img.save(buffer, format="JPEG", quality=85) - buffer.seek(0) - - # Sauvegarder l'image traitée si demandé - if args.save: - output_path = f"processed_{os.path.basename(image_path)}.jpg" - img.save(output_path, format="JPEG", quality=85) - print(f"Image traitée sauvegardée: {output_path}") - - # Encoder en base64 - encoded = base64.b64encode(buffer.read()).decode("utf-8") - print(f"Taille du base64: {len(encoded)} caractères") - return encoded - - except Exception as e: - print(f"Erreur lors de l'optimisation de l'image: {str(e)}") - try: - # Seconde tentative avec une approche plus simple - print("Tentative de secours...") - with Image.open(image_path) as img: - # Convertir directement en RGB quelle que soit l'image - img = img.convert("RGB") - buffer = io.BytesIO() - img.save(buffer, format="JPEG", quality=75) - buffer.seek(0) - - if args.save: - output_path = f"fallback_{os.path.basename(image_path)}.jpg" - img.save(output_path, format="JPEG", quality=75) - print(f"Image de secours sauvegardée: {output_path}") - - encoded = base64.b64encode(buffer.read()).decode("utf-8") - print(f"Taille du base64 (secours): {len(encoded)} caractères") - return encoded - except Exception as e2: - print(f"Deuxième erreur lors de l'optimisation de l'image: {str(e2)}") - # Dernier recours: encoder l'image originale sans optimisation - print("Dernier recours: encodage sans optimisation...") - with open(image_path, "rb") as image_file: - encoded = base64.b64encode(image_file.read()).decode("utf-8") - print(f"Taille du base64 (brut): {len(encoded)} caractères") - return encoded - -def test_image_processing(image_path, verbose=False): - """ - Teste le prétraitement d'image utilisé par LlamaVision - """ - if not os.path.exists(image_path): - print(f"Erreur: L'image {image_path} n'existe pas") - return - - # Analyser l'image avec Pillow - try: - with Image.open(image_path) as img: - print("\n=== INFORMATIONS SUR L'IMAGE ===") - print(f"Format: {img.format}") - print(f"Mode: {img.mode}") - print(f"Taille: {img.size}") - print(f"Palette: {hasattr(img, 'palette')}") - if hasattr(img, 'info'): - print(f"Info supplémentaires: {img.info.keys()}") - except Exception as e: - print(f"Erreur lors de l'analyse de l'image: {e}") - return - - # Encoder l'image - print("\n=== TRAITEMENT DE L'IMAGE ===") - encoded = encoder_image_base64(image_path) - - # Sauvegarder des métadonnées - metadata = { - "filename": os.path.basename(image_path), - "path": image_path, - "base64_length": len(encoded), - "first_20_chars": encoded[:20], - "timestamp": __import__('datetime').datetime.now().strftime("%Y-%m-%d %H:%M:%S") - } - - output_file = f"image_info_{os.path.basename(image_path)}.json" - with open(output_file, "w", encoding="utf-8") as f: - json.dump(metadata, f, ensure_ascii=False, indent=2) - - print(f"\nMétadonnées enregistrées dans {output_file}") - - # Sauvegarder un extrait du base64 - if verbose: - print("\n=== EXTRAIT DU BASE64 ===") - print(encoded[:100] + "...") - -if __name__ == "__main__": - args = parse_args() - test_image_processing(args.image_path, args.verbose) \ No newline at end of file diff --git a/test_image_sorter.py b/test_image_sorter.py deleted file mode 100644 index 41fc738..0000000 --- a/test_image_sorter.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import os -import sys -import argparse -import json -from llm_classes.llama_vision import LlamaVision -from agents.llama_vision.agent_image_sorter import AgentImageSorter - -def parse_args(): - parser = argparse.ArgumentParser(description="Test de l'agent de tri d'images") - parser.add_argument("image_path", help="Chemin vers l'image à analyser") - parser.add_argument("--debug", "-d", action="store_true", help="Mode debug") - parser.add_argument("--ticket_id", "-t", default="T9999", help="ID du ticket pour les tests") - return parser.parse_args() - -def main(): - args = parse_args() - image_path = args.image_path - - if not os.path.exists(image_path): - print(f"Erreur: L'image {image_path} n'existe pas") - return 1 - - print(f"=== TEST DE L'AGENT DE TRI D'IMAGES ===") - print(f"Image: {image_path}") - - # Initialiser le modèle LlamaVision - try: - print("Initialisation du modèle LlamaVision...") - llm = LlamaVision() # modèle par défaut - print(f"Modèle initialisé: {llm.modele}") - except Exception as e: - print(f"Erreur lors de l'initialisation du modèle: {e}") - return 1 - - # Initialiser l'agent de tri - try: - print("Initialisation de l'agent de tri d'images...") - agent = AgentImageSorter(llm) - print("Agent initialisé") - except Exception as e: - print(f"Erreur lors de l'initialisation de l'agent: {e}") - return 1 - - # Exécuter l'agent sur l'image - try: - print("\nExécution de l'agent sur l'image...") - result = agent.executer(image_path) - - # Afficher le résultat - print("\n=== RÉSULTAT ===") - print(f"Image pertinente: {result['is_relevant']}") - print(f"Raison: {result['reason']}") - - if args.debug: - print("\n=== RÉPONSE BRUTE ===") - print(result['raw_response']) - print("\n=== OCR ===") - print(f"OCR FR: {result['ocr_fr'] or 'Aucun texte détecté'}") - print(f"OCR EN: {result['ocr_en'] or 'Aucune traduction'}") - - # Sauvegarder le résultat dans un fichier JSON - output_file = f"test_tri_{os.path.basename(image_path)}.json" - with open(output_file, "w", encoding="utf-8") as f: - json.dump(result, f, ensure_ascii=False, indent=2) - print(f"\nRésultat enregistré dans {output_file}") - - return 0 - except Exception as e: - print(f"Erreur lors de l'exécution de l'agent: {e}") - import traceback - traceback.print_exc() - return 1 - -if __name__ == "__main__": - sys.exit(main()) \ No newline at end of file diff --git a/test_ocr.py b/test_ocr.py deleted file mode 100644 index 51343ae..0000000 --- a/test_ocr.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import os -import sys -import argparse -import json -from PIL import Image -from utils.ocr_utils import extraire_texte_fr -from utils.translate_utils import fr_to_en, en_to_fr - -def parse_args(): - parser = argparse.ArgumentParser(description="Test direct d'OCR et traduction") - parser.add_argument("image_path", help="Chemin vers l'image à analyser") - parser.add_argument("--verbose", "-v", action="store_true", help="Mode verbeux") - parser.add_argument("--info", "-i", action="store_true", help="Afficher les infos de l'image") - return parser.parse_args() - -def test_ocr_traduction(image_path, verbose=False, show_info=False): - """ - Teste l'OCR et la traduction sur une image spécifique - """ - # Vérification de l'existence du fichier - if not os.path.exists(image_path): - print(f"Erreur: Le fichier {image_path} n'existe pas") - return - - # Afficher les infos sur l'image si demandé - if show_info: - try: - with Image.open(image_path) as img: - print(f"Format: {img.format}") - print(f"Mode: {img.mode}") - print(f"Taille: {img.size}") - print(f"Palette: {hasattr(img, 'palette')}") - except Exception as e: - print(f"Erreur lors de l'analyse de l'image: {e}") - return - - # Exécution de l'OCR - print(f"Exécution de l'OCR sur {image_path}...") - ocr_fr = extraire_texte_fr(image_path) - - # Affichage du résultat OCR - if ocr_fr: - print("\n--- TEXTE DÉTECTÉ (FR) ---") - print(ocr_fr) - print("-------------------------") - else: - print("Aucun texte détecté par l'OCR") - - # Traduction si du texte a été détecté - if ocr_fr: - print("\nTraduction FR -> EN...") - ocr_en = fr_to_en(ocr_fr) - print("\n--- TRADUCTION (EN) ---") - print(ocr_en) - print("-------------------------") - - print("\nTraduction EN -> FR (vérification)...") - ocr_en_back_fr = en_to_fr(ocr_en) - print("\n--- TRADUCTION RETOUR (FR) ---") - print(ocr_en_back_fr) - print("-------------------------") - - # Enregistrer les résultats dans un JSON - results = { - "filename": os.path.basename(image_path), - "ocr_fr": ocr_fr, - "ocr_en": ocr_fr and fr_to_en(ocr_fr) or "", - "ocr_en_back_fr": ocr_fr and en_to_fr(fr_to_en(ocr_fr)) or "", - } - - output_file = f"ocr_test_{os.path.basename(image_path)}.json" - with open(output_file, "w", encoding="utf-8") as f: - json.dump(results, f, ensure_ascii=False, indent=2) - - print(f"\nRésultats enregistrés dans {output_file}") - -if __name__ == "__main__": - args = parse_args() - test_ocr_traduction(args.image_path, args.verbose, args.info) \ No newline at end of file diff --git a/test_ocr_image.png b/test_ocr_image.png deleted file mode 100644 index ea8c1c6e5483fdea49f51d6c1e1104e318e77430..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1066 zcmeAS@N?(olHy`uVBq!ia0vp^CxF<9g9%7ZGiKh#z`*>`)5S5QV$R!JwjNd4497oS z-mfvmK|m*Xg{nbE+y|b-X>y-aGj*f2oHIISDMdF;b5P09kkSgct<)l;<)f@|Y0<)i zM-Q4UcKFcibo$hDzV`o$yKcTMt9{pc`n~bo&p&LQ+ok(SF&3l{`vO!0bp`SNA)avl~Y zXJ_a5H|@{AR=q9TU0`Kpr6tzg-`{`QPUymy$s1ghCjK*jD628oZ};7I=gyrwdi1D& z_(c2Gspp?h^;#OE_uoY4pWfcRdxKU^sh_U3UEb-$*|WYtFB{FQv48RX_wi%L_Wf)K zh!m|j?xi;QVL^mNUQUjV`Q;QNPGe5R=g*&ub-OOV92*z+NqK2dW=+kX!%@>uKP|D^ zf8+e&!_22Q9dcc^e0h9a9Eali_3PjNZ#%SqB~!e4NN8x}+OU6@W3;Ab<>l#_7w6@j zdsy(K$g(YQ)6F-3{_HvYaK@}zQ4tXpb#-YHY3b?h_7&%I%;IBXYd=0boVNMwxpUvX zeEFcfGv?g;@5VgBoh~6-SM6(UeoUMtzXli)GRHq22gbw8lDxb;VBB`QEPC}SYy0ik zyoE=TcJAG4D#24)T6#38FfHv^hKUi6aR2ehX;V+8@bdD$e*IcLY-Px*43j9WsdayU zJ-L41^;bDr*`+}%dwY9<>EiF-ze|^@&OW>QdGq|P{ZCjgSwFy`TFnGH9xvX