@@ -1019,7 +1019,7 @@ def upload_local_model(
1019
1019
repo_name : Union[str, dict], optional
1020
1020
repository in which to create the project
1021
1021
version: str, optional
1022
- The version of the model being uploaded
1022
+ The version of the model being uploaded. Defaults to 'latest'. For new model version, use 'new'.
1023
1023
"""
1024
1024
# Use default repository if not specified
1025
1025
try :
@@ -1045,17 +1045,34 @@ def upload_local_model(
1045
1045
# Get project from repo if it exists; if it doesn't, create a new one
1046
1046
p = mr .get_project (project_name )
1047
1047
if p is None :
1048
- mr .create_project (project_name , repository )
1048
+ p = mr .create_project (project_name , repository )
1049
1049
1050
1050
# zip up all files in directory (except any previous zip files)
1051
1051
zip_name = str (Path (path ) / (model_name + ".zip" ))
1052
- file_names = sorted (Path (path ).glob ("*[!zip]" ))
1053
- with zipfile .ZipFile (str (zip_name ), mode = "w" ) as zFile :
1052
+ file_names = sorted (Path (path ).glob ("*[!(zip|sasast)]" ))
1053
+ sasast_file = next (Path (path ).glob ("*.sasast" ), None )
1054
+ if sasast_file :
1055
+ # If a sasast file is present, upload it as well
1056
+ with open (sasast_file , "rb" ) as sasast :
1057
+ sasast_model = sasast .read ()
1058
+ data = {
1059
+ "name" : model_name ,
1060
+ "projectId" : p .id ,
1061
+ "type" : "ASTORE" ,
1062
+ "versionOption" : version ,
1063
+ }
1064
+ files = {"files" : (sasast_file .name , sasast_model )}
1065
+ model = mr .post ("/models" , files = files , data = data )
1054
1066
for file in file_names :
1055
- zFile .write (str (file ), arcname = file .name )
1056
- # upload zipped model
1057
- with open (zip_name , "rb" ) as zip_file :
1058
- model = mr .import_model_from_zip (
1059
- model_name , project_name , zip_file , version = version
1060
- )
1067
+ with open (file , "r" ) as f :
1068
+ mr .add_model_content (model , f , file .name )
1069
+ else :
1070
+ with zipfile .ZipFile (str (zip_name ), mode = "w" ) as zFile :
1071
+ for file in file_names :
1072
+ zFile .write (str (file ), arcname = file .name )
1073
+ # upload zipped model
1074
+ with open (zip_name , "rb" ) as zip_file :
1075
+ model = mr .import_model_from_zip (
1076
+ model_name , project_name , zip_file , version = version
1077
+ )
1061
1078
return model
0 commit comments