2504-11:47

This commit is contained in:
Ladebeze66 2025-04-25 11:47:57 +02:00
parent c75faf7905
commit b1e78f2b7d
16 changed files with 238 additions and 752 deletions

View File

@ -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)
}

View File

@ -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 = {

View File

@ -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)

View File

@ -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)
}

View File

@ -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 lessai 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

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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] [<suo] [v hisromou\n\nposé. à partir de 11 e z2k1.brg-lab.com",
"metadata": {
"ticket_id": "T11143",
"timestamp": "20250425_095125",
"timestamp": "20250425_111716",
"source_module": "ocr_utils + translate_utils",
"lang_detected": "fr"
}

View File

@ -108,113 +108,3 @@ a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif
[EN] _
[EN→FR] _
image.png
[FR] Apache Tomcat x +
GC @ 2 zk1.brg-lab.com
@ Andre Demo Devmat @ Base modéle
It works !
If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!
This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat7/webapps/ROOT/index.html
Tomcat? veterans might be pleased to learn that this system instance of Tomcat is installed with CATALINA_HOME in /usr/share/tomcat7 and CATALINA_BASE in /var/1ib/tomcat7, following the rules from /usr/share/doc/tomcat7-common/RUNNING. txt. gz.
You might consider installing the following packages, if you haven't already done so:
tomcat7-docs: This package installs a web application that allows to browse the Tomcat 7 documentation locally. Once installed, you can access it by clicking
tomcat7-examples: This package installs a web application that allows to access the Tomcat 7 Servlet and JSP examples. Once installed, you can access it by clicking
tomcat7-admin: This package installs two web applications that can help managing this Tomcat instance. Once installed, you can access the and the
NOTE: For security reasons, using the manager webapp is restricted to users with role "manager-gui". The host-manager webapp is restricted to users with role "admin-gui". Users are defined in /etc/tomcat7/tomcat-users.xml.
[EN] Apache Tomcat x +
GC @ 2 zk1.brg-lab.com
@ Andre Demo Devmat @ Base model
It works!
If you are seeing this page via a web browser, it means you've setup tomcat successfully. Congratulations!
This is the Default Tomcat Home Page. It can be found on the local Filesystem at: /var/lib/tomcat7/webapps/root/index.html
Tomcat? veterans might be pleased to read this system instance of tomcat is installed with catalina_home in/usr/tomcat7 and catalina_base in/var/1ib/tomcat7, following the rules from/usr/share/doc/tomcat7-common/Running. TXT. Gz.
You might consider installing the following packages, if you have alreni done so:
Tomcat7-Docs: This Package Installes A Web Application that Allows to Browse the Tomcat 7 Locally documentation. Once Installed, you can access it by clicking
Tomcat7-Example: This Package Installes A Web Application that Allows to Access the Tomcat 7 Servlet and JSP Examples. Once Installed, you can access it by clicking
Tomcat7-Admin: This Package Installes Two Web Applications that can help managing this tomcat instance. Once Installed, you can access the and the
Note: For Security Reasons, Using the Manager Webapp is restricted to users with role "manager-gui". The Host-Manager Webapp is restricted to users with role "admin-gui". USERS ARE DEFINED in/and/TOMCAT7/TOMCTA-users.xml.
[EN→FR] Apache Tomcat x +
Gc @ 2 zk1.brg-b.com
@ Andre Demo Devmat @ Modèle de base
Ça marche!
Si vous voyez cette page via un navigateur Web, cela signifie que vous avez configuré Tomcat avec succès. Félicitations!
Il 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
Matou? 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.
Vous pourriez envisager d'installer les packages suivants, si vous avez fait Alreni:
Tomcat7-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
Tomcat7-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
Tomcat7-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
Remarque: 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.
image_145435.png
[FR] C3 giraudbrg-lobicom/BRG-LAB/PAGE programmetssai/zEAAAHEVNGOAA
BRGLAS CD Béton CD Foumasew tubo © Masse
Echantillion n° 25-0007 éceptianné le 02/04/2025 pr BOLLÉE Victor prélevi le 02/04/2025 por BOLLEE Victor n° péédéwement 25-00078
Matériau Sable 0/20 CARRIERE ADCEG
[vEssu JEMmarme |[ M Porrouo || onservanons ][<suo ][V hisromou
posait. de 11 e z2k1.brg-lab.com
[EN] C3 GIRAUDBRG-LOBICOM/BRG-LAB/PAGE PROGRATSSAI/ZEAAAHEVNGOAAA
Brglas CD concrete CD Foumasew Tubo © Mass
Echantillion n ° 25-0007 eceptian on 02/04/2025 PR BOLLÉ Victor prevoted on 04/04/2025 POR BOLLEE Victor N ° Pédéwment 25-00078
Sand material 0/20 CARRIERE ADCEG
[FAI JEMMARME | [M porrouo || onservanons] [<suo] [v hisromou
posed. from 11 e z2k1.brg-lab.com
[EN→FR] C3 Giraudbrg-Lobicom / Brg-Lab / Page Progratsai / Zeaaahevngoaaaa
Brglas cd béton cd foumasew tubo © masse
ECHANTILLION 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
Matériau de sable 0/20 Carriere adceg
[Fai Jemmarme | [M Porrouo || onservanons] [<suo] [v hisromou
posé. à partir de 11 e z2k1.brg-lab.com
543d7da1b54c29ff43ce5712d1a9aa4962ed21795c4e943fcb8cb84fd4d7465a.jpg
[FR] _
[EN] _
[EN→FR] _
a20f7697fd5e1d1fca3296c6d01228220e0e112c46b4440cc938f74d10934e98.gif
[FR] _
[EN] _
[EN→FR] _

View File

@ -1,7 +0,0 @@
2025-04-18 16:27:23,091 - INFO - LLM MistralLarge initialisé pour l'analyse du ticket
2025-04-18 16:27:23,092 - INFO - LLM PixtralLarge initialisé pour le tri d'images
2025-04-18 16:27:23,092 - INFO - LLM PixtralLarge initialisé pour l'analyse d'images
2025-04-18 16:27:23,092 - INFO - AgentTicketAnalyser initialisé
2025-04-18 16:27:23,092 - INFO - AgentImageSorter initialisé
2025-04-18 16:27:23,092 - INFO - AgentImageAnalyser initialisé
2025-04-18 16:27:23,092 - INFO - Analyse du ticket T11143

View File

@ -1,152 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import argparse
import json
import base64
from PIL import Image
import io
def parse_args():
parser = argparse.ArgumentParser(description="Test de prétraitement d'images")
parser.add_argument("image_path", help="Chemin vers l'image à analyser")
parser.add_argument("--save", "-s", action="store_true", help="Sauvegarder les images traitées")
parser.add_argument("--verbose", "-v", action="store_true", help="Mode verbeux")
return parser.parse_args()
def encoder_image_base64(image_path: str) -> 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)

View File

@ -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())

View File

@ -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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,232 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import argparse
import json
import time
from PIL import Image
import pytesseract
from utils.ocr_utils import extraire_texte_fr, pretraiter_image
from utils.translate_utils import fr_to_en, en_to_fr
from llm_classes.llama_vision import LlamaVision
from agents.llama_vision.agent_image_sorter import AgentImageSorter
def parse_args():
parser = argparse.ArgumentParser(description="Test complet OCR + Traduction + Tri d'images")
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("--only-ocr", "-o", action="store_true", help="Tester uniquement l'OCR")
parser.add_argument("--skip-llm", "-s", action="store_true", help="Sauter l'appel au LLM (pour tester rapidement OCR)")
parser.add_argument("--test-dir", "-d", help="Tester toutes les images d'un répertoire")
return parser.parse_args()
def test_image(image_path, verbose=False, only_ocr=False, skip_llm=False):
"""
Teste la chaîne de traitement complète sur une image
"""
start_time = time.time()
print(f"\n=== TEST DE L'IMAGE: {os.path.basename(image_path)} ===")
if not os.path.exists(image_path):
print(f"Erreur: Le fichier {image_path} n'existe pas")
return None
# Afficher les infos sur l'image
try:
with Image.open(image_path) as img:
print(f"Format: {img.format}")
print(f"Mode: {img.mode}")
print(f"Taille: {img.size}")
except Exception as e:
print(f"Erreur lors de l'analyse de l'image: {e}")
return None
# ÉTAPE 1: OCR
print("\n=== ÉTAPE 1: OCR ===")
ocr_time_start = time.time()
# Test avec l'image originale
print("OCR sur image originale...")
ocr_fr_original = ""
try:
with Image.open(image_path) as img:
ocr_fr_original = pytesseract.image_to_string(img, lang="fra").strip()
except Exception as e:
print(f"Erreur OCR image originale: {e}")
if ocr_fr_original:
print(f"Texte détecté (original): {ocr_fr_original}")
else:
print("Aucun texte détecté sur l'image originale")
# Test avec l'image prétraitée
print("\nOCR avec image prétraitée...")
try:
# Utiliser notre fonction de prétraitement
ocr_fr = extraire_texte_fr(image_path)
if ocr_fr:
print(f"Texte détecté (prétraité): {ocr_fr}")
else:
print("Aucun texte détecté après prétraitement")
except Exception as e:
print(f"Erreur lors de l'OCR prétraité: {e}")
ocr_fr = ""
ocr_time = time.time() - ocr_time_start
print(f"Temps OCR: {ocr_time:.2f} secondes")
# Si on s'arrête à l'OCR
if only_ocr:
total_time = time.time() - start_time
print(f"\nTemps total: {total_time:.2f} secondes")
return {
"image": os.path.basename(image_path),
"ocr_fr_original": ocr_fr_original,
"ocr_fr": ocr_fr,
"processing_time": {
"ocr": ocr_time,
"total": total_time
}
}
# ÉTAPE 2: TRADUCTION
print("\n=== ÉTAPE 2: TRADUCTION ===")
translation_time_start = time.time()
ocr_en = ""
if ocr_fr:
try:
ocr_en = fr_to_en(ocr_fr)
print(f"Traduction EN: {ocr_en}")
# Traduction de vérification
ocr_en_back_fr = en_to_fr(ocr_en)
print(f"Traduction retour FR: {ocr_en_back_fr}")
except Exception as e:
print(f"Erreur lors de la traduction: {e}")
else:
print("Aucun texte à traduire")
translation_time = time.time() - translation_time_start
print(f"Temps traduction: {translation_time:.2f} secondes")
# Si on saute l'appel au LLM
if skip_llm:
total_time = time.time() - start_time
print(f"\nTemps total: {total_time:.2f} secondes")
return {
"image": os.path.basename(image_path),
"ocr_fr": ocr_fr,
"ocr_en": ocr_en,
"processing_time": {
"ocr": ocr_time,
"translation": translation_time,
"total": total_time
}
}
# ÉTAPE 3: ANALYSE LLM
print("\n=== ÉTAPE 3: ANALYSE LLM ===")
llm_time_start = time.time()
llm_result = None
try:
# Initialiser le modèle LlamaVision
llm = LlamaVision()
# Initialiser l'agent
agent = AgentImageSorter(llm)
# Exécuter l'agent
llm_result = agent.executer(image_path)
if llm_result:
print(f"Image pertinente: {llm_result['is_relevant']}")
print(f"Raison: {llm_result['reason']}")
else:
print("Erreur: Aucun résultat retourné par l'agent")
except Exception as e:
print(f"Erreur lors de l'analyse LLM: {e}")
llm_time = time.time() - llm_time_start
print(f"Temps LLM: {llm_time:.2f} secondes")
# Temps total
total_time = time.time() - start_time
print(f"\nTemps total: {total_time:.2f} secondes")
# Résultat complet
result = {
"image": os.path.basename(image_path),
"ocr_fr": ocr_fr,
"ocr_en": ocr_en,
"llm_result": llm_result,
"processing_time": {
"ocr": ocr_time,
"translation": translation_time,
"llm": llm_time,
"total": total_time
}
}
# Enregistrer le résultat
output_file = f"complete_test_{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"Résultat enregistré dans: {output_file}")
return result
def test_directory(dir_path, verbose=False, only_ocr=False, skip_llm=False):
"""
Teste toutes les images d'un répertoire
"""
if not os.path.exists(dir_path) or not os.path.isdir(dir_path):
print(f"Le répertoire {dir_path} n'existe pas")
return
# Extensions d'images à tester
extensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.tif', '.webp']
# Trouver toutes les images
image_files = []
for root, _, files in os.walk(dir_path):
for file in files:
if any(file.lower().endswith(ext) for ext in extensions):
image_files.append(os.path.join(root, file))
print(f"=== TEST DE {len(image_files)} IMAGES DANS {dir_path} ===")
results = []
for i, image_path in enumerate(image_files, 1):
print(f"\nImage {i}/{len(image_files)}: {os.path.basename(image_path)}")
result = test_image(image_path, verbose, only_ocr, skip_llm)
if result:
results.append(result)
# Enregistrer les résultats combinés
if results:
output_file = f"batch_test_results.json"
with open(output_file, "w", encoding="utf-8") as f:
json.dump(results, f, ensure_ascii=False, indent=2)
print(f"\nRésultats combinés enregistrés dans: {output_file}")
return results
def main():
args = parse_args()
# Test d'un répertoire
if args.test_dir:
test_directory(args.test_dir, args.verbose, args.only_ocr, args.skip_llm)
# Test d'une seule image
else:
test_image(args.image_path, args.verbose, args.only_ocr, args.skip_llm)
return 0
if __name__ == "__main__":
sys.exit(main())