fix: grounding pour TOUT texte visible (OCR + VLM), auto-unload gemma4

1. Le grounding se déclenche pour by_text_source="vlm" (pas juste "ocr")
   Les textes lus par gemma4 (onglets, labels) sont du texte visible,
   le grounding doit les chercher comme n'importe quel texte OCR.

2. gemma4 est automatiquement déchargé après le build_replay
   pour libérer la VRAM et permettre à qwen2.5vl de charger au replay.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dom
2026-04-05 12:24:44 +02:00
parent 1c5ff42006
commit f0b311306d
2 changed files with 22 additions and 4 deletions

View File

@@ -5189,8 +5189,8 @@ def _resolve_target_sync(
# --------------------------------------------------------------- # ---------------------------------------------------------------
by_text_source = target_spec.get("by_text_source", "") by_text_source = target_spec.get("by_text_source", "")
if by_text_strict and by_text_source == "ocr": if by_text_strict and by_text_source in ("ocr", "vlm"):
# Texte OCR fiable → grounding VLM direct # Texte visible (OCR ou lu par gemma4) → grounding VLM direct
grounding_result = _resolve_by_grounding( grounding_result = _resolve_by_grounding(
screenshot_path=screenshot_path, screenshot_path=screenshot_path,
target_spec=target_spec, target_spec=target_spec,
@@ -5206,8 +5206,8 @@ def _resolve_target_sync(
) )
return grounding_result return grounding_result
if not by_text_strict or by_text_source != "ocr": if not by_text_strict or by_text_source not in ("ocr", "vlm"):
# Template matching sur la fenêtre active si disponible (évite les faux positifs) # Template matching pour les éléments sans texte (icônes pures)
window_capture = target_spec.get("window_capture", {}) window_capture = target_spec.get("window_capture", {})
window_rect = window_capture.get("rect") window_rect = window_capture.get("rect")
from pathlib import Path as _Path from pathlib import Path as _Path

View File

@@ -438,6 +438,20 @@ def _needs_post_wait(action: dict) -> int:
_GEMMA4_PORT = os.environ.get("GEMMA4_PORT", "11435") _GEMMA4_PORT = os.environ.get("GEMMA4_PORT", "11435")
def _unload_gemma4():
"""Décharger gemma4 du GPU Docker pour libérer la VRAM pour qwen2.5vl."""
try:
import requests as _req
_req.post(
f"http://localhost:{_GEMMA4_PORT}/api/generate",
json={"model": "gemma4:e4b", "keep_alive": 0},
timeout=5,
)
logger.info("gemma4 déchargé du GPU (VRAM libérée)")
except Exception:
pass
def _gemma4_read_element( def _gemma4_read_element(
img_b64: str, img_b64: str,
window_title: str = "", window_title: str = "",
@@ -1512,6 +1526,10 @@ def build_replay_from_raw_events(
"(%d/%d clics avec visual_mode, %d avec screenshot de référence)", "(%d/%d clics avec visual_mode, %d avec screenshot de référence)",
session_id, len(result), visual_clicks, total_clicks, verified_count, session_id, len(result), visual_clicks, total_clicks, verified_count,
) )
# Libérer gemma4 du GPU pour que qwen2.5vl puisse charger au replay
_unload_gemma4()
return result return result