feat(cli): charger les moteurs optionnels depuis les modeles embarques

This commit is contained in:
2026-06-17 19:52:29 +02:00
parent 9b40fc0a85
commit ea1752d4a7
5 changed files with 120 additions and 9 deletions

View File

@@ -13,6 +13,8 @@ Version compatible : gliner==0.2.18 (pas plus récent, casse optimum-onnx)
from __future__ import annotations
import logging
import sys
from pathlib import Path
from typing import Any, Dict, List, Optional
log = logging.getLogger(__name__)
@@ -56,6 +58,18 @@ GLINER_LABEL_MAP: Dict[str, str] = {
}
DEFAULT_MODEL = "urchade/gliner_multi_pii-v1"
BUNDLED_MODEL_DIR = "gliner_multi_pii-v1"
def _app_dir() -> Path:
if getattr(sys, "frozen", False):
return Path(getattr(sys, "_MEIPASS", Path(sys.executable).parent))
return Path(__file__).resolve().parent
def _bundled_model_path() -> Optional[Path]:
candidate = _app_dir() / "models" / BUNDLED_MODEL_DIR
return candidate if candidate.is_dir() else None
class GlinerManager:
@@ -73,10 +87,15 @@ class GlinerManager:
if not _GLINER_AVAILABLE:
raise RuntimeError("gliner non disponible. Installez : pip install 'gliner==0.2.18'")
self.unload()
self.model_id = model_id
self._model = GLiNER.from_pretrained(model_id)
source = model_id
if model_id == DEFAULT_MODEL:
bundled = _bundled_model_path()
if bundled is not None:
source = str(bundled)
self.model_id = source
self._model = GLiNER.from_pretrained(source)
self._loaded = True
log.info(f"GLiNER chargé: {model_id}")
log.info(f"GLiNER chargé: {source}")
def unload(self) -> None:
self._model = None