Skip to content

Instantly share code, notes, and snippets.

@kaysush
Created July 10, 2021 11:16
Show Gist options
  • Save kaysush/d1b082bf4dfb5b31de4ce2b63d677b4b to your computer and use it in GitHub Desktop.
Save kaysush/d1b082bf4dfb5b31de4ce2b63d677b4b to your computer and use it in GitHub Desktop.
Generate Batch Prediction file for Auto ML
import json
from google.cloud import storage
BUCKET='apt-task-314904-us'
DELIMITER='/'
TEST_PREFIX='test1/test1/'
TEST_BASE_PATH = f'gs://{BUCKET}/{TEST_PREFIX}'
print("Starting the import file generation process")
print("Process Details")
print(f"BUCKET : {BUCKET}")
storage_client = storage.Client()
print("Fetchig list of Test objects")
test_blobs = storage_client.list_blobs(BUCKET, prefix=TEST_PREFIX, delimiter=DELIMITER)
test_file = open("test.jsonl", "w")
for blob in test_blobs:
full_path = f"gs://{BUCKET}/{blob.name}"
mime_type = "image/jpeg"
data = {
'content': full_path,
'mimeType': mime_type
}
jsonLine = json.dumps(data)
test_file.write(jsonLine + "\n")
test_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment