Spaces:
Running
Running
Add metadata tracking to model pusher
Browse files
src/mlpipeline/components/model_pusher.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import shutil
|
| 2 |
import os
|
|
|
|
| 3 |
from pathlib import Path
|
|
|
|
| 4 |
from mlpipeline.entity import ModelPusherConfig, ModelPusherArtifact
|
| 5 |
from mlpipeline.logging.logger import get_logger
|
| 6 |
from mlpipeline.exception import ModelPusherException
|
|
@@ -18,6 +20,7 @@ class ModelPusher:
|
|
| 18 |
logger.info("Starting model pusher")
|
| 19 |
|
| 20 |
os.makedirs(self.config.model_registry_path, exist_ok=True)
|
|
|
|
| 21 |
|
| 22 |
model_source = Path(self.config.model_path)
|
| 23 |
model_dest = Path(self.config.model_registry_path) / model_source.name
|
|
@@ -31,6 +34,18 @@ class ModelPusher:
|
|
| 31 |
|
| 32 |
logger.info(f"Model pushed to: {model_dest}")
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
return ModelPusherArtifact(
|
| 35 |
pushed_model_path=str(model_dest),
|
| 36 |
is_pushed=True,
|
|
|
|
| 1 |
import shutil
|
| 2 |
import os
|
| 3 |
+
import json
|
| 4 |
from pathlib import Path
|
| 5 |
+
from datetime import datetime
|
| 6 |
from mlpipeline.entity import ModelPusherConfig, ModelPusherArtifact
|
| 7 |
from mlpipeline.logging.logger import get_logger
|
| 8 |
from mlpipeline.exception import ModelPusherException
|
|
|
|
| 20 |
logger.info("Starting model pusher")
|
| 21 |
|
| 22 |
os.makedirs(self.config.model_registry_path, exist_ok=True)
|
| 23 |
+
os.makedirs(self.config.root_dir, exist_ok=True)
|
| 24 |
|
| 25 |
model_source = Path(self.config.model_path)
|
| 26 |
model_dest = Path(self.config.model_registry_path) / model_source.name
|
|
|
|
| 34 |
|
| 35 |
logger.info(f"Model pushed to: {model_dest}")
|
| 36 |
|
| 37 |
+
# Save push metadata
|
| 38 |
+
metadata = {
|
| 39 |
+
"pushed_at": datetime.now().isoformat(),
|
| 40 |
+
"source_path": str(model_source),
|
| 41 |
+
"destination_path": str(model_dest),
|
| 42 |
+
"status": "success"
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
metadata_path = Path(self.config.root_dir) / "push_metadata.json"
|
| 46 |
+
with open(metadata_path, 'w') as f:
|
| 47 |
+
json.dump(metadata, f, indent=4)
|
| 48 |
+
|
| 49 |
return ModelPusherArtifact(
|
| 50 |
pushed_model_path=str(model_dest),
|
| 51 |
is_pushed=True,
|