Skip to content

Commit f6c0b38

Browse files
authored
REVAI-3855: examples (#106)
* REVAI-3855: examples
1 parent cfac469 commit f6c0b38

13 files changed

+308
-36
lines changed

examples/async_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""
1515

1616
import time
17-
from rev_ai import apiclient
17+
from rev_ai import apiclient, JobStatus
1818
from rev_ai.models import CustomVocabulary
1919

2020
# String containing your access token
@@ -72,23 +72,23 @@
7272
while True:
7373
# Obtains details of a job in json format
7474
job_details = client.get_job_details(job.id)
75-
status = job_details.status.name
75+
status = job_details.status
7676

7777
print("Job Status : {}".format(status))
7878

7979
# Checks if the job has been transcribed. Please note that this is not the recommended way
8080
# of getting job status in a real application. For recommended methods of getting job status
8181
# please see our documentation on setting a callback url here:
8282
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
83-
if status == "IN_PROGRESS":
83+
if status == JobStatus.IN_PROGRESS:
8484
time.sleep(5)
8585
continue
8686

8787
elif status == "FAILED":
8888
print("Job Failed : {}".format(job_details.failure_detail))
8989
break
9090

91-
if status == "TRANSCRIBED":
91+
if status == JobStatus.TRANSCRIBED:
9292
# Getting a list of current jobs connected with your account
9393
# The optional parameters limits the length of the list.
9494
# starting_after is a job id which causes the removal of

examples/async_summarize.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
"""Copyright 2019 REV
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
"""
15+
16+
import time
17+
from rev_ai import apiclient, JobStatus
18+
from rev_ai.models.asynchronous.summarization_job_status import SummarizationJobStatus
19+
from rev_ai.models.asynchronous.summarization_options import SummarizationOptions
20+
from rev_ai.models.nlp_model import NlpModel
21+
22+
# String containing your access token
23+
access_token = "<your_access_token>"
24+
25+
# Create your api client
26+
client = apiclient.RevAiAPIClient(access_token)
27+
28+
# Submitting a job through a local file.
29+
#
30+
# job = client.submit_job_local_file("your_local_file_path",
31+
# delete_after_seconds=2592000,
32+
# language='en',
33+
# summarization_config=SummarizationOptions(
34+
# model=NlpModel.PREMIUM
35+
# ))
36+
37+
38+
# Submitting a job with a link to the file you want transcribed
39+
# Change url to your url, custom_vocabularies is optional like above
40+
url = "https://www.rev.ai/FTC_Sample_1.mp3"
41+
job = client.submit_job_url(media_url=url,
42+
delete_after_seconds=2592000,
43+
language='en',
44+
summarization_config=SummarizationOptions(model=NlpModel.PREMIUM))
45+
46+
print("Submitted Job")
47+
print("Job Status : {}".format(job.status))
48+
# Checks if the job has been transcribed and summarized. Please note that this is not the recommended way
49+
# of getting job status in a real application. For recommended methods of getting job status
50+
# please see our documentation on setting a callback url here:
51+
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
52+
53+
while job.status == JobStatus.IN_PROGRESS:
54+
time.sleep(5)
55+
# Obtains details of a job in json format
56+
job = client.get_job_details(job.id)
57+
print("Job Status : {}".format(job.status))
58+
59+
if job.status == JobStatus.FAILED:
60+
print("Job Failed : {}".format(job.failure_detail))
61+
exit()
62+
63+
if job.status == JobStatus.TRANSCRIBED:
64+
print("Summarization Status : {}".format(job.summarization.status))
65+
# Checks if the job has been summarized. Please note that this is not the recommended way
66+
# of getting job status in a real application. For recommended methods of getting job status
67+
# please see our documentation on setting a callback url here:
68+
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
69+
while job.summarization.status == SummarizationJobStatus.IN_PROGRESS:
70+
time.sleep(5)
71+
# Obtains details of a job in json format
72+
job = client.get_job_details(job.id)
73+
print("Summarization Status : {}".format(job.summarization.status))
74+
75+
if job.summarization.status == SummarizationJobStatus.FAILED:
76+
print("Summarization Failed : {}".format(job.summarization.failure))
77+
exit()
78+
79+
# obtain transcript summary as a string for the job.
80+
summary_text = client.get_transcript_summary_text(job.id)
81+
print(summary_text)
82+
83+
# obtain transcript summary as a json object for the job.
84+
summary_json = client.get_transcript_summary_json(job.id)
85+
86+
# obtain transcript summary object for the job.
87+
summary_obj = client.get_transcript_summary_object(job.id)
88+
89+
# Use the objects however you please
90+
91+
# Once you are done with the job, you can delete it.
92+
# NOTE : This will PERMANENTLY DELETE all data related to a job. Exercise only
93+
# if you're sure you want to delete the job.
94+
# client.delete_job(job.id)
95+
print("Job Submission and Collection Finished.")

examples/async_translate.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"""Copyright 2019 REV
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
"""
15+
16+
import time
17+
from rev_ai import apiclient, JobStatus
18+
from rev_ai.models.asynchronous.translation_job_status import TranslationJobStatus
19+
from rev_ai.models.asynchronous.translation_language_options import TranslationLanguageOptions
20+
from rev_ai.models.asynchronous.translation_options import TranslationOptions
21+
from rev_ai.models.nlp_model import NlpModel
22+
23+
# String containing your access token
24+
access_token = "<your_access_token>"
25+
26+
# Create your api client
27+
client = apiclient.RevAiAPIClient(access_token)
28+
29+
# Submitting a job through a local file.
30+
#
31+
# job = client.submit_job_local_file("your_local_file_path",
32+
# delete_after_seconds=2592000,
33+
# language='en',
34+
# translation_config=TranslationOptions(
35+
# target_languages=[
36+
# TranslationLanguageOptions("es", NlpModel.PREMIUM)
37+
# ]
38+
# ))
39+
40+
41+
# Submitting a job with a link to the file you want transcribed and translated
42+
url = "https://www.rev.ai/FTC_Sample_1.mp3"
43+
job = client.submit_job_url(media_url=url,
44+
delete_after_seconds=2592000,
45+
language='en',
46+
translation_config=TranslationOptions(
47+
target_languages=[
48+
TranslationLanguageOptions("es", NlpModel.PREMIUM)
49+
]
50+
))
51+
52+
print("Submitted Job")
53+
print("Job Status : {}".format(job.status))
54+
55+
# Checks if the job has been transcribed and summarized. Please note that this is not the recommended way
56+
# of getting job status in a real application. For recommended methods of getting job status
57+
# please see our documentation on setting a callback url here:
58+
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
59+
60+
while job.status == JobStatus.IN_PROGRESS:
61+
time.sleep(5)
62+
# Obtains details of a job in json format
63+
job = client.get_job_details(job.id)
64+
print("Job Status : {}".format(job.status))
65+
66+
if job.status == JobStatus.FAILED:
67+
print("Job Failed : {}".format(job.failure_detail))
68+
exit()
69+
70+
if job.status == JobStatus.TRANSCRIBED:
71+
print("Translation Status : {}".format(job.translation.target_languages[0].status))
72+
# Checks if the job has been summarized. Please note that this is not the recommended way
73+
# of getting job status in a real application. For recommended methods of getting job status
74+
# please see our documentation on setting a callback url here:
75+
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
76+
while job.translation.target_languages[0].status == TranslationJobStatus.IN_PROGRESS:
77+
time.sleep(5)
78+
# Obtains details of a job in json format
79+
job = client.get_job_details(job.id)
80+
print("Translation Status : {}".format(job.translation.target_languages[0].status))
81+
82+
if job.translation.target_languages[0].status == TranslationJobStatus.FAILED:
83+
print("Translation Failed : {}".format(job.translation.target_languages[0].failure))
84+
exit()
85+
86+
# obtain transcript translation as a string for the job.
87+
transcript_text = client.get_translated_transcript_text(job.id, 'es')
88+
print(transcript_text)
89+
90+
# obtain transcript translation as a json object for the job.
91+
transcript_json = client.get_translated_transcript_json(job.id, 'es')
92+
93+
# obtain transcript translation object for the job.
94+
transcript_obj = client.get_translated_transcript_object(job.id, 'es')
95+
96+
# obtain translated captions for the job.
97+
captions = client.get_translated_captions(job.id, 'es')
98+
99+
# Use the objects however you please
100+
101+
# Once you are done with the job, you can delete it.
102+
# NOTE : This will PERMANENTLY DELETE all data related to a job. Exercise only
103+
# if you're sure you want to delete the job.
104+
# client.delete_job(job.id)
105+
print("Job Submission and Collection Finished.")

examples/language_identification_example.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"""
1515

1616
import time
17-
from rev_ai import language_identification_client
18-
17+
from rev_ai import language_identification_client, JobStatus
1918

2019
from rev_ai.models.customer_url_data import CustomerUrlData
2120

@@ -40,23 +39,23 @@
4039
while True:
4140
# Obtains details of a job in json format
4241
job_details = client.get_job_details(job.id)
43-
status = job_details.status.name
42+
status = job_details.status
4443

4544
print("Job Status : {}".format(status))
4645

4746
# Checks if the job has been completed. Please note that this is not the recommended way
4847
# of getting job status in a real application. For recommended methods of getting job status
4948
# please see our documentation on callback_urls here:
5049
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
51-
if status == "IN_PROGRESS":
52-
time.sleep(2)
50+
if status == JobStatus.IN_PROGRESS:
51+
time.sleep(5)
5352
continue
5453

55-
elif status == "FAILED":
54+
elif status == JobStatus.FAILED:
5655
print("Job Failed : {}".format(job_details.failure_detail))
5756
break
5857

59-
if status == "COMPLETED":
58+
if status == JobStatus.COMPLETED:
6059
# Getting a list of current language identification jobs connected with your account
6160
# The optional parameters limits the length of the list.
6261
# starting_after is a job id which causes the removal of

examples/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
rev-ai==2.17.1
1+
rev-ai==2.19.1
22
pyaudio==0.2.11
33
six==1.12.0

examples/sentiment_analysis_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""
1515

1616
import time
17-
from rev_ai import sentiment_analysis_client, apiclient
17+
from rev_ai import sentiment_analysis_client, apiclient, JobStatus
1818
from rev_ai.models import SentimentValue
1919

2020

@@ -59,23 +59,23 @@
5959
while True:
6060
# Obtains details of a job in json format
6161
job_details = client.get_job_details(job.id)
62-
status = job_details.status.name
62+
status = job_details.status
6363

6464
print("Job Status : {}".format(status))
6565

6666
# Checks if the job has been completed. Please note that this is not the recommended way
6767
# of getting job status in a real application. For recommended methods of getting job status
6868
# please see our documentation on callback_urls here:
6969
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
70-
if status == "IN_PROGRESS":
70+
if status == JobStatus.IN_PROGRESS:
7171
time.sleep(2)
7272
continue
7373

74-
elif status == "FAILED":
74+
elif status == JobStatus.FAILED:
7575
print("Job Failed : {}".format(job_details.failure_detail))
7676
break
7777

78-
if status == "COMPLETED":
78+
if status == JobStatus.COMPLETED:
7979
# Getting a list of current sentiment analysis jobs connected with your account
8080
# The optional parameters limits the length of the list.
8181
# starting_after is a job id which causes the removal of

examples/topic_extraction_example.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"""
1515

1616
import time
17-
from rev_ai import topic_extraction_client, apiclient
18-
17+
from rev_ai import topic_extraction_client, apiclient, JobStatus
1918

2019
# String containing your access token
2120
access_token = "<your_access_token>"
@@ -56,23 +55,23 @@
5655
while True:
5756
# Obtains details of a job in json format
5857
job_details = client.get_job_details(job.id)
59-
status = job_details.status.name
58+
status = job_details.status
6059

6160
print("Job Status : {}".format(status))
6261

6362
# Checks if the job has been completed. Please note that this is not the recommended way
6463
# of getting job status in a real application. For recommended methods of getting job status
6564
# please see our documentation on setting a callback url here:
6665
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
67-
if status == "IN_PROGRESS":
66+
if status == JobStatus.IN_PROGRESS:
6867
time.sleep(2)
6968
continue
7069

71-
elif status == "FAILED":
70+
elif status == JobStatus.FAILED:
7271
print("Job Failed : {}".format(job_details.failure_detail))
7372
break
7473

75-
if status == "COMPLETED":
74+
if status == JobStatus.COMPLETED:
7675
# Getting a list of current topic extraction jobs connected with your account
7776
# The optional parameters limits the length of the list.
7877
# starting_after is a job id which causes the removal of

src/rev_ai/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
"""Top-level package for rev_ai"""
33

4-
__version__ = '2.19.0'
4+
__version__ = '2.19.1'
55

66
from .models import Job, JobStatus, Account, Transcript, Monologue, Element, MediaConfig, \
77
CaptionType, CustomVocabulary, TopicExtractionJob, TopicExtractionResult, Topic, Informant, \

0 commit comments

Comments
 (0)