fix: CLIP en premier, suppression vérification OCR croisée, fix indentation
Some checks failed
security-audit / Bandit (scan statique) (push) Successful in 13s
security-audit / pip-audit (CVE dépendances) (push) Successful in 11s
security-audit / Scan secrets (grep) (push) Successful in 9s
tests / Lint (ruff + black) (push) Successful in 13s
tests / Tests unitaires (sans GPU) (push) Failing after 15s
tests / Tests sécurité (critique) (push) Has been skipped

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dom
2026-04-21 18:36:20 +02:00
parent 0b06db222d
commit 7feef3b6a9
2 changed files with 27 additions and 53 deletions

View File

@@ -845,25 +845,9 @@ def execute_action(action_type: str, params: dict) -> dict:
x, y, confidence, method_used = None, None, 0, ''
# === MÉTHODE PRINCIPALE : OCR → UI-TARS (fiable, 1-5s) ===
if _fc_target_text and _fc_target_text not in _action_types:
print(f"🔍 [Grounding] Recherche par texte: '{_fc_target_text}'")
grounding_result = _shared_find_element(
target_text=_fc_target_text,
target_description=_fc_target_desc,
anchor_image_base64=screenshot_base64,
anchor_bbox=anchor_bbox
)
if grounding_result:
x, y = grounding_result['x'], grounding_result['y']
confidence = grounding_result['confidence']
method_used = f"grounding_{grounding_result['method']}"
print(f"✅ [Grounding] Trouvé via {grounding_result['method']} à ({x}, {y}) conf={confidence:.2f}")
# === FALLBACK : CLIP (si le grounding n'a rien trouvé) ===
if x is None:
print(f"🔄 [Vision] Fallback CLIP...")
# === MÉTHODE 1 : CLIP visuel (rapide, fiable si écran similaire) ===
from services.intelligent_executor import find_and_click
print(f"🧠 [Vision] Recherche visuelle CLIP...")
result = find_and_click(
anchor_image_base64=screenshot_base64,
anchor_bbox=anchor_bbox,
@@ -877,6 +861,20 @@ def execute_action(action_type: str, params: dict) -> dict:
confidence = result['confidence']
method_used = 'clip'
# === MÉTHODE 2 : OCR → UI-TARS (si CLIP échoue) ===
if x is None and _fc_target_text and _fc_target_text not in _action_types:
print(f"🔍 [Grounding] Fallback OCR/UI-TARS: '{_fc_target_text}'")
grounding_result = _shared_find_element(
target_text=_fc_target_text,
target_description=_fc_target_desc,
anchor_image_base64=screenshot_base64,
anchor_bbox=anchor_bbox
)
if grounding_result:
x, y = grounding_result['x'], grounding_result['y']
confidence = grounding_result['confidence']
method_used = f"grounding_{grounding_result['method']}"
if x is not None:
print(f"✅ [Vision] Ancre trouvée à ({x}, {y}) — {method_used} (conf={confidence:.2f})")

View File

@@ -724,30 +724,6 @@ def find_and_click(
# clip_result.found est conditionné par les seuils dans find_anchor_in_screen
if clip_result.found:
# Vérification croisée OCR : le texte à cette position correspond-il ?
clip_validated = True
if target_text and target_text not in ('click_anchor', 'double_click_anchor',
'right_click_anchor', 'hover_anchor', 'focus_anchor'):
try:
from services.ocr_service import ocr_extract_words
words = ocr_extract_words(screen_image)
cx, cy = clip_result.center['x'], clip_result.center['y']
nearby_texts = []
for w in words:
wx = (w['bbox'][0] + w['bbox'][2]) / 2
wy = (w['bbox'][1] + w['bbox'][3]) / 2
dist = ((wx - cx)**2 + (wy - cy)**2) ** 0.5
if dist < 100:
nearby_texts.append(w['text'])
nearby_str = ' '.join(nearby_texts).lower()
target_lower = target_text.lower()
if target_lower not in nearby_str and not any(t.lower() in target_lower for t in nearby_texts if len(t) > 2):
print(f"⛔ [Vision] CLIP rejeté par OCR: texte proche='{nearby_str}' ne contient pas '{target_text}'")
clip_validated = False
except Exception as ocr_err:
print(f"⚠️ [Vision] Vérification OCR échouée: {ocr_err}")
if clip_validated:
print(f"✅ [Vision] UI-DETR-1+CLIP réussi! Confiance: {clip_result.confidence:.2f}")
return {
'found': True,