#!/usr/bin/env python3 import oss2 import sys import os import time oss_ak = 'LTAI5tC2qXGxwHZUZP7DoD1A' oss_sk = 'qPo9O6ZvEfqo4t8oflGEm0DoxLHJhm' auth = oss2.Auth(oss_ak, oss_sk) endpoint = 'https://oss-rg-china-mainland.aliyuncs.com' bucket = oss2.Bucket(auth, endpoint, 'emblem-models') class ProgressCallback: def __init__(self, filename, total_size): self.filename = filename self.total_size = total_size self.consumed = 0 self.start_time = time.time() def __call__(self, consumed, total): self.consumed = consumed elapsed = time.time() - self.start_time if elapsed > 0: kbps = (consumed / elapsed) / 1024 # Convert to KB/s percent = 100 * consumed / total if total else 0 consumed_kb = consumed / 1024 total_kb = total / 1024 print(f"\r{self.filename}: {percent:.1f}% ({consumed_kb:.0f}/{total_kb:.0f} KB, {kbps:.0f} KB/s)", end='', flush=True) for x in sys.argv[1:]: file_size = os.path.getsize(x) file_size_kb = file_size / 1024 filename = os.path.basename(x) print(f"Uploading {filename} ({file_size_kb:.0f} KB)...") bucket.put_object_from_file(filename, x, progress_callback=ProgressCallback(filename, file_size)) print() # New line after progress completes