Embarquer modèle NER + chargement auto au démarrage
- GUI V5 : charge DistilCamemBERT-NER automatiquement en arrière-plan - _app_dir() : chemin compatible Nuitka onefile - Build Nuitka : inclut models/ + config/ dans le .exe - GitHub Actions : étape download model avant compilation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
18
.github/workflows/build-windows.yml
vendored
18
.github/workflows/build-windows.yml
vendored
@@ -9,7 +9,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build-windows:
|
build-windows:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
timeout-minutes: 45
|
timeout-minutes: 60
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@@ -27,6 +27,10 @@ jobs:
|
|||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
pip install nuitka orderedset zstandard
|
pip install nuitka orderedset zstandard
|
||||||
|
|
||||||
|
- name: Download NER model
|
||||||
|
run: |
|
||||||
|
python -c "from ner_manager_onnx import NerModelManager; m=NerModelManager(cache_dir='models'); m.load('cmarkea/distilcamembert-base-ner'); print('Model OK:', m.is_loaded()); m.unload()"
|
||||||
|
|
||||||
- name: Build with Nuitka
|
- name: Build with Nuitka
|
||||||
run: |
|
run: |
|
||||||
python -m nuitka `
|
python -m nuitka `
|
||||||
@@ -37,6 +41,7 @@ jobs:
|
|||||||
--include-module=ner_manager_onnx `
|
--include-module=ner_manager_onnx `
|
||||||
--include-module=eds_pseudo_manager `
|
--include-module=eds_pseudo_manager `
|
||||||
--include-data-dir=config=config `
|
--include-data-dir=config=config `
|
||||||
|
--include-data-dir=models=models `
|
||||||
--windows-console-mode=disable `
|
--windows-console-mode=disable `
|
||||||
--output-filename=Pseudonymisation.exe `
|
--output-filename=Pseudonymisation.exe `
|
||||||
--company-name="Hopital" `
|
--company-name="Hopital" `
|
||||||
@@ -47,22 +52,15 @@ jobs:
|
|||||||
--remove-output `
|
--remove-output `
|
||||||
Pseudonymisation_Gui_V5.py
|
Pseudonymisation_Gui_V5.py
|
||||||
|
|
||||||
- name: Prepare release archive
|
|
||||||
run: |
|
|
||||||
New-Item -ItemType Directory -Force -Path dist
|
|
||||||
Copy-Item Pseudonymisation.exe dist/
|
|
||||||
Copy-Item -Recurse config dist/config
|
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: Pseudonymisation-Windows-x64
|
name: Pseudonymisation-Windows-x64
|
||||||
path: dist/
|
path: Pseudonymisation.exe
|
||||||
retention-days: 30
|
retention-days: 30
|
||||||
|
|
||||||
- name: Upload to release (on tag)
|
- name: Upload to release (on tag)
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
files: |
|
files: Pseudonymisation.exe
|
||||||
dist/Pseudonymisation.exe
|
|
||||||
|
|||||||
@@ -67,7 +67,16 @@ except ImportError:
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
APP_TITLE = "Pseudonymisation de PDF"
|
APP_TITLE = "Pseudonymisation de PDF"
|
||||||
APP_VERSION = "v5.0"
|
APP_VERSION = "v5.0"
|
||||||
DEFAULT_CFG = Path("config/dictionnaires.yml")
|
|
||||||
|
def _app_dir() -> Path:
|
||||||
|
"""Répertoire racine de l'application (compatible Nuitka onefile)."""
|
||||||
|
# Nuitka onefile extrait dans un dossier temporaire
|
||||||
|
if "__compiled__" in dir():
|
||||||
|
return Path(__file__).resolve().parent
|
||||||
|
return Path.cwd()
|
||||||
|
|
||||||
|
DEFAULT_CFG = _app_dir() / "config" / "dictionnaires.yml"
|
||||||
|
MODELS_DIR = _app_dir() / "models"
|
||||||
|
|
||||||
DEFAULTS_CFG_TEXT = r"""
|
DEFAULTS_CFG_TEXT = r"""
|
||||||
# dictionnaires.yml – valeurs par défaut (bloc littéral pour les regex)
|
# dictionnaires.yml – valeurs par défaut (bloc littéral pour les regex)
|
||||||
@@ -255,8 +264,8 @@ class App:
|
|||||||
self.th_per = 0.90
|
self.th_per = 0.90
|
||||||
self.th_org = 0.90
|
self.th_org = 0.90
|
||||||
self.th_loc = 0.90
|
self.th_loc = 0.90
|
||||||
self._onnx_manager: Optional[Any] = NerModelManager(cache_dir=Path("models")) if NerModelManager else None
|
self._onnx_manager: Optional[Any] = NerModelManager(cache_dir=MODELS_DIR) if NerModelManager else None
|
||||||
self._eds_manager: Optional[Any] = EdsPseudoManager(cache_dir=Path("models")) if EdsPseudoManager else None
|
self._eds_manager: Optional[Any] = EdsPseudoManager(cache_dir=MODELS_DIR) if EdsPseudoManager else None
|
||||||
self._active_manager: Optional[Any] = None
|
self._active_manager: Optional[Any] = None
|
||||||
self.cfg_data: Dict[str, Any] = {}
|
self.cfg_data: Dict[str, Any] = {}
|
||||||
|
|
||||||
@@ -277,6 +286,9 @@ class App:
|
|||||||
self._ensure_cfg_exists()
|
self._ensure_cfg_exists()
|
||||||
self._load_cfg()
|
self._load_cfg()
|
||||||
|
|
||||||
|
# --- Chargement automatique du modèle NER ---
|
||||||
|
self._auto_load_ner()
|
||||||
|
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# Thème
|
# Thème
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
@@ -848,6 +860,26 @@ class App:
|
|||||||
pass
|
pass
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# Chargement automatique NER au démarrage
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
def _auto_load_ner(self):
|
||||||
|
"""Charge le modèle NER par défaut en arrière-plan."""
|
||||||
|
if not self._onnx_manager:
|
||||||
|
return
|
||||||
|
self.status_var.set("Chargement du modèle NER...")
|
||||||
|
threading.Thread(target=self._auto_load_ner_worker, daemon=True).start()
|
||||||
|
|
||||||
|
def _auto_load_ner_worker(self):
|
||||||
|
try:
|
||||||
|
default_model = "cmarkea/distilcamembert-base-ner"
|
||||||
|
self._onnx_manager.load(default_model)
|
||||||
|
self._active_manager = self._onnx_manager
|
||||||
|
self.use_hf = True
|
||||||
|
self.status_var.set("Prêt — NER actif.")
|
||||||
|
except Exception as e:
|
||||||
|
self.status_var.set(f"Prêt (NER indisponible : {e})")
|
||||||
|
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# Modèles NER (API interne)
|
# Modèles NER (API interne)
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ REM ============================================================
|
|||||||
setlocal
|
setlocal
|
||||||
set APP_NAME=Pseudonymisation
|
set APP_NAME=Pseudonymisation
|
||||||
set ENTRY=Pseudonymisation_Gui_V5.py
|
set ENTRY=Pseudonymisation_Gui_V5.py
|
||||||
|
set MODEL_ID=cmarkea/distilcamembert-base-ner
|
||||||
|
|
||||||
echo [build] Verification de Python...
|
echo [build] Verification de Python...
|
||||||
python --version || (echo Python introuvable & exit /b 1)
|
python --version || (echo Python introuvable & exit /b 1)
|
||||||
@@ -20,7 +21,10 @@ python --version || (echo Python introuvable & exit /b 1)
|
|||||||
echo [build] Installation de Nuitka si absent...
|
echo [build] Installation de Nuitka si absent...
|
||||||
pip install nuitka orderedset zstandard 2>nul
|
pip install nuitka orderedset zstandard 2>nul
|
||||||
|
|
||||||
echo [build] Compilation avec Nuitka (cela peut prendre 5-15 min)...
|
echo [build] Telechargement du modele NER si absent...
|
||||||
|
python -c "from ner_manager_onnx import NerModelManager; m=NerModelManager(cache_dir='models'); m.load('%MODEL_ID%'); print('Modele OK'); m.unload()"
|
||||||
|
|
||||||
|
echo [build] Compilation avec Nuitka (cela peut prendre 10-20 min)...
|
||||||
python -m nuitka ^
|
python -m nuitka ^
|
||||||
--standalone ^
|
--standalone ^
|
||||||
--onefile ^
|
--onefile ^
|
||||||
@@ -29,6 +33,7 @@ python -m nuitka ^
|
|||||||
--include-module=ner_manager_onnx ^
|
--include-module=ner_manager_onnx ^
|
||||||
--include-module=eds_pseudo_manager ^
|
--include-module=eds_pseudo_manager ^
|
||||||
--include-data-dir=config=config ^
|
--include-data-dir=config=config ^
|
||||||
|
--include-data-dir=models=models ^
|
||||||
--windows-console-mode=disable ^
|
--windows-console-mode=disable ^
|
||||||
--output-filename=%APP_NAME%.exe ^
|
--output-filename=%APP_NAME%.exe ^
|
||||||
--company-name="Hopital" ^
|
--company-name="Hopital" ^
|
||||||
@@ -45,5 +50,5 @@ if %ERRORLEVEL% NEQ 0 (
|
|||||||
)
|
)
|
||||||
|
|
||||||
echo [build] OK — Executable cree : %APP_NAME%.exe
|
echo [build] OK — Executable cree : %APP_NAME%.exe
|
||||||
echo [build] Copiez %APP_NAME%.exe + le dossier config/ sur la machine cible.
|
echo [build] Le modele NER est embarque. Aucun telechargement necessaire.
|
||||||
endlocal
|
endlocal
|
||||||
|
|||||||
Reference in New Issue
Block a user