-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_input.py
41 lines (30 loc) · 1.01 KB
/
url_input.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
#!/usr/bin/env python
"""
Sample code to run image classification with image url as input
"""
import requests
import os
import sys
def infer():
# Get the API key for invoking Tiyaro API
apiKey = os.getenv("TIYARO_API_KEY")
if apiKey is None:
print("Please set TIYARO_API_KEY environment variable. You can generate your API key from here - https://console.tiyaro.ai/apikeys")
sys.exit(1)
# API endpoint
url = "https://api.tiyaro.ai/v1/ent/google/5/imagenet/resnet_v1_101/classification"
# Input image
imgURL = "https://public-model-demo.s3.us-west-2.amazonaws.com/object-detect-1.jpg"
payload = {"imageRef": {"URL": imgURL}}
headers = {
"accept": "*/*",
"content-type": "application/json",
"authorization": f"Bearer {apiKey}"
}
response = requests.request("POST", url, json=payload, headers=headers)
# Check for errors
response.raise_for_status()
# Inference response
print(response.text)
if __name__ == "__main__":
infer()