-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfer.py
More file actions
44 lines (33 loc) · 1.21 KB
/
infer.py
File metadata and controls
44 lines (33 loc) · 1.21 KB
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
#!/usr/bin/env python
"""
Sample code to run NLP Text Classification
"""
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/huggingface/1/finiteautomata/beto-sentiment-analysis"
# Input string
inputString = """I bought this for my husband who plays the piano.
He is having a wonderful time playing these old hymns.
The music is at times hard to read because we think the book was
published for singing from more than playing from. Great purchase though!"""
payload = {"input": inputString}
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()