import boto3 import os # 1. Credentials (Ready to use from your screenshot) ACCESS_KEY = "a9f685d13afd9a290e54dca612ef83d2" SECRET_KEY = "8284c338275d0e6ebb3e6e697ba5999f6409908cb92c08fe8351da4af728c875" ACCOUNT_ID = "659b46b7d1773d3742cd10b2c9194dd3" BUCKET_NAME = "oil-spill-detection" # 2. Path to your model file # Note: Ensure oil_spill_unet_best.keras is in this same folder! FILE_PATH = "oil_spill_unet_best.keras" def upload(): # Setup the Cloudflare R2 Client via S3 API s3 = boto3.client( service_name='s3', endpoint_url=f'https://{ACCOUNT_ID}.r2.cloudflarestorage.com', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY, region_name='auto' ) print(f"Starting high-speed API upload of {FILE_PATH}...") if not os.path.exists(FILE_PATH): print(f"ERROR: File '{FILE_PATH}' not found in the current directory.") print("FIX: Make sure you have downloaded it from Google Drive to this folder.") return try: s3.upload_file(FILE_PATH, BUCKET_NAME, "oil_spill_unet_best.keras") print("\n" + "="*40) print("SUCCESS! Your model is now on Cloudflare R2.") print("="*40) print("You can now run 'docker-compose up --build' and the system will pull the model automatically.") except Exception as e: print(f"UPLOAD FAILED: {e}") if __name__ == "__main__": upload()