diff --git a/cdn_manager.py b/cdn_manager.py index 8ca26b5..4b11d1b 100644 --- a/cdn_manager.py +++ b/cdn_manager.py @@ -1,25 +1,34 @@ import io +import sys + import boto3 +import yaml +import os class CDNCredentials: - def __init__(self, host, access_key, secret_key): + def __init__(self, host, downloader_access_key, downloader_access_secret, uploader_access_key, uploader_access_secret): self.host = host - self.access_key = access_key - self.secret_key = secret_key + self.downloader_access_key = downloader_access_key + self.downloader_access_secret = downloader_access_secret + self.uploader_access_key = uploader_access_key + self.uploader_access_secret = uploader_access_secret class CDNManager: def __init__(self, credentials: CDNCredentials): self.creds = credentials - self.minio_client = boto3.client('s3', endpoint_url=self.creds.host, - aws_access_key_id=self.creds.access_key, - aws_secret_access_key=self.creds.secret_key) + self.download_client = boto3.client('s3', endpoint_url=self.creds.host, + aws_access_key_id=self.creds.downloader_access_key, + aws_secret_access_key=self.creds.downloader_access_secret) + self.upload_client = boto3.client('s3', endpoint_url=self.creds.host, + aws_access_key_id=self.creds.uploader_access_key, + aws_secret_access_key=self.creds.uploader_access_secret) def upload(self, bucket: str, filename: str, file_bytes: bytearray): try: - self.minio_client.upload_fileobj(io.BytesIO(file_bytes), bucket, filename) - print(f'Uploaded {len(file_bytes)} bytes to {self.creds.host}/{bucket}/{filename}') + self.upload_client.upload_fileobj(io.BytesIO(file_bytes), bucket, filename) + print(f'uploaded {filename} ({len(file_bytes)} bytes) to the {bucket}') return True except Exception as e: print(e) @@ -27,8 +36,35 @@ class CDNManager: def download(self, bucket: str, filename: str): try: - self.minio_client.download_file(bucket, filename, filename) + self.download_client.download_file(bucket, filename, filename) + print(f'downloaded {filename} from the {bucket} to current folder') return True except Exception as e: print(e) return False + + +config_file = os.path.join('downloader_config.yaml') +with open(config_file, 'r') as f: + config = yaml.safe_load(f) + +cdn_manager = CDNManager(CDNCredentials( + config['host'], + config['downloader_access_key'], + config['downloader_access_secret'], + config['uploader_access_key'], + config['uploader_access_secret'] +)) + +input_action = sys.argv[1] +input_bucket = sys.argv[2] +input_filename = sys.argv[3] +if len(sys.argv) > 4: # 0 is this script's path, hence 5 args is max + input_path = sys.argv[4] + +if input_action == 'upload': + with open(input_path, 'rb') as f: + cdn_manager.upload(input_bucket, input_filename, bytearray(f.read())) +elif input_action == 'download': + cdn_manager.download(input_bucket, input_filename) + diff --git a/config.yaml b/config.yaml index 5a8e52f..beef3f6 100644 --- a/config.yaml +++ b/config.yaml @@ -1,7 +1,9 @@ cdn: - host: 'https://cdnapi.azaion.com' - access_key: '8gx5HWhLXD1sEZgQjxam' - secret_key: 'KHjr6xmveqgKa7UibY9kEQUQ7VhjT8yfmG1fP0tV' + host: 'https://cdnapi.azaion.com/' + downloader_access_key: '8ynZ0rrMLL00GLBopklw' + downloader_access_secret: 'McNgEKhAJUxoa3t4WDDbCbhYPg4Qhe7FNQEKrtbk' + uploader_access_key: 'YhdHtKaq8DmvrYohetu6' + uploader_access_secret: 'nlOtjo1c4UWiMiJOjcIpR0aJFPitIhcwU6zFev7H' bucket: 'models' api: diff --git a/start_inference.py b/start_inference.py index b220e31..97cbcdf 100644 --- a/start_inference.py +++ b/start_inference.py @@ -22,6 +22,8 @@ if __name__ == "__main__": # Inference(TensorRTEngine('azaion-2025-03-10_batch8.engine', batch_size=8), # confidence_threshold=0.5, iou_threshold=0.3).process('ForAI_test.mp4') + CDNManager() + with open(constants.CONFIG_FILE, "r") as f: config_dict = yaml.safe_load(f) d_config = Dotdict(config_dict) @@ -32,15 +34,6 @@ if __name__ == "__main__": tensor_model_bytes = api_client.load_resource(constants.AI_TENSOR_MODEL_FILE_BIG, constants.AI_TENSOR_MODEL_FILE_SMALL) onxx_model_bytes = api_client.load_resource(constants.AI_ONNX_MODEL_FILE_BIG, constants.AI_ONNX_MODEL_FILE_SMALL) - input_string2 = "{'0': 'Armored-Vehicle', '1': 'Truck', '2': 'Vehicle', '3': 'Artillery', '4': 'Shadow', '5': 'Trenches', '6': 'Military-men', '7': 'Tyre-tracks', '8': 'Additional-armored-tank', '9': 'Smoke', '10': 'Plane', '11': 'Moto', '12': 'Camouflage-net', '13': 'Camouflage-branches', '14': 'Class-15', '15': 'Class-16', '16': 'Class-17', '17': 'Class-18', '18': 'Class-19', '19': 'Class-20'}" - result_dict2 = eval(input_string2) - - try: - input_string3 = "{'0': 'Armored-Vehicle', '1': 'Truck', '2': 'Vehicle', '3': 'Artillery', '4': 'Shadow', '5': 'Trenches', '6': 'Military-men', '7': 'Tyre-tracks', '8': 'Additional-armored-tank', '9': 'Smoke', '10': 'Plane', '11': 'Moto', '12': 'Camouflage-net', '13': 'Camouflage-branches', '14': 'Class-15', '15': 'Class-16', '16': 'Class-17', '17': 'Class-18', '18': 'Class-19', '19': 'Class-20', '20': 'Armored-Vehicle(Wint)', '21': 'Truck(Wint)', '22': 'Vehicle(Wint)', '23': 'Artillery(Wint)', '24': 'Shadow(Wint)', '25': 'Trenches(Wint)', '26': 'Military-men(Wint)', '27': 'Tyre-tracks(Wint)', '28': 'Additional-armored-tank(Wint)', '29': 'Smoke(Wint)', '30': 'Plane(Wint)', '31': 'Moto(Wint)', '32': 'Camouflage-net(Wint)', '33': 'Camouflage-branches(Wint)', '34': 'Class-35', '35': 'Class-36', '36': 'Class-37', '37': 'Class-38', '38': 'Class-39', '39': 'Class-40', '40': 'Armored-Vehicle(Night)', '41': 'Truck(Night)', '42': 'Vehicle(Night)', '43': 'Artillery(Night)', '44': 'Shadow(Night)', '45': 'Trenches(Night)', '46': 'Military-men(Night)', '47': 'Tyre-tracks(Night)', '48': 'Additional-armored-tank(Night)', '49': 'Smoke(Night)', '50': 'Plane(Night)', '51': 'Moto(Night)', '52': 'Camouflage-net(Night)', '53': 'Camouflage-branches(Night)', '54': 'Class-55', '55': 'Class-56', '56': 'Class-57', '57': 'Class-58', '58': 'Class-59', '59': 'Class-60', '60': 'Class-61', '61': 'Class-62', '62': 'Class-63', '63': 'Class-64', '64': 'Class-65', '65': 'Class-66', '66': 'Class-67', '67': 'Class-68', '68': 'Class-69', '69': 'Class-70', '70': 'Class-71', '71': 'Class-72', '72': 'Class-73', '73': 'Class-74', '74': 'Class-75', '75': 'Class-76', '76': 'Class-77', '77': 'Class-78', '78': 'Class-79', '79': 'Class-80'}" - result_dict3 = eval(input_string3) - print(result_dict3) - except Exception as e: - print(e) # Inference(OnnxEngine(onxx_model_bytes, batch_size=4), # confidence_threshold=0.5, iou_threshold=0.3).process('tests/ForAI_test.mp4')