Actualiser app.py
This commit is contained in:
25
app.py
25
app.py
@@ -5,8 +5,8 @@ import yaml
|
||||
|
||||
from flask import Flask, request, jsonify, make_response
|
||||
|
||||
# Ces imports sont suffisants et corrects pour votre configuration actuelle:
|
||||
from presidio_analyzer import AnalyzerEngine, RecognizerResult, AnalyzerEngineProvider
|
||||
# Ces imports sont corrects pour la version qui va suivre.
|
||||
from presidio_analyzer import AnalyzerEngineProvider
|
||||
from presidio_anonymizer import AnonymizerEngine
|
||||
|
||||
logging.basicConfig(level=logging.INFO,
|
||||
@@ -15,7 +15,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# --- Initialisation combinée de l'Analyzer et de l'Anonymizer ---
|
||||
# --- Initialisation ---
|
||||
analyzer = None
|
||||
anonymizer = None
|
||||
|
||||
@@ -26,18 +26,21 @@ try:
|
||||
if not os.path.exists(CONFIG_FILE_PATH):
|
||||
raise FileNotFoundError(f"Configuration file not found at: {CONFIG_FILE_PATH}")
|
||||
|
||||
# --- CORRECTION DE LA LOGIQUE D'INITIALISATION ---
|
||||
|
||||
# 1. On initialise l'AnalyzerEngine en passant LE CHEMIN DU FICHIER, comme dans votre code original.
|
||||
# L'argument correct est 'analyzer_engine_conf_file'.
|
||||
provider = AnalyzerEngineProvider(analyzer_engine_conf_file=CONFIG_FILE_PATH)
|
||||
analyzer = provider.create_engine()
|
||||
logger.info("AnalyzerEngine created successfully.")
|
||||
|
||||
# 2. Pour l'AnonymizerEngine, nous devons charger le fichier YAML nous-mêmes
|
||||
# pour extraire sa section de configuration.
|
||||
with open(CONFIG_FILE_PATH, 'r') as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
# 1. Créer l'Analyzer Engine en utilisant le provider et la configuration chargée
|
||||
# C'est cette ligne qui utilise AnalyzerEngineProvider, il n'y a donc pas besoin
|
||||
# d'importer NlpEngineProvider séparément.
|
||||
provider = AnalyzerEngineProvider(analyzer_engine_conf=config)
|
||||
analyzer = provider.create_engine()
|
||||
|
||||
# 2. Créer l'Anonymizer Engine en lui passant sa section de configuration
|
||||
anonymizer_config = config.get("anonymizer_config", {})
|
||||
anonymizer = AnonymizerEngine(anonymizer_config=anonymizer_config)
|
||||
logger.info("AnonymizerEngine created successfully.")
|
||||
|
||||
logger.info(f"Analyzer and Anonymizer are ready. Languages: {analyzer.supported_languages}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user