Skip to content

Commit

Permalink
REVAI-3855: examples (#106)
Browse files Browse the repository at this point in the history
* REVAI-3855: examples
  • Loading branch information
kirillatrev authored Dec 26, 2023
1 parent cfac469 commit f6c0b38
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 36 deletions.
8 changes: 4 additions & 4 deletions examples/async_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""

import time
from rev_ai import apiclient
from rev_ai import apiclient, JobStatus
from rev_ai.models import CustomVocabulary

# String containing your access token
Expand Down Expand Up @@ -72,23 +72,23 @@
while True:
# Obtains details of a job in json format
job_details = client.get_job_details(job.id)
status = job_details.status.name
status = job_details.status

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

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

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

if status == "TRANSCRIBED":
if status == JobStatus.TRANSCRIBED:
# Getting a list of current jobs connected with your account
# The optional parameters limits the length of the list.
# starting_after is a job id which causes the removal of
Expand Down
95 changes: 95 additions & 0 deletions examples/async_summarize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""Copyright 2019 REV
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import time
from rev_ai import apiclient, JobStatus
from rev_ai.models.asynchronous.summarization_job_status import SummarizationJobStatus
from rev_ai.models.asynchronous.summarization_options import SummarizationOptions
from rev_ai.models.nlp_model import NlpModel

# String containing your access token
access_token = "<your_access_token>"

# Create your api client
client = apiclient.RevAiAPIClient(access_token)

# Submitting a job through a local file.
#
# job = client.submit_job_local_file("your_local_file_path",
# delete_after_seconds=2592000,
# language='en',
# summarization_config=SummarizationOptions(
# model=NlpModel.PREMIUM
# ))


# Submitting a job with a link to the file you want transcribed
# Change url to your url, custom_vocabularies is optional like above
url = "https://www.rev.ai/FTC_Sample_1.mp3"
job = client.submit_job_url(media_url=url,
delete_after_seconds=2592000,
language='en',
summarization_config=SummarizationOptions(model=NlpModel.PREMIUM))

print("Submitted Job")
print("Job Status : {}".format(job.status))
# Checks if the job has been transcribed and summarized. Please note that this is not the recommended way
# of getting job status in a real application. For recommended methods of getting job status
# please see our documentation on setting a callback url here:
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/

while job.status == JobStatus.IN_PROGRESS:
time.sleep(5)
# Obtains details of a job in json format
job = client.get_job_details(job.id)
print("Job Status : {}".format(job.status))

if job.status == JobStatus.FAILED:
print("Job Failed : {}".format(job.failure_detail))
exit()

if job.status == JobStatus.TRANSCRIBED:
print("Summarization Status : {}".format(job.summarization.status))
# Checks if the job has been summarized. Please note that this is not the recommended way
# of getting job status in a real application. For recommended methods of getting job status
# please see our documentation on setting a callback url here:
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
while job.summarization.status == SummarizationJobStatus.IN_PROGRESS:
time.sleep(5)
# Obtains details of a job in json format
job = client.get_job_details(job.id)
print("Summarization Status : {}".format(job.summarization.status))

if job.summarization.status == SummarizationJobStatus.FAILED:
print("Summarization Failed : {}".format(job.summarization.failure))
exit()

# obtain transcript summary as a string for the job.
summary_text = client.get_transcript_summary_text(job.id)
print(summary_text)

# obtain transcript summary as a json object for the job.
summary_json = client.get_transcript_summary_json(job.id)

# obtain transcript summary object for the job.
summary_obj = client.get_transcript_summary_object(job.id)

# Use the objects however you please

# Once you are done with the job, you can delete it.
# NOTE : This will PERMANENTLY DELETE all data related to a job. Exercise only
# if you're sure you want to delete the job.
# client.delete_job(job.id)
print("Job Submission and Collection Finished.")
105 changes: 105 additions & 0 deletions examples/async_translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""Copyright 2019 REV
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import time
from rev_ai import apiclient, JobStatus
from rev_ai.models.asynchronous.translation_job_status import TranslationJobStatus
from rev_ai.models.asynchronous.translation_language_options import TranslationLanguageOptions
from rev_ai.models.asynchronous.translation_options import TranslationOptions
from rev_ai.models.nlp_model import NlpModel

# String containing your access token
access_token = "<your_access_token>"

# Create your api client
client = apiclient.RevAiAPIClient(access_token)

# Submitting a job through a local file.
#
# job = client.submit_job_local_file("your_local_file_path",
# delete_after_seconds=2592000,
# language='en',
# translation_config=TranslationOptions(
# target_languages=[
# TranslationLanguageOptions("es", NlpModel.PREMIUM)
# ]
# ))


# Submitting a job with a link to the file you want transcribed and translated
url = "https://www.rev.ai/FTC_Sample_1.mp3"
job = client.submit_job_url(media_url=url,
delete_after_seconds=2592000,
language='en',
translation_config=TranslationOptions(
target_languages=[
TranslationLanguageOptions("es", NlpModel.PREMIUM)
]
))

print("Submitted Job")
print("Job Status : {}".format(job.status))

# Checks if the job has been transcribed and summarized. Please note that this is not the recommended way
# of getting job status in a real application. For recommended methods of getting job status
# please see our documentation on setting a callback url here:
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/

while job.status == JobStatus.IN_PROGRESS:
time.sleep(5)
# Obtains details of a job in json format
job = client.get_job_details(job.id)
print("Job Status : {}".format(job.status))

if job.status == JobStatus.FAILED:
print("Job Failed : {}".format(job.failure_detail))
exit()

if job.status == JobStatus.TRANSCRIBED:
print("Translation Status : {}".format(job.translation.target_languages[0].status))
# Checks if the job has been summarized. Please note that this is not the recommended way
# of getting job status in a real application. For recommended methods of getting job status
# please see our documentation on setting a callback url here:
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
while job.translation.target_languages[0].status == TranslationJobStatus.IN_PROGRESS:
time.sleep(5)
# Obtains details of a job in json format
job = client.get_job_details(job.id)
print("Translation Status : {}".format(job.translation.target_languages[0].status))

if job.translation.target_languages[0].status == TranslationJobStatus.FAILED:
print("Translation Failed : {}".format(job.translation.target_languages[0].failure))
exit()

# obtain transcript translation as a string for the job.
transcript_text = client.get_translated_transcript_text(job.id, 'es')
print(transcript_text)

# obtain transcript translation as a json object for the job.
transcript_json = client.get_translated_transcript_json(job.id, 'es')

# obtain transcript translation object for the job.
transcript_obj = client.get_translated_transcript_object(job.id, 'es')

# obtain translated captions for the job.
captions = client.get_translated_captions(job.id, 'es')

# Use the objects however you please

# Once you are done with the job, you can delete it.
# NOTE : This will PERMANENTLY DELETE all data related to a job. Exercise only
# if you're sure you want to delete the job.
# client.delete_job(job.id)
print("Job Submission and Collection Finished.")
13 changes: 6 additions & 7 deletions examples/language_identification_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"""

import time
from rev_ai import language_identification_client

from rev_ai import language_identification_client, JobStatus

from rev_ai.models.customer_url_data import CustomerUrlData

Expand All @@ -40,23 +39,23 @@
while True:
# Obtains details of a job in json format
job_details = client.get_job_details(job.id)
status = job_details.status.name
status = job_details.status

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

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

elif status == "FAILED":
elif status == JobStatus.FAILED:
print("Job Failed : {}".format(job_details.failure_detail))
break

if status == "COMPLETED":
if status == JobStatus.COMPLETED:
# Getting a list of current language identification jobs connected with your account
# The optional parameters limits the length of the list.
# starting_after is a job id which causes the removal of
Expand Down
2 changes: 1 addition & 1 deletion examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rev-ai==2.17.1
rev-ai==2.19.1
pyaudio==0.2.11
six==1.12.0
10 changes: 5 additions & 5 deletions examples/sentiment_analysis_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""

import time
from rev_ai import sentiment_analysis_client, apiclient
from rev_ai import sentiment_analysis_client, apiclient, JobStatus
from rev_ai.models import SentimentValue


Expand Down Expand Up @@ -59,23 +59,23 @@
while True:
# Obtains details of a job in json format
job_details = client.get_job_details(job.id)
status = job_details.status.name
status = job_details.status

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

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

elif status == "FAILED":
elif status == JobStatus.FAILED:
print("Job Failed : {}".format(job_details.failure_detail))
break

if status == "COMPLETED":
if status == JobStatus.COMPLETED:
# Getting a list of current sentiment analysis jobs connected with your account
# The optional parameters limits the length of the list.
# starting_after is a job id which causes the removal of
Expand Down
11 changes: 5 additions & 6 deletions examples/topic_extraction_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"""

import time
from rev_ai import topic_extraction_client, apiclient

from rev_ai import topic_extraction_client, apiclient, JobStatus

# String containing your access token
access_token = "<your_access_token>"
Expand Down Expand Up @@ -56,23 +55,23 @@
while True:
# Obtains details of a job in json format
job_details = client.get_job_details(job.id)
status = job_details.status.name
status = job_details.status

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

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

elif status == "FAILED":
elif status == JobStatus.FAILED:
print("Job Failed : {}".format(job_details.failure_detail))
break

if status == "COMPLETED":
if status == JobStatus.COMPLETED:
# Getting a list of current topic extraction jobs connected with your account
# The optional parameters limits the length of the list.
# starting_after is a job id which causes the removal of
Expand Down
2 changes: 1 addition & 1 deletion src/rev_ai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Top-level package for rev_ai"""

__version__ = '2.19.0'
__version__ = '2.19.1'

from .models import Job, JobStatus, Account, Transcript, Monologue, Element, MediaConfig, \
CaptionType, CustomVocabulary, TopicExtractionJob, TopicExtractionResult, Topic, Informant, \
Expand Down
Loading

0 comments on commit f6c0b38

Please sign in to comment.