Skip to content

Commit a070479

Browse files
authored
Merge pull request #47 from slashml/update-exampels
update example
2 parents 5d2bc3e + 826f5b0 commit a070479

File tree

8 files changed

+18
-57
lines changed

8 files changed

+18
-57
lines changed

examples/pipeline_podcast_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Replace `API_KEY` with your SlasML API token. This example still runs without
44
# the API token but usage will be limited
5-
API_KEY = "a7011983a0f3d64ee113317b1e36f8e5bf56c14a"
5+
API_KEY = "YOUR_API_KEY"
66

77
service_provider_speech_to_text = SpeechToText.ServiceProvider.WHISPER
88
service_provider_summarize = TextSummarization.ServiceProvider.OPENAI

examples/speech_summarized.py

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,30 @@
11
from slashml import SpeechToText, TextSummarization
2-
import time
3-
4-
5-
def speech_to_text(uploaded_audio_url, service_provider, api_key):
6-
# Initialize model
7-
model = SpeechToText(api_key=api_key)
8-
9-
# Submit transcription request
10-
job = model.transcribe(uploaded_audio_url, service_provider=service_provider)
11-
12-
assert job.status != "ERROR", f"{job}"
13-
print(f"Job ID: {job.id}")
14-
15-
# check job status
16-
response = model.status(job.id, service_provider=service_provider)
17-
18-
while response.status == "IN_PROGRESS":
19-
time.sleep(30)
20-
response = model.status(job.id, service_provider=service_provider)
21-
print(f"Response = {response}. Retrying in 30 seconds")
22-
23-
return response
24-
25-
26-
def summarize(text, service_provider, api_key):
27-
# Initialize model
28-
model = TextSummarization(api_key=api_key)
29-
30-
# Submit request
31-
job = model.summarize(text=text, service_provider=service_provider)
32-
33-
assert job.status != "ERROR", f"{job}"
34-
print(f"Job ID: {job.id}")
35-
36-
# Check job status
37-
response = model.status(job.id, service_provider=service_provider)
38-
39-
# Keep checking job status until the task is complete
40-
while response.status == "PENDING":
41-
print(f"Response = {response}. Retrying in 30 seconds")
42-
time.sleep(30)
43-
response = model.status(job.id, service_provider=service_provider)
44-
45-
return response
46-
472

483
# Replace `API_KEY` with your SlasML API token. This example still runs without
494
# the API token but usage will be limited
50-
API_KEY = "b503d137d229fdd4085f59e9ea06ac95d2706182"
5+
API_KEY = "YOUR_API_KEY"
516

52-
service_provider_speech_to_text = SpeechToText.ServiceProvider.AWS
7+
service_provider_speech_to_text = SpeechToText.ServiceProvider.WHISPER
538
service_provider_summarize = TextSummarization.ServiceProvider.OPENAI
549

5510
# 10 minute audio file already uploaded
5611
uploaded_url = (
5712
"https://slashml.s3.ca-central-1.amazonaws.com/fda70f6a-6057-4541-adf1-2cf4f4182929"
5813
)
5914

15+
transcribe = SpeechToText(api_key=API_KEY)
16+
summarize = TextSummarization(api_key=API_KEY)
6017

61-
response_speech_to_text = speech_to_text(uploaded_url, service_provider_speech_to_text, API_KEY)
18+
response = transcribe.execute(
19+
upload_url=uploaded_url, service_provider=service_provider_speech_to_text
20+
)
6221

63-
transcribed_text = response_speech_to_text.transcription_data.transcription
22+
print('starting pipeline, the first response might take 10 secs')
23+
transcribed_text = response.transcription_data.transcription
6424
print (f"Transcribed Text = {transcribed_text}")
6525

66-
response_summarize = summarize(transcribed_text, service_provider_summarize, API_KEY)
26+
response_summarize = summarize.execute(transcribed_text, service_provider_summarize)
27+
6728
summary = response_summarize.summarization_data
6829

6930
print (f"Summarized Text = {summary}")

examples/speech_to_text_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def speech_to_text(audio_filepath, service_provider, api_key):
3232

3333
# Replace `API_KEY` with your SlasML API token. This example still runs without
3434
# the API token but usage will be limited
35-
API_KEY = None
35+
API_KEY = "YOUR_API_KEY"
3636
service_provider = SpeechToText.ServiceProvider.DEEPGRAM
3737
audio_filepath = "test.mp3"
3838

examples/speech_to_text_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Replace `API_KEY` with your SlasML API token. This example still runs without
44
# the API token but usage will be limited
5-
API_KEY = None
5+
API_KEY = "YOUR_API_KEY"
66
service_provider = SpeechToText.ServiceProvider.REV
77
audio_filepath = "test.mp3"
88

examples/summarize_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def summarize(text, service_provider, api_key):
2525

2626
# Replace `API_KEY` with your SlasML API token. This example still runs without
2727
# the API token but usage will be limited
28-
API_KEY = "b503d137d229fdd4085f59e9ea06ac95d2706182"
28+
API_KEY = "YOUR_API_KEY"
2929
service_provider = TextSummarization.ServiceProvider.OPENAI
3030
input_text = """A good writer doesn't just think, and then write down what he thought, as a sort of transcript. A good writer will almost always discover new things in the process of writing. And there is, as far as I know, no substitute for this kind of discovery. Talking about your ideas with other people is a good way to develop them. But even after doing this, you'll find you still discover new things when you sit down to write. There is a kind of thinking that can only be done by writing."""
3131

examples/summarize_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Replace `API_KEY` with your SlasML API token. This example still runs without
55
# the API token but usage will be limited
6-
API_KEY = "a7011983a0f3d64ee113317b1e36f8e5bf56c14a"
6+
API_KEY = "YOUR_API_KEY"
77
service_provider = TextSummarization.ServiceProvider.OPENAI
88

99
input_text = """A good writer doesn't just think, and then write down what he thought, as a sort of transcript. A good writer will almost always discover new things in the process of writing. And there is, as far as I know, no substitute for this kind of discovery. Talking about your ideas with other people is a good way to develop them. But even after doing this, you'll find you still discover new things when you sit down to write. There is a kind of thinking that can only be done by writing."""

examples/text_to_speech_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Replace `API_KEY` with your SlasML API token. This example still runs without
55
# the API token but usage will be limited
6-
API_KEY = None
6+
API_KEY = "YOUR_API_KEY"
77
service_provider = TextToSpeech.ServiceProvider.AWS
88
input_text = "To be or not to be, that is the question!"
99

examples/text_to_speech_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Replace `API_KEY` with your SlasML API token. This example still runs without
44
# the API token but usage will be limited
5-
API_KEY = None
5+
API_KEY = "YOUR_API_KEY"
66
service_provider = TextToSpeech.ServiceProvider.AWS
77
input_text = "To be or not to be, that is the question!"
88

0 commit comments

Comments
 (0)