class_docstr: Uploader class that handles uploading data to S3 and display progress bar
class_docstr_tok: ["Uploader","class","that","handles","uploading","data","to","S3","and","display","progress","bar"]
docstr: Compress and upload the model tar object to S3
docstr_tok: ["Compress","and","upload","the","model","tar","object","to","S3"]
code: def upload(
      self,
      model_dir,
      total_size: int,
      credentials: botocore.credentials.Credentials,
      region_name: str,
      bucket: str,
      key: str,
  ):
      """Compress and upload the model tar object to S3"""
      self.total_left = total_size
      with tqdm.tqdm(
          total=total_size,
          desc="Uploading model artifacts",
          unit="bytes",
          ncols=100,
      ) as self.pbar:
          files = [
              os.path.join(model_dir, name)
              for name in os.listdir(model_dir)
          ]
          temp = tempfile.mkdtemp()
          tar_file = create_tar_file(
              files, os.path.join(temp, "model.tar.gz")
          )
  
          s3 = boto3.session.Session(
              region_name=region_name,
              aws_access_key_id=credentials.access_key,
              aws_secret_access_key=credentials.secret_key,
              aws_session_token=credentials.token,
          ).client("s3")
          s3.upload_file(
              os.path.join(temp, "model.tar.gz"),
              bucket,
              key,
              Callback=self.observe,
          )
          os.remove(tar_file)
          self.pbar.update(self.total_left)
          self.pbar.close()
          self.pbar = None
  
file_path: sagemaker-python-sdk/src/sagemaker/serve/utils/uploader.py
imports: from __future__ import absolute_import
  import logging
  import os
  import tempfile
  import botocore
  import boto3
  import tqdm
  from sagemaker.session import Session
  from sagemaker.s3_utils import s3_path_join
  from sagemaker.s3 import S3Uploader
  from sagemaker.utils import create_tar_file
label_desc: Use image node_id 3 for calling the Uploader obj's underlying member method code with example usage: obj.upload(model_dir, total_size, credentials, region_name, bucket, key) without return types