Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
All notable changes to `slashml-python-client` aka `slashml` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## 0.0.4 - 2023-05-08
## 0.0.6 - 2023-05-11

### Changed
- Combined submit_job and status check into a single function call.

## 0.0.5 - 2023-05-08

### Added
- SpeechToText service
Expand Down
74 changes: 19 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,92 +16,56 @@ pip install slashml

```python
from slashml import TextToSpeech
import time

# Initialize model
model = TextToSpeech()

service_provider = TextToSpeech.ServiceProvider.GOOGLE

# Submit speechification request
job = model.speechify(text="To be or not to be, that is the question!", service_provider=service_provider)

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

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

while response.status == "IN_PROGRESS":
time.sleep(5)
response = model.status(job.id, service_provider=service_provider)
print(f"Response = {response}. Retrying in 5 seconds")
# Submit request
job = model.execute(text=input_text, service_provider=TextToSpeech.ServiceProvider.AWS)

print(response)
print (f"\n\n\n You can access the audio file here: {job.audio_url}")
```

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

```python
from slashml import SpeechToText
import time

# Initialize model
model = SpeechToText()

service_provider = SpeechToText.ServiceProvider.WHISPER
# Submit transcription request
job = model.transcribe(upload_url="https://slashml.s3.ca-central-1.amazonaws.com/c7d38026-3ab4-4a04-ad9e-b6679ab79a87", service_provider=service_provider)

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

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

while response.status == "IN_PROGRESS":
time.sleep(5)
response = model.status(job.id, service_provider=service_provider)
print(f"Response = {response}. Retrying in 5 seconds")
print(f"\n\n\n\nTranscription = {response.transcription_data.transcription}")

print(response)
```

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

```python
from slashml import TextSummarization
import time

# Initialize model
model = TextSummarization()

service_provider = TextSummarization.ServiceProvider.OPENAI

# Submit summariztion request
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)
model = TextSummarization(api_key=None)

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

# check job status
response = model.status(job.id, service_provider=service_provider)
response = model.execute(text=input_text, service_provider=TextSummarization.ServiceProvider.OPENAI)

while response.status == "IN_PROGRESS":
time.sleep(5)
response = model.status(job.id, service_provider=service_provider)
print(f"Response = {response}. Retrying in 5 seconds")
print(f"Summary = {response.summarization_data}")

print(response)
```




### View the list of service providers available

```python
from slashml import TextToSpeech

Expand Down
37 changes: 37 additions & 0 deletions examples/pipeline_podcast_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from slashml import SpeechToText, TextSummarization, TextToSpeech

# Replace `API_KEY` with your SlasML API token. This example still runs without
# the API token but usage will be limited
API_KEY = "a7011983a0f3d64ee113317b1e36f8e5bf56c14a"

service_provider_speech_to_text = SpeechToText.ServiceProvider.WHISPER
service_provider_summarize = TextSummarization.ServiceProvider.OPENAI
service_provider_text_to_speech = TextToSpeech.ServiceProvider.GOOGLE

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

transcribe = SpeechToText(api_key=API_KEY)
summarize = TextSummarization(api_key=API_KEY)
speechify = TextToSpeech(api_key=API_KEY)


response = transcribe.execute(
upload_url=uploaded_url, service_provider=service_provider_speech_to_text
)

print('starting pipeline, the first response might take 10 secs')
transcribed_text = response.transcription_data.transcription
print (f"Transcribed Text = {transcribed_text}")

response_summarize = summarize.execute(transcribed_text, service_provider_summarize)

summary = response_summarize.summarization_data

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

response = speechify.execute(summary, service_provider_text_to_speech)

print (f"\n\n\n You can access the audio file here: {response.audio_url}")
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from slashml import SpeechToText
import time

# update the examples using execute from the SpeechToText class

def speech_to_text(audio_filepath, service_provider, api_key):
# Initialize model
Expand Down
24 changes: 24 additions & 0 deletions examples/speech_to_text_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from slashml import SpeechToText

# Replace `API_KEY` with your SlasML API token. This example still runs without
# the API token but usage will be limited
API_KEY = None
service_provider = SpeechToText.ServiceProvider.AWS
audio_filepath = "test.mp3"

# Find all the service providers that we support by running the choices() method
print(f"Available providers: {SpeechToText.ServiceProvider.choices()}")
print(f"Selected provider: {service_provider}")


model = SpeechToText(api_key=API_KEY)

# Upload audio
uploaded_file = model.upload_audio(audio_filepath)
print(f"file uploaded: {uploaded_file}")

response = model.execute(
upload_url=uploaded_file["upload_url"], service_provider=service_provider
)

print(f"\n\n\n\nTranscription = {response.transcription_data.transcription}")
File renamed without changes.
19 changes: 19 additions & 0 deletions examples/summarize_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from slashml import TextSummarization


# Replace `API_KEY` with your SlasML API token. This example still runs without
# the API token but usage will be limited
API_KEY = "a7011983a0f3d64ee113317b1e36f8e5bf56c14a"
service_provider = TextSummarization.ServiceProvider.OPENAI

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."""

model = TextSummarization(api_key=API_KEY)

# Find all the service providers that we support by running the choices() method
print(f"Available providers: {TextSummarization.ServiceProvider.choices()}")
print(f"Selected provider: {service_provider}")

response = model.execute(text=input_text, service_provider=service_provider)

print(f"Summary = {response.summarization_data}")
File renamed without changes.
18 changes: 18 additions & 0 deletions examples/text_to_speech_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from slashml import TextToSpeech

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

# Find all the service providers that we support by running the choices() method
print(f"Available providers: {TextToSpeech.ServiceProvider.choices()}")
print(f"Selected provider: {service_provider}")

model = TextToSpeech(api_key=API_KEY)

# Submit request
job = model.execute(text=input_text, service_provider=service_provider)

print (f"\n\n\n You can access the audio file here: {job.audio_url}")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def read_req_file(req_type):

setup(
name="slashml",
version="0.0.5",
version="0.0.6",
url="https://slashml.com/",
author="eff-kay",
author_email="faiizan14@gmail.com",
Expand Down
28 changes: 27 additions & 1 deletion slashml/speech_to_text.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import time
from enum import Enum
from .utils import generateURL, baseUrl, generateHeaders, formatResponse, getTaskStatus

Expand All @@ -25,7 +26,7 @@ def upload_audio(self, file_location: str):
response = requests.post(url, headers=self._headers, files=files)
return formatResponse(response)

def transcribe(self, upload_url: str, service_provider: ServiceProvider):
def submit_job(self, upload_url: str, service_provider: ServiceProvider):
url = generateURL(self._base_url, "jobs")
payload = {
"uploaded_audio_url": upload_url,
Expand All @@ -36,3 +37,28 @@ def transcribe(self, upload_url: str, service_provider: ServiceProvider):

def status(self, job_id: str, service_provider: ServiceProvider):
return getTaskStatus(self._base_url, self._headers, job_id, service_provider)

def execute(self, upload_url: str, service_provider: ServiceProvider):
url = generateURL(self._base_url, "jobs")

payload = {
"uploaded_audio_url": upload_url,
"service_provider": service_provider.value,
}

response = requests.post(url, headers=self._headers, data=payload)
job = formatResponse(response)

assert job.status != "ERROR", f"{job}"
print(f"Got Job ID: {job.id}")

# check job status
response = getTaskStatus(self._base_url, self._headers, job.id, service_provider)

while response.status == "IN_PROGRESS":
time.sleep(5)
response = getTaskStatus(self._base_url, self._headers, job.id, service_provider)
print(f"Response = {response}. Retrying in 5 seconds")

return response

23 changes: 22 additions & 1 deletion slashml/text_summarization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import time
from enum import Enum
from .utils import generateURL, baseUrl, generateHeaders, formatResponse, getTaskStatus

Expand All @@ -17,11 +18,31 @@ def choices(cls):
def __init__(self, api_key: str = None):
self._headers = generateHeaders(api_key)

def summarize(self, text: str, service_provider: ServiceProvider):
def submit_job(self, text: str, service_provider: ServiceProvider):
url = generateURL(self._base_url, "jobs")
payload = {"text": [text], "service_provider": service_provider.value}
response = requests.post(url, headers=self._headers, data=payload)
return formatResponse(response)

def status(self, job_id: str, service_provider: ServiceProvider):
return getTaskStatus(self._base_url, self._headers, job_id, service_provider)

def execute(self, text: str, service_provider: ServiceProvider):
url = generateURL(self._base_url, "jobs")
payload = {"text": [text], "service_provider": service_provider.value}
response = requests.post(url, headers=self._headers, data=payload)
job = formatResponse(response)

assert job.status != "ERROR", f"{job}"
print(f"Got Job ID: {job.id}")

# check job status
response = getTaskStatus(self._base_url, self._headers, job.id, service_provider)

while response.status == "IN_PROGRESS":
time.sleep(5)
response = getTaskStatus(self._base_url, self._headers, job.id, service_provider)
print(f"Response = {response}. Retrying in 5 seconds")

return response

23 changes: 22 additions & 1 deletion slashml/text_to_speech.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import requests
import time

from enum import Enum
from .utils import generateURL, baseUrl, generateHeaders, formatResponse, getTaskStatus

Expand All @@ -18,11 +20,30 @@ def choices(cls):
def __init__(self, api_key: str = None):
self._headers = generateHeaders(api_key)

def speechify(self, text: str, service_provider: ServiceProvider):
def submit_job(self, text: str, service_provider: ServiceProvider):
url = generateURL(self._base_url, "jobs")
payload = {"text": text, "service_provider": service_provider.value}
response = requests.post(url, headers=self._headers, data=payload)
return formatResponse(response)

def status(self, job_id: str, service_provider: ServiceProvider):
return getTaskStatus(self._base_url, self._headers, job_id, service_provider)

def execute(self, text: str, service_provider: ServiceProvider):
url = generateURL(self._base_url, "jobs")
payload = {"text": text, "service_provider": service_provider.value}
response = requests.post(url, headers=self._headers, data=payload)
job = formatResponse(response)

assert job.status != "ERROR", f"{job}"
print(f"Got Job ID: {job.id}")

# check job status
response = getTaskStatus(self._base_url, self._headers, job.id, service_provider)

while response.status == "IN_PROGRESS":
time.sleep(5)
response = getTaskStatus(self._base_url, self._headers, job.id, service_provider)
print(f"Response = {response}. Retrying in 5 seconds")

return response