Spaces:
Sleeping
Sleeping
Commit ·
aab61a1
1
Parent(s): 63b7948
Fixed4
Browse files- requirements.txt +3 -4
- utils/model_selector.py +18 -2
requirements.txt
CHANGED
|
@@ -7,7 +7,7 @@ eventlet==0.35.2
|
|
| 7 |
Flask-Mail==0.9.1
|
| 8 |
requests
|
| 9 |
|
| 10 |
-
# Machine Learning & Data
|
| 11 |
numpy<2.0.0
|
| 12 |
pandas<2.2.0
|
| 13 |
scikit-learn==1.5.1
|
|
@@ -15,16 +15,15 @@ imbalanced-learn==0.12.0
|
|
| 15 |
lightgbm>=4.0.0
|
| 16 |
joblib==1.4.2
|
| 17 |
scipy
|
| 18 |
-
|
| 19 |
-
lightgbm
|
| 20 |
huggingface_hub
|
|
|
|
| 21 |
|
| 22 |
# Network & Analysis
|
| 23 |
scapy==2.5.0
|
| 24 |
pyshark
|
| 25 |
psutil
|
| 26 |
|
| 27 |
-
# Utils
|
| 28 |
groq
|
| 29 |
fpdf
|
| 30 |
matplotlib
|
|
|
|
| 7 |
Flask-Mail==0.9.1
|
| 8 |
requests
|
| 9 |
|
| 10 |
+
# Machine Learning & Data
|
| 11 |
numpy<2.0.0
|
| 12 |
pandas<2.2.0
|
| 13 |
scikit-learn==1.5.1
|
|
|
|
| 15 |
lightgbm>=4.0.0
|
| 16 |
joblib==1.4.2
|
| 17 |
scipy
|
|
|
|
|
|
|
| 18 |
huggingface_hub
|
| 19 |
+
packaging # Added to support our version patch
|
| 20 |
|
| 21 |
# Network & Analysis
|
| 22 |
scapy==2.5.0
|
| 23 |
pyshark
|
| 24 |
psutil
|
| 25 |
|
| 26 |
+
# Utils
|
| 27 |
groq
|
| 28 |
fpdf
|
| 29 |
matplotlib
|
utils/model_selector.py
CHANGED
|
@@ -3,7 +3,7 @@ import joblib
|
|
| 3 |
import threading
|
| 4 |
import traceback
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
-
|
| 7 |
# --- CONFIGURATION ---
|
| 8 |
HF_REPO_ID = "CodebaseAi/netraids-ml-models" # Replace with your actual public repo ID
|
| 9 |
# ---------------------
|
|
@@ -12,6 +12,15 @@ ACTIVE_MODEL = "bcc"
|
|
| 12 |
_ACTIVE_LOCK = threading.Lock()
|
| 13 |
_MODEL_CACHE = {}
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# 1. FIXED PATH LOGIC:
|
| 16 |
# __file__ is /app/utils/model_selector.py
|
| 17 |
# dirname(__file__) is /app/utils
|
|
@@ -57,9 +66,16 @@ def _try_load(filename):
|
|
| 57 |
print(f"[model_selector] SKIP: {filename} path invalid.")
|
| 58 |
return None
|
| 59 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
return joblib.load(path)
|
| 61 |
except Exception as e:
|
| 62 |
-
print(f"[model_selector] FAILED to load {filename}
|
|
|
|
| 63 |
return None
|
| 64 |
|
| 65 |
def load_model(model_key):
|
|
|
|
| 3 |
import threading
|
| 4 |
import traceback
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
+
import sklearn.utils
|
| 7 |
# --- CONFIGURATION ---
|
| 8 |
HF_REPO_ID = "CodebaseAi/netraids-ml-models" # Replace with your actual public repo ID
|
| 9 |
# ---------------------
|
|
|
|
| 12 |
_ACTIVE_LOCK = threading.Lock()
|
| 13 |
_MODEL_CACHE = {}
|
| 14 |
|
| 15 |
+
# --- PATCH FOR SKLEARN 1.6+ COMPATIBILITY ---
|
| 16 |
+
# This fixes the "cannot import name 'parse_version' from 'sklearn.utils'" error
|
| 17 |
+
if not hasattr(sklearn.utils, 'parse_version'):
|
| 18 |
+
import packaging.version
|
| 19 |
+
def parse_version(v):
|
| 20 |
+
return packaging.version.parse(v)
|
| 21 |
+
sklearn.utils.parse_version = parse_version
|
| 22 |
+
# --------------------------------------------
|
| 23 |
+
|
| 24 |
# 1. FIXED PATH LOGIC:
|
| 25 |
# __file__ is /app/utils/model_selector.py
|
| 26 |
# dirname(__file__) is /app/utils
|
|
|
|
| 66 |
print(f"[model_selector] SKIP: {filename} path invalid.")
|
| 67 |
return None
|
| 68 |
try:
|
| 69 |
+
# Check if file size is > 0 before loading
|
| 70 |
+
if os.path.getsize(path) == 0:
|
| 71 |
+
print(f"[model_selector] ERROR: {filename} is an empty file.")
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
+
print(f"[model_selector] Attempting joblib.load for {filename}")
|
| 75 |
return joblib.load(path)
|
| 76 |
except Exception as e:
|
| 77 |
+
print(f"[model_selector] CRITICAL FAILED to load {filename}")
|
| 78 |
+
print(traceback.format_exc()) # This will show exactly why in HF logs
|
| 79 |
return None
|
| 80 |
|
| 81 |
def load_model(model_key):
|