#!/usr/bin/perl use JSON::XS; use MIME::Base64; if ( (-s "$ARGV[0].json") > 10 && (-s "$ARGV[0].json") != 294 ) { print "SKIP ($ARGV[0])\n"; exit; }; #skip if we've already run... $JSONREF->{'parameters'}->{'sampleCount'} = 3; $JSONREF->{'parameters'}->{'language'} = 'en'; open(FILE, $ARGV[0]); binmode(FILE); read(FILE, $buf, (-s FILE)); close(FILE); $JSONREF->{'instances'}[0]->{'image'}->{'bytesBase64Encoded'} = encode_base64($buf); open(OUT, ">$ARGV[0].to"); print OUT JSON::XS->new->utf8->allow_nonref->encode($JSONREF); close(OUT); print "Running... ($ARGV[0])\n"; system("curl -s -X POST -H \"Authorization: Bearer \$(gcloud auth print-access-token)\" -H \"Content-Type: application/json; charset=utf-8\" -d \@$ARGV[0].to \"https://us-central1-aiplatform.googleapis.com/v1/projects/[YOURPROJECTID]/locations/us-central1/publishers/google/models/imagetext:predict\" > $ARGV[0].json "); unlink("$ARGV[0].to"); if (-s "$ARGV[0].json" == 294) { print "WARNING: QUOTA EXCEEDED!\n"; }; sleep 4;