-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict.py
31 lines (26 loc) · 895 Bytes
/
predict.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
import asyncio
import aiohttp
async def fetch(url, data):
async with aiohttp.ClientSession() as session:
async with session.post(url, json=data) as response:
return await response.text()
async def main():
# Define the URL to make the request to
url = "http://localhost:8501/v1/models/test_model.tf:predict"
model_inputs = [
list(range(10)),
[list(range(10)),list(range(10))],
[list(range(5)),list(range(5))]
]
# Define the data to include in the JSON payload
payloads = [
{"instances": [x]}
for x in model_inputs
]
# Make the request and print the response
# Loop over the data payloads and make requests with each one
responses = [fetch(url, data) for data in payloads]
responses = await asyncio.gather(*responses)
print(responses)
# Run the main() function
asyncio.run(main())