-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REVAI-3855: examples #106
Merged
Merged
REVAI-3855: examples #106
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c067595
REVAI-3855: examples
kirillatrev 2f01360
1
kirillatrev ffbaf89
1
kirillatrev c513a0d
Update examples/async_summarize.py
kirillatrev eeeaeba
1
kirillatrev 65645e3
JobStatus pre-refactoring
kirillatrev b151aa2
JobStatus refactoring
kirillatrev 73cd38d
1
kirillatrev 91c7665
1
kirillatrev 645e118
1
kirillatrev 3674a06
compat
kirillatrev 5691fb7
1
kirillatrev 6677b65
1
kirillatrev fdd1b16
1
kirillatrev ce89403
1
kirillatrev 50f5e8e
1
kirillatrev 0638fbf
Fix
kirillatrev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"""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") | ||
|
||
while True: | ||
# Obtains details of a job in json format | ||
job_details = client.get_job_details(job.id) | ||
status = job_details.status | ||
summarization_status = job_details.summarization.status | ||
print("Job Status : {}. Summarization status: {}.".format(status, summarization_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/ | ||
if status == JobStatus.IN_PROGRESS or summarization_status == SummarizationJobStatus.IN_PROGRESS: | ||
time.sleep(5) | ||
continue | ||
|
||
if status == JobStatus.FAILED or summarization_status == SummarizationJobStatus.FAILED: | ||
print("Job Failed : {}".format(job_details.failure_detail)) | ||
break | ||
|
||
if status == JobStatus.TRANSCRIBED and summarization_status == SummarizationJobStatus.COMPLETED: | ||
# obtain transcript text as a string for the job. | ||
summary_text = client.get_transcript_summary_text(job.id) | ||
print(summary_text) | ||
|
||
# obtain transcript text as a json object for the job. | ||
summary_json = client.get_transcript_summary_json(job.id) | ||
|
||
# obtain transcript object for the job. | ||
summary_obj = client.get_transcript_summary_object(job.id) | ||
|
||
break | ||
|
||
# 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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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") | ||
|
||
while True: | ||
# Obtains details of a job in json format | ||
job_details = client.get_job_details(job.id) | ||
status = job_details.status | ||
translation_status = job_details.translation.target_languages[0].status | ||
print("Job Status : {}. Translation status: {}.".format(status, translation_status)) | ||
|
||
# Checks if the job has been transcribed and translated. 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 == JobStatus.IN_PROGRESS or translation_status == TranslationJobStatus.IN_PROGRESS: | ||
time.sleep(5) | ||
continue | ||
|
||
elif status == JobStatus.FAILED or translation_status == TranslationJobStatus.FAILED: | ||
print("Job Failed : {}".format(job_details.failure_detail)) | ||
break | ||
|
||
if status == JobStatus.TRANSCRIBED and translation_status == TranslationJobStatus.COMPLETED: | ||
# obtain transcript text as a string for the job. | ||
transcript_text = client.get_translated_transcript_text(job.id, 'es') | ||
print(transcript_text) | ||
|
||
# obtain transcript text as a json object for the job. | ||
transcript_json = client.get_translated_transcript_json(job.id, 'es') | ||
|
||
# obtain transcript object for the job. | ||
transcript_obj = client.get_translated_transcript_object(job.id, 'es') | ||
|
||
# obtain captions for the job. | ||
captions = client.get_translated_captions(job.id, 'es') | ||
|
||
break | ||
|
||
# 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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is odd formatting style (the integration instead of 4 spaces is much larger) are you trying to follow the existing format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely linter was complaining about the line length. I'll double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general - yes I was trying to follow existing formatting in other example files for consistency