- Frontend v4 accessible sur réseau local (192.168.1.40) - Ports ouverts: 3002 (frontend), 5001 (backend), 5004 (dashboard) - Ollama GPU fonctionnel - Self-healing interactif - Dashboard confiance Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
181 lines
5.9 KiB
Python
Executable File
181 lines
5.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Test de la vraie détection VLM avec Ollama
|
|
|
|
Ce script teste la détection d'éléments UI avec le VLM réel (pas de simulation).
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Ajouter le répertoire parent au path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from core.detection.ui_detector import UIDetector, DetectionConfig
|
|
from core.detection.ollama_client import check_ollama_available
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
import tempfile
|
|
|
|
|
|
def create_test_screenshot():
|
|
"""Créer un screenshot de test avec des éléments UI simulés"""
|
|
# Créer une image de test
|
|
img = Image.new('RGB', (800, 600), color='white')
|
|
draw = ImageDraw.Draw(img)
|
|
|
|
# Dessiner quelques éléments UI simulés
|
|
# Bouton "Submit"
|
|
draw.rectangle([300, 200, 450, 250], fill='blue', outline='black', width=2)
|
|
draw.text((350, 215), "Submit", fill='white')
|
|
|
|
# Champ de texte
|
|
draw.rectangle([300, 100, 500, 140], fill='white', outline='gray', width=2)
|
|
draw.text((310, 110), "Enter text...", fill='gray')
|
|
|
|
# Checkbox
|
|
draw.rectangle([300, 300, 330, 330], fill='white', outline='black', width=2)
|
|
draw.text((340, 305), "Accept terms", fill='black')
|
|
|
|
# Bouton "Cancel"
|
|
draw.rectangle([470, 200, 600, 250], fill='gray', outline='black', width=2)
|
|
draw.text((510, 215), "Cancel", fill='white')
|
|
|
|
# Sauvegarder temporairement
|
|
temp_file = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
|
img.save(temp_file.name)
|
|
return temp_file.name
|
|
|
|
|
|
def test_real_vlm_detection():
|
|
"""Tester la vraie détection VLM"""
|
|
print("=" * 80)
|
|
print("TEST: Vraie Détection VLM avec Ollama")
|
|
print("=" * 80)
|
|
|
|
# Vérifier qu'Ollama est disponible
|
|
print("\n1. Vérification de la disponibilité d'Ollama...")
|
|
if not check_ollama_available():
|
|
print("❌ Ollama n'est pas disponible!")
|
|
print(" Assurez-vous qu'Ollama est lancé: ollama serve")
|
|
return False
|
|
print("✓ Ollama est disponible")
|
|
|
|
# Créer un screenshot de test
|
|
print("\n2. Création d'un screenshot de test...")
|
|
screenshot_path = create_test_screenshot()
|
|
print(f"✓ Screenshot créé: {screenshot_path}")
|
|
|
|
# Créer le détecteur avec VLM
|
|
print("\n3. Initialisation du UIDetector avec VLM...")
|
|
config = DetectionConfig(
|
|
vlm_model="qwen3-vl:8b",
|
|
confidence_threshold=0.7, # Seuil production (évite faux positifs)
|
|
detect_regions=False # Analyser l'image complète
|
|
)
|
|
detector = UIDetector(config)
|
|
|
|
if detector.vlm_client is None:
|
|
print("❌ Le VLM n'a pas pu être initialisé!")
|
|
return False
|
|
print(f"✓ UIDetector initialisé avec {config.vlm_model}")
|
|
|
|
# Détecter les éléments
|
|
print("\n4. Détection des éléments UI avec le VLM...")
|
|
print(" (Cela peut prendre quelques secondes...)")
|
|
|
|
window_context = {
|
|
"title": "Test Application",
|
|
"process": "test_app"
|
|
}
|
|
|
|
elements = detector.detect(screenshot_path, window_context)
|
|
|
|
print(f"\n✓ Détection terminée: {len(elements)} éléments trouvés")
|
|
|
|
# Afficher les résultats
|
|
if len(elements) == 0:
|
|
print("\n⚠ Aucun élément détecté!")
|
|
print(" Le VLM n'a peut-être pas pu analyser l'image correctement.")
|
|
return False
|
|
|
|
print("\n5. Éléments détectés:")
|
|
print("-" * 80)
|
|
for i, elem in enumerate(elements, 1):
|
|
print(f"\nÉlément {i}:")
|
|
print(f" ID: {elem.element_id}")
|
|
print(f" Type: {elem.type}")
|
|
print(f" Rôle: {elem.role}")
|
|
print(f" Label: {elem.label}")
|
|
print(f" Position: {elem.bbox}")
|
|
print(f" Centre: {elem.center}")
|
|
print(f" Confiance: {elem.confidence:.2f}")
|
|
print(f" Détecté par: {elem.metadata.get('detected_by', 'unknown')}")
|
|
|
|
print("\n" + "=" * 80)
|
|
print("✓ Test de détection VLM réussie!")
|
|
print("=" * 80)
|
|
|
|
return True
|
|
|
|
|
|
def test_element_classification():
|
|
"""Tester la classification d'un élément individuel"""
|
|
print("\n" + "=" * 80)
|
|
print("TEST: Classification d'Élément avec VLM")
|
|
print("=" * 80)
|
|
|
|
# Vérifier Ollama
|
|
if not check_ollama_available():
|
|
print("❌ Ollama n'est pas disponible!")
|
|
return False
|
|
|
|
# Créer un détecteur
|
|
detector = UIDetector()
|
|
if detector.vlm_client is None:
|
|
print("❌ VLM non initialisé!")
|
|
return False
|
|
|
|
# Créer une image d'un bouton
|
|
print("\n1. Création d'une image de bouton de test...")
|
|
img = Image.new('RGB', (150, 50), color='blue')
|
|
draw = ImageDraw.Draw(img)
|
|
draw.text((50, 15), "Submit", fill='white')
|
|
|
|
# Classifier le type
|
|
print("\n2. Classification du type...")
|
|
elem_type, type_conf = detector.classify_type(img)
|
|
print(f" Type détecté: {elem_type} (confiance: {type_conf:.2f})")
|
|
|
|
# Classifier le rôle
|
|
print("\n3. Classification du rôle...")
|
|
elem_role, role_conf = detector.classify_role(img, elem_type)
|
|
print(f" Rôle détecté: {elem_role} (confiance: {role_conf:.2f})")
|
|
|
|
print("\n✓ Classification terminée!")
|
|
return True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("\n🚀 Test de la Vraie Détection VLM\n")
|
|
|
|
# Test 1: Détection complète
|
|
success1 = test_real_vlm_detection()
|
|
|
|
# Test 2: Classification individuelle
|
|
success2 = test_element_classification()
|
|
|
|
# Résumé
|
|
print("\n" + "=" * 80)
|
|
print("RÉSUMÉ DES TESTS")
|
|
print("=" * 80)
|
|
print(f"Détection complète: {'✓ PASS' if success1 else '❌ FAIL'}")
|
|
print(f"Classification individuelle: {'✓ PASS' if success2 else '❌ FAIL'}")
|
|
print("=" * 80)
|
|
|
|
if success1 and success2:
|
|
print("\n🎉 Tous les tests sont passés!")
|
|
sys.exit(0)
|
|
else:
|
|
print("\n⚠ Certains tests ont échoué")
|
|
sys.exit(1)
|