From 08af108cfbc76cb5fd044ec2019a231c4053f600 Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Tue, 25 Nov 2025 07:53:47 +0000 Subject: [PATCH] Fix backend crash when initializing hybrid ML detector Corrected `main.py` to handle the `ml_analyzer` being `None` when `USE_HYBRID_DETECTOR` is true, preventing an `AttributeError` during startup. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 27f5de5e-5ed6-4ee6-9cc2-a7c448ad2334 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/XSkkaPM --- python_ml/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/python_ml/main.py b/python_ml/main.py index 31b9eac..2254655 100644 --- a/python_ml/main.py +++ b/python_ml/main.py @@ -680,7 +680,16 @@ if __name__ == "__main__": import uvicorn # Prova a caricare modello esistente - ml_analyzer.load_model() + if USE_HYBRID_DETECTOR: + # Hybrid detector: già caricato all'inizializzazione (riga 69) + if ml_detector and ml_detector.is_trained: + print("[ML] ✓ Hybrid detector models loaded and ready") + else: + print("[ML] ⚠ Hybrid detector initialized but no models found (will train on-demand)") + else: + # Legacy analyzer + if ml_analyzer: + ml_analyzer.load_model() print("🚀 Starting IDS API on http://0.0.0.0:8000") print("📚 Docs available at http://0.0.0.0:8000/docs")