Skip to content

Commit 8094585

Browse files
authored
Merge pull request #35 from slashml/add-model-execute
change interface; todo: update changelog
2 parents a4979d4 + 4e588fd commit 8094585

13 files changed

+196
-60
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
All notable changes to `slashml-python-client` aka `slashml` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5-
## 0.0.4 - 2023-05-08
5+
## 0.0.6 - 2023-05-11
6+
7+
### Changed
8+
- Combined submit_job and status check into a single function call.
9+
10+
## 0.0.5 - 2023-05-08
611

712
### Added
813
- SpeechToText service

README.md

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,92 +16,56 @@ pip install slashml
1616

1717
```python
1818
from slashml import TextToSpeech
19-
import time
2019

21-
# Initialize model
22-
model = TextToSpeech()
23-
24-
service_provider = TextToSpeech.ServiceProvider.GOOGLE
25-
26-
# Submit speechification request
27-
job = model.speechify(text="To be or not to be, that is the question!", service_provider=service_provider)
28-
29-
assert job.status != "ERROR", f"{job}"
30-
print(f"Job ID: {job.id}")
20+
# Replace `API_KEY` with your SlasML API token. This example still runs without
21+
# the API token but usage will be limited
22+
model = TextToSpeech(api_key=None)
3123

32-
# check job status
33-
response = model.status(job.id, service_provider=service_provider)
24+
input_text = "to be or not to be, that is the question!"
3425

35-
while response.status == "IN_PROGRESS":
36-
time.sleep(5)
37-
response = model.status(job.id, service_provider=service_provider)
38-
print(f"Response = {response}. Retrying in 5 seconds")
26+
# Submit request
27+
job = model.execute(text=input_text, service_provider=TextToSpeech.ServiceProvider.AWS)
3928

40-
print(response)
29+
print (f"\n\n\n You can access the audio file here: {job.audio_url}")
4130
```
4231

4332
#### Transcribe an audio file
4433
<!-- write a code snippet in the minimum number of lines -->
4534

4635
```python
4736
from slashml import SpeechToText
48-
import time
49-
50-
# Initialize model
51-
model = SpeechToText()
52-
53-
service_provider = SpeechToText.ServiceProvider.WHISPER
54-
# Submit transcription request
55-
job = model.transcribe(upload_url="https://slashml.s3.ca-central-1.amazonaws.com/c7d38026-3ab4-4a04-ad9e-b6679ab79a87", service_provider=service_provider)
5637

57-
assert job.status != "ERROR", f"{job}"
58-
print(f"Job ID: {job.id}")
38+
# Replace `API_KEY` with your SlasML API token. This example still runs without
39+
# the API token but usage will be limited
40+
model = SpeechToText(api_key=None)
5941

60-
# check job status
61-
response = model.status(job.id, service_provider=service_provider)
42+
response = model.execute(
43+
upload_url='https://slashml.s3.ca-central-1.amazonaws.com/695c711f-9f5d-4ff1-ae4f-4439842eef5f',
44+
service_provider=SpeechToText.ServiceProvider.WHISPER
45+
)
6246

63-
while response.status == "IN_PROGRESS":
64-
time.sleep(5)
65-
response = model.status(job.id, service_provider=service_provider)
66-
print(f"Response = {response}. Retrying in 5 seconds")
47+
print(f"\n\n\n\nTranscription = {response.transcription_data.transcription}")
6748

68-
print(response)
6949
```
7050

7151
#### Summarize a text input
7252
<!-- write a code snippet in the minimum number of lines -->
7353

7454
```python
7555
from slashml import TextSummarization
76-
import time
7756

78-
# Initialize model
79-
model = TextSummarization()
80-
81-
service_provider = TextSummarization.ServiceProvider.OPENAI
82-
83-
# Submit summariztion request
84-
job = model.summarize(text="There are of course kinds of thinking that can be done without writing. If you don't need to go too deeply into a problem, you can solve it without writing. If you're thinking about how two pieces of machinery should fit together, writing about it probably won't help much. And when a problem can be described formally, you can sometimes solve it in your head. But if you need to solve a complicated, ill-defined problem, it will almost always help to write about it. Which in turn means that someone who's not good at writing will almost always be at a disadvantage in solving such problems.", service_provider=service_provider)
57+
model = TextSummarization(api_key=None)
8558

86-
assert job.status != "ERROR", f"{job}"
87-
print(f"Job ID: {job.id}")
59+
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."""
8860

89-
# check job status
90-
response = model.status(job.id, service_provider=service_provider)
61+
response = model.execute(text=input_text, service_provider=TextSummarization.ServiceProvider.OPENAI)
9162

92-
while response.status == "IN_PROGRESS":
93-
time.sleep(5)
94-
response = model.status(job.id, service_provider=service_provider)
95-
print(f"Response = {response}. Retrying in 5 seconds")
63+
print(f"Summary = {response.summarization_data}")
9664

97-
print(response)
9865
```
9966

10067

101-
102-
10368
### View the list of service providers available
104-
10569
```python
10670
from slashml import TextToSpeech
10771

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from slashml import SpeechToText, TextSummarization, TextToSpeech
2+
3+
# Replace `API_KEY` with your SlasML API token. This example still runs without
4+
# the API token but usage will be limited
5+
API_KEY = "a7011983a0f3d64ee113317b1e36f8e5bf56c14a"
6+
7+
service_provider_speech_to_text = SpeechToText.ServiceProvider.WHISPER
8+
service_provider_summarize = TextSummarization.ServiceProvider.OPENAI
9+
service_provider_text_to_speech = TextToSpeech.ServiceProvider.GOOGLE
10+
11+
# 10 minute audio file already uploaded
12+
uploaded_url = (
13+
"https://slashml.s3.ca-central-1.amazonaws.com/fda70f6a-6057-4541-adf1-2cf4f4182929"
14+
)
15+
16+
transcribe = SpeechToText(api_key=API_KEY)
17+
summarize = TextSummarization(api_key=API_KEY)
18+
speechify = TextToSpeech(api_key=API_KEY)
19+
20+
21+
response = transcribe.execute(
22+
upload_url=uploaded_url, service_provider=service_provider_speech_to_text
23+
)
24+
25+
print('starting pipeline, the first response might take 10 secs')
26+
transcribed_text = response.transcription_data.transcription
27+
print (f"Transcribed Text = {transcribed_text}")
28+
29+
response_summarize = summarize.execute(transcribed_text, service_provider_summarize)
30+
31+
summary = response_summarize.summarization_data
32+
33+
print (f"Summarized Text = {summary}")
34+
35+
response = speechify.execute(summary, service_provider_text_to_speech)
36+
37+
print (f"\n\n\n You can access the audio file here: {response.audio_url}")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from slashml import SpeechToText
22
import time
33

4+
# update the examples using execute from the SpeechToText class
45

56
def speech_to_text(audio_filepath, service_provider, api_key):
67
# Initialize model

examples/speech_to_text_sync.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from slashml import SpeechToText
2+
3+
# Replace `API_KEY` with your SlasML API token. This example still runs without
4+
# the API token but usage will be limited
5+
API_KEY = None
6+
service_provider = SpeechToText.ServiceProvider.AWS
7+
audio_filepath = "test.mp3"
8+
9+
# Find all the service providers that we support by running the choices() method
10+
print(f"Available providers: {SpeechToText.ServiceProvider.choices()}")
11+
print(f"Selected provider: {service_provider}")
12+
13+
14+
model = SpeechToText(api_key=API_KEY)
15+
16+
# Upload audio
17+
uploaded_file = model.upload_audio(audio_filepath)
18+
print(f"file uploaded: {uploaded_file}")
19+
20+
response = model.execute(
21+
upload_url=uploaded_file["upload_url"], service_provider=service_provider
22+
)
23+
24+
print(f"\n\n\n\nTranscription = {response.transcription_data.transcription}")

examples/summarize_sync.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from slashml import TextSummarization
2+
3+
4+
# Replace `API_KEY` with your SlasML API token. This example still runs without
5+
# the API token but usage will be limited
6+
API_KEY = "a7011983a0f3d64ee113317b1e36f8e5bf56c14a"
7+
service_provider = TextSummarization.ServiceProvider.OPENAI
8+
9+
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."""
10+
11+
model = TextSummarization(api_key=API_KEY)
12+
13+
# Find all the service providers that we support by running the choices() method
14+
print(f"Available providers: {TextSummarization.ServiceProvider.choices()}")
15+
print(f"Selected provider: {service_provider}")
16+
17+
response = model.execute(text=input_text, service_provider=service_provider)
18+
19+
print(f"Summary = {response.summarization_data}")

examples/text_to_speech_sync.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from slashml import TextToSpeech
2+
3+
# Replace `API_KEY` with your SlasML API token. This example still runs without
4+
# the API token but usage will be limited
5+
API_KEY = None
6+
service_provider = TextToSpeech.ServiceProvider.AWS
7+
input_text = "To be or not to be, that is the question!"
8+
9+
# Find all the service providers that we support by running the choices() method
10+
print(f"Available providers: {TextToSpeech.ServiceProvider.choices()}")
11+
print(f"Selected provider: {service_provider}")
12+
13+
model = TextToSpeech(api_key=API_KEY)
14+
15+
# Submit request
16+
job = model.execute(text=input_text, service_provider=service_provider)
17+
18+
print (f"\n\n\n You can access the audio file here: {job.audio_url}")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def read_req_file(req_type):
1414

1515
setup(
1616
name="slashml",
17-
version="0.0.5",
17+
version="0.0.6",
1818
url="https://slashml.com/",
1919
author="eff-kay",
2020
author_email="faiizan14@gmail.com",

0 commit comments

Comments
 (0)