refactor: nettoyage agent + fix SomEngine review (singleton partagé, cache, thread-safe)
Nettoyage Windows agent : - Suppression lea_ui inutilisés (chat_widget, overlay, styles, etc. — -1991 lignes) - Suppression window_info*.py dupliqués (racine + core/ — -494 lignes) - build/ + dist/ supprimés (48 MB PyInstaller abandonné, gitignorés) Fix SomEngine (review quality guardian) : - Singleton GPU partagé via get_shared_engine() (1 instance au lieu de 2) - Thread-safe avec threading.Lock (double-checked locking) - Cache SomResult par screenshot_id (max 50, évite YOLO+OCR redondants) - Fuite fichier temp docTR corrigée (finally block) - Chemin YOLO configurable via SOM_YOLO_WEIGHTS env var - Guard som_image None avant VLM - Match texte partiel : len(label) >= 3 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3326,21 +3326,13 @@ def _vlm_quick_find(
|
||||
# Résolution Set-of-Mark : SomEngine (détection) + VLM (identification)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_som_engine_api = None # Singleton
|
||||
|
||||
|
||||
def _get_som_engine_api():
|
||||
"""Singleton SomEngine pour la résolution visuelle (lazy-loaded, GPU)."""
|
||||
global _som_engine_api
|
||||
if _som_engine_api is None:
|
||||
try:
|
||||
from core.detection.som_engine import SomEngine
|
||||
_som_engine_api = SomEngine(device="cuda")
|
||||
logger.info("SomEngine API initialisé (lazy singleton)")
|
||||
except Exception as e:
|
||||
logger.warning("SomEngine API non disponible : %s", e)
|
||||
_som_engine_api = False
|
||||
return _som_engine_api if _som_engine_api is not False else None
|
||||
"""Singleton SomEngine partagé."""
|
||||
try:
|
||||
from core.detection.som_engine import get_shared_engine
|
||||
return get_shared_engine()
|
||||
except ImportError:
|
||||
return None
|
||||
|
||||
|
||||
def _resolve_by_som(
|
||||
@@ -3423,7 +3415,7 @@ def _resolve_by_som(
|
||||
if not exact_matches:
|
||||
exact_matches = [
|
||||
e for e in som_result.elements
|
||||
if e.label and (
|
||||
if e.label and len(e.label) >= 3 and (
|
||||
label_lower in e.label.lower()
|
||||
or e.label.lower() in label_lower
|
||||
)
|
||||
@@ -3493,6 +3485,10 @@ def _resolve_by_som(
|
||||
)
|
||||
|
||||
# ── 3. Sauvegarder l'image annotée SoM temporairement ──
|
||||
if som_result.som_image is None:
|
||||
logger.debug("SoM resolve : pas d'image annotée, skip VLM")
|
||||
return None
|
||||
|
||||
import tempfile
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmp:
|
||||
|
||||
Reference in New Issue
Block a user