Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Binary file removed .DS_Store
Binary file not shown.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 SlashML

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
75 changes: 73 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,74 @@
# slashml-python-client
# SLASHML Python client

to be updated to guide users
This is a Python client for SLASHML. It lets you run transcription jobs from your Python code or Jupyter notebook. Do a transcription job with three lines of code
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add url for slashml

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The readme should be generic, so it doesn't run transcrption jobs. It runs machine learning jobs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you can give an example of how to do transcription as an example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

```
import speechtotext

speect_to_text = speechtotext.SpeechToText()
transcribe_id= speect_to_text.transcribe(audio_url,service_provider="aws")
status=speect_to_text.status(transcribe_id,service_provider=service_provider)

```
There is a daily limit (throttling) on the number of calls the user performs, transcription jobs can be done without specifying a token (API key). If the user intends on using the service more frequently, it is recommended to generate an token or API key from the dashboard @ [Slashml.com](https://www.slashml.com/).

Grab your token from [https://www.slashml.com/dashboard] (>settings> new api key) and authenticate by setting it as an environment variable (or when you initialize the service, see examples):
```
export SLASHML_API_KEY=[token]
```
or including it in your code as follows:
```
import speechtotext
API_KEY="your_api_key"
speect_to_text = speechtotext.SpeechToText(API_KEY)
transcribe_id= speect_to_text.transcribe(audio_url,service_provider="aws")
status=speect_to_text.status(transcribe_id,service_provider=service_provider)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will not work, you need to wait for the status to turn to COMPLETED.


```

-- update from this part, include examples, sign up, token, service providers, type of servies, benchmarking, link to pricing, Tutorial examples/examples


SDK for SlashML documentation:
- methods: upload_audio, transcribe, status

Steps to Integrate
1 - (Optional) Upload files where the data points to your audio file
```
# call the class
speect_to_text = speechtotext.SpeechToText()
file_location="path/to/your/file.mp3"
# when
API_KEY="SLASH_ML_API_KEY"
model_choice="assembly"
result_upload = speect_to_text.upload_audio(file_location,API_KEY, model_choice)
print(result_upload)
```
Save the upload_url. You can use this url link in the rest of the calls.


2- Submit your audio file for transcription
```
upload_url=upload_url # you can skip step 1 and just input the accessible link of your # file)

result_transcribe = speect_to_text.transcribe(upload_url,API_KEY, model_choice)

print(result_transcribe)
```
Save the id in the response object.


3 - Check the status and get the text result of the transcription
```
job_id= id
result_status = speect_to_text.status(job_id,API_KEY, model_choice=model_choice)

### get the full details of the result
print(result_status)
### get the text reulst only
print(json.loads(result)["text"])
```


et voilà, Next steps:
- pip install slashml
- add SLASH_API_KEY to sys path
Binary file removed SDK_v1/.DS_Store
Binary file not shown.
Binary file removed SDK_v1/__pycache__/speechtotext.cpython-310.pyc
Binary file not shown.
44 changes: 0 additions & 44 deletions SDK_v1/readme.md

This file was deleted.

58 changes: 0 additions & 58 deletions SDK_v1/speechtotext.py

This file was deleted.

51 changes: 0 additions & 51 deletions SDK_v1/test_speechtotext.py

This file was deleted.

21 changes: 21 additions & 0 deletions src/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only license we need should be at the root, so remove all the licenses inside the folders.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to push the chnages, the license at src/LICENSE.txt still exists in this PR, we wan't to remove it.


Copyright (c) 2022 SlashML

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.28.1
85 changes: 85 additions & 0 deletions src/slashml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import requests
import os
from pathlib import Path
import json

class SpeechToText:

SLASHML_BASE_URL = 'https://api.slashml.com/speech-to-text/v1'
SLASHML_UPLOAD_URL = SLASHML_BASE_URL+'/upload/'
SLASHML_TRANSCRIPT_URL = SLASHML_BASE_URL+'/transcribe/'
SLASHML_STATUS_URL = SLASHML_BASE_URL+'/transcription'
SLASHML_TRANSCRIPT_STATUS_URL = lambda self,id: f"{SpeechToText.SLASHML_STATUS_URL}/{id}/"

HEADERS:dict = {}
## add the api key to sys path envs
def __init__(self,API_KEY: str = None):
self.API_KEY=None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.API_KEY is not used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change is not pushed

if API_KEY:
token="Token {0}".format(API_KEY)
self.HEADERS = {'authorization': token}
# print("Auth with "+API_KEY+"\nMake sure this matches your API Key generated in the dashboard settings")
elif os.environ.get('SLASHML_API_KEY'):
key_env = os.environ.get('SLASHML_API_KEY')
token="Token {0}".format(key_env)
self.HEADERS = {'authorization': token}
# print("Auth with environment variable SLASHML_API_KEY")
else:
self.HEADERS=None
print("No Auth, there are certain limites to the usage")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No API key provided, there are limits to the usage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


def upload_audio(self, file_location:str,header=None):
headers = self.HEADERS
files=[
('audio',('test_audio.mp3',open(file_location,'rb'),'audio/mpeg'))
]
response = requests.post(self.SLASHML_UPLOAD_URL,
headers=headers,files=files)
return response.json()["upload_url"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a possibility that you receive 400 or 500 when uploading the file. When that happens the response.json() might not contain upload_url.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added conditions on this, if the response is success get the upload URL.


def transcribe(self,upload_url:str, service_provider: str,header=None ):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the output of transcription?


transcript_request = {'audio_url': upload_url}
headers = self.HEADERS
payload = {
"uploaded_audio_url": upload_url,
"service_provider": service_provider
}
response = requests.post(self.SLASHML_TRANSCRIPT_URL, headers=headers, data=payload)
# Check the status code of the response
if response.status_code == 200:
return response.json()["id"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is correct, but are you sure you just want to return the ID from transcribe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now yes,


elif response.status_code == 429:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't check for all invidual error codes. Just pass the error to the user as a reponse. Also you want to pass the error msg.

return "THROTTLED"

elif response.status_code == 404:
return "NOT FOUND"

elif response.status_code == 500:
return "SERVER ERROR"
else:
return "UNKNOWN ERROR"

def status(self,job_id:str, service_provider: str ,header=None):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the output of status?

headers = self.HEADERS
payload = {
"service_provider": service_provider
}

response = requests.get(self.SLASHML_TRANSCRIPT_STATUS_URL(job_id) , headers=headers, data=payload)

# Check the status code of the response
if response.status_code == 200:
return response.json()["transcription_data"]["transcription"]

elif response.status_code == 429:
return "THROTTLED"

elif response.status_code == 404:
return "NOT FOUND"

elif response.status_code == 500:
return "SERVER ERROR"
else:
return "UNKNOWN ERROR"
21 changes: 21 additions & 0 deletions src/test_speechtotext_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import slashml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this file, or convert it into tests

import os

#API KEY (optional)

# set environment path
os.environ["SLASHML_API_KEY"] = "0d91bfede9c5c9de6ff1d5610ef71c3b6d5be9ee"
# Initialize SlashML
speect_to_text = slashml.SpeechToText()
# optional local file to upload, if not an accessible url
file_location="/Users/JJneid/Desktop/SlashMl/Benchmarking/podcast1/podcast1_long_trim.mp3"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this location is specific to your computer.

# If your audio files aren't accessible via a URL already, you can upload your audio file using this API
upload_url= speect_to_text.upload_audio(file_location)
# choose your service provider: "asembly", "aws", "whisper"
service_provider="aws"
# transcribe
transcribe_id= speect_to_text.transcribe(upload_url,service_provider)
print(transcribe_id)

status=speect_to_text.status(transcribe_id,service_provider=service_provider)
print(status)