Spaces:
Sleeping
Sleeping
- model_handler.py +13 -4
model_handler.py
CHANGED
|
@@ -99,13 +99,22 @@ class AIDetectionModelHandler:
|
|
| 99 |
self.xgboost_model = None
|
| 100 |
self.model_loaded = False
|
| 101 |
|
| 102 |
-
|
| 103 |
if model_path is None:
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
self.model_path = model_path
|
| 108 |
-
|
|
|
|
| 109 |
|
| 110 |
# Load the models
|
| 111 |
self._load_models()
|
|
|
|
| 99 |
self.xgboost_model = None
|
| 100 |
self.model_loaded = False
|
| 101 |
|
| 102 |
+
# Default model paths
|
| 103 |
if model_path is None:
|
| 104 |
+
# Prefer explicit env var
|
| 105 |
+
env_model_path = os.getenv("MODEL_PATH")
|
| 106 |
+
if env_model_path and os.path.exists(env_model_path):
|
| 107 |
+
model_path = env_model_path
|
| 108 |
+
elif os.path.exists("/app/model"):
|
| 109 |
+
model_path = "/app/model"
|
| 110 |
+
else:
|
| 111 |
+
# Fallback to legacy relative path
|
| 112 |
+
backend_dir = Path(__file__).parent
|
| 113 |
+
model_path = str(backend_dir.parent / "model" / "model")
|
| 114 |
|
| 115 |
self.model_path = model_path
|
| 116 |
+
# XGBoost file is expected inside the same folder as the other model artifacts
|
| 117 |
+
self.xgboost_path = str(Path(model_path) / "xgboost_model.json")
|
| 118 |
|
| 119 |
# Load the models
|
| 120 |
self._load_models()
|