-
Notifications
You must be signed in to change notification settings - Fork 2
/
ElevateAI.py
114 lines (81 loc) · 3.24 KB
/
ElevateAI.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""ElevateAI functions to get transcriptions."""
import requests
import json
def DeclareAudioInteraction(
language,
verticle,
downloadUri,
token,
audioTranscriptionMode,
includeAiResults: bool,
originalFileName=None,
externalIdentifier=None,
):
"""1st step in processing an interaction is to declare the interaction."""
url = "https://api.elevateai.com/v1/interactions/"
payload = json.dumps(
{
"type": "audio",
"languageTag": language,
"vertical": verticle,
"audioTranscriptionMode": audioTranscriptionMode,
"downloadUri": downloadUri,
"includeAiResults": includeAiResults,
"originalfilename": originalFileName,
"externalidentifier": externalIdentifier,
}
)
if downloadUri is None:
payload = json.dumps(
{
"type": "audio",
"languageTag": language,
"vertical": verticle,
"audioTranscriptionMode": audioTranscriptionMode,
"includeAiResults": includeAiResults,
"originalfilename": originalFileName,
"externalidentifier": externalIdentifier,
}
)
headers = {"X-API-TOKEN": token, "Content-Type": "application/json"}
response = requests.request("POST", url, headers=headers, data=payload)
return response
def GetInteractionStatus(interactionId, token):
"""Check if interaction has been processed."""
url = "https://api.elevateai.com/v1/interactions/%s/status" % interactionId
headers = {"X-API-TOKEN": token, "Content-Type": "application/json"}
response = requests.request("GET", url, headers=headers)
return response
def UploadInteraction(
interactionId, token, localFilePath, fileName, originalFileName=None
):
"""Upload file to ElevateAI."""
url = "https://api.elevateai.com/v1/interactions/%s/upload" % interactionId
payload = {}
files = [
(fileName, (fileName, open(localFilePath, "rb"), "application/octet-stream"))
]
headers = {"X-API-Token": token}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
return response
def GetWordByWordTranscript(interactionId, token):
"""Get the word by word transcription of the interaction."""
url = "https://api.elevateai.com/v1/interactions/%s/transcript" % interactionId
headers = {"X-API-TOKEN": token, "Content-Type": "application/json"}
response = requests.request("GET", url, headers=headers)
return response
def GetPuncutatedTranscript(interactionId, token):
"""Get the punctuated version of the transcription."""
url = (
"https://api.elevateai.com/v1/interactions/%s/transcripts/punctuated"
% interactionId
)
headers = {"X-API-TOKEN": token, "Content-Type": "application/json"}
response = requests.request("GET", url, headers=headers)
return response
def GetAIResults(interactionId, token):
"""Get JSON with AI results."""
url = "https://api.elevateai.com/v1/interactions/%s/ai" % interactionId
headers = {"X-API-TOKEN": token, "Content-Type": "application/json"}
response = requests.request("GET", url, headers=headers)
return response