File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 1
1
import logging
2
+ import tempfile
3
+ import time
2
4
from typing import Any
3
5
4
6
import dill
@@ -44,22 +46,22 @@ def load_object(file_path: str) -> Any:
44
46
raise e
45
47
46
48
49
+ @timing_decorator
47
50
def download_blob_and_return_object (
48
51
bucket_name : str = EnvironmentVariables ().GCP_MLFLOW_MODEL_ARTIFACT_BUCKET_NAME ,
49
52
source_blob_name : str = "model.pkl" ,
50
- destination_file_name : str = "gcp_model.pkl" ,
51
53
) -> Any :
52
54
"""
53
55
Downloads a blob from the bucket and return serialized object
54
56
55
- :param destination_file_name:
56
57
:param bucket_name: The ID of your GCS bucket
57
58
:param source_blob_name: The ID of your GCS object
58
59
:return: serialized object
59
60
"""
60
-
61
61
storage_client = storage .Client ()
62
62
bucket = storage_client .bucket (bucket_name )
63
- blob = bucket .blob (source_blob_name )
64
- blob .download_to_filename (destination_file_name )
65
- return load_object (destination_file_name )
63
+ with tempfile .NamedTemporaryFile () as file_location :
64
+ blob = bucket .blob (source_blob_name )
65
+ blob .download_to_filename (file_location .file .name )
66
+ serialized_model = load_object (file_location .file .name )
67
+ return serialized_model
You can’t perform that action at this time.
0 commit comments