@@ -1019,7 +1019,7 @@ def upload_local_model(
10191019 repo_name : Union[str, dict], optional
10201020 repository in which to create the project
10211021 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'.
10231023 """
10241024 # Use default repository if not specified
10251025 try :
@@ -1045,17 +1045,34 @@ def upload_local_model(
10451045 # Get project from repo if it exists; if it doesn't, create a new one
10461046 p = mr .get_project (project_name )
10471047 if p is None :
1048- mr .create_project (project_name , repository )
1048+ p = mr .create_project (project_name , repository )
10491049
10501050 # zip up all files in directory (except any previous zip files)
10511051 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 )
10541066 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+ )
10611078 return model
0 commit comments