-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment.py
More file actions
54 lines (38 loc) · 1.59 KB
/
deployment.py
File metadata and controls
54 lines (38 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
deploying the Logistic Regression Model in training data.
Name: Needal Altiti
Date: 14 / 09 / 2023
"""
import shutil
import os
import json
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
class ModelDeployment:
def __init__(self, config):
self.config = config
self.dataset_csv_path = os.path.join(config['output_folder_path'], 'ingestedfiles.txt')
self.trained_model_path = os.path.join(config['output_model_path'], 'trainedmodel.pkl')
self.metrics_path = os.path.join(config['output_model_path'], 'latestscore.txt')
self.prod_deployment_path = os.path.join(config['prod_deployment_path'])
def deploy_model(self):
"""
Copy the latest pickle file, the latestscore.txt value,
and the ingestfiles.txt file into the deployment directory
"""
logging.info("Deploying trained model to production")
os.makedirs(self.prod_deployment_path, exist_ok=True)
# Copy trained model
shutil.copy2(self.trained_model_path, self.prod_deployment_path)
# Copy latestscore.txt
shutil.copy2(self.metrics_path, self.prod_deployment_path)
# Copy ingestedfiles.txt
shutil.copy2(self.dataset_csv_path, self.prod_deployment_path)
logging.info("Model, score, and ingested files copied to the deployment directory.")
if __name__ == '__main__':
# Load config.json and correct path variable
with open('config.json','r') as f:
config = json.load(f)
deployment = ModelDeployment(config)
deployment.deploy_model()