import runpod | |
import json | |
import os | |
import requests | |
import time | |
# json test file name | |
json_test_file = "test_input.json" | |
# open test file | |
with open(json_test_file) as f: | |
input = json.load(f) | |
# load runpod api key and serverless model id | |
runpod.api_key = "" | |
RUNPOD_MODEL_ID = "" | |
endpoint = runpod.Endpoint(RUNPOD_MODEL_ID) | |
start = time.time() | |
# First way to call serverless api | |
run_request = endpoint.run_sync(input) | |
print(run_request) | |
end = time.time() | |
print('Time taken: ', end-start) | |
# Second way to call serverless api | |
url = f'https://api.runpod.ai/v2/{RUNPOD_MODEL_ID}/run_sync' # or change to runsync | |
headers = { | |
'accept': 'application/json', | |
'Content-Type': 'application/json', | |
'Authorization': f'Bearer {runpod.api_key}' | |
} | |
start = time.time() | |
response = requests.post(url, headers=headers, data=json.dumps(input)) | |
print('\n') | |
print(response.json()) | |
end = time.time() | |
print('Time taken: ', end-start) | |