-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_request_vertex.py
46 lines (40 loc) · 1.36 KB
/
generate_request_vertex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from google.cloud import aiplatform
import base64
from google.protobuf import json_format
from google.protobuf.struct_pb2 import Value
import argparse
import json
with open('../images/blip_test.jpeg', "rb") as image_file:
img = base64.b64encode(image_file.read())
def main(opt):
instances_list = {
"instances" : [
{
"image": img.decode('utf-8'),
"parameters" : {
"type" : "captioning",
"sample" : False,
"img_size" : 384,
"num_beams" : 3,
"max_length" : 20,
"min_length" : 5
}
}
]
}
instances = json.dumps(instances_list).encode('utf-8')
endpoint = aiplatform.Endpoint(opt.endpoint_name)
results = endpoint.raw_predict(body=instances, headers={'Content-Type':'application/json'})
print(results)
with open("response.json", "w") as text_file:
text_file.write(results.text)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--endpoint-name",
type=str,
required=True,
help="Endpoint name in format projects/<project_id>/locations/us-central1/endpoints/<endpoint_id>"
)
opt = parser.parse_args()
main(opt)