-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment.py
More file actions
46 lines (36 loc) · 1.47 KB
/
deployment.py
File metadata and controls
46 lines (36 loc) · 1.47 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
"""
Python script meant to deploy a trained ML model
"""
import os
import logging
import sys
import json
from shutil import copy2
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
with open('config.json', 'r') as f:
"""
Load config.json and correct path variable
"""
config = json.load(f)
model_path = os.path.join(config['output_model_path'])
prod_deployment_path = os.path.join(config['prod_deployment_path'])
output_folder_path = config["output_folder_path"]
def store_model_into_pickle():
"""
Function for deployment
"""
# copy the latest pickle file, the latestscore.txt value, and the ingestfiles.txt file into the deployment directory
for file in ["ingestedfiles.txt", "trainedmodel.pkl", "encoder.pkl", "latestscore.txt"]:
if file in ["ingestedfiles.txt"]:
source_filepath = os.path.join(output_folder_path, file)
else:
source_filepath = os.path.join(model_path, file)
new_filepath = os.path.join(prod_deployment_path, file)
print(f'Copying {source_filepath} to {new_filepath}')
copy2(source_filepath, new_filepath)
if __name__ == '__main__':
logging.info("Running Deployment!")
store_model_into_pickle()
logging.info("Artifacts output written in production_deployment/ingestedfiles.txt")
logging.info("Artifacts output written in production_deployment/trainedmodel.pkl")
logging.info("Artifacts output written in production_deployment/latestscore.txt")