-
Notifications
You must be signed in to change notification settings - Fork 1
Speechtext #15
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
Speechtext #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,66 @@ | ||||||
| # slashml-python-client | ||||||
| # SlashML Python client | ||||||
| [SlashML](https://www.slashml.com/) | ||||||
| # Introduction | ||||||
| ## Overview | ||||||
| This is a Python client (SDK) for SlashML. It allows the user to use the apps available and active in [SlashML-Dashboard](https://www.slashml.com/dashboard). | ||||||
| The apps can be together in the same code. For example, if the user wants to transcribe an audio file and get a summary, they can call speechtotext followed by summarization. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| to be updated to guide users | ||||||
| State-of-the-art AI models from several service providers are available. At SlashML, we also do the benchmarking on these models for the user. This will give them an idea of the best service provider for their application. For the full list of the available models thru SlashML, click [here](##availlable-service-providers) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thru?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will give who an idea for the best service provider. The user is reading the email. Write in third person, not second person. |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| to lets you run transcription jobs from your Python code or Jupyter notebook. The transcription can be done with three lines of code | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capitalize
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first line of this paragraph does not make sense. |
||||||
| ``` | ||||||
| import slashml | ||||||
| speect_to_text = slashml.SpeechToText() | ||||||
| transcribe_id= speect_to_text.transcribe(audio_url,service_provider="aws") | ||||||
| status=speect_to_text.status(transcribe_id,service_provider=service_provider) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
| ``` | ||||||
|
|
||||||
| ## Set up and usage | ||||||
| There is a daily limit (throttling) on the number of calls the user performs, the code runs without specifying a token (API key), the throttling kicks in and prevents new jobs after exceeding 10 calls per minute. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| If the user intends on using the service more frequently, it is recommended to generate an token or API key from [SlashML-Dashboard](https://www.slashml.com/dashboard). This way, the throttling limit will increase. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
|
||||||
| Sign up and Grab your token from [SlashML-Dashboard](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 Quickstart tutorial): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be a new subsection. Also, reword this |
||||||
|
|
||||||
| In your terminal | ||||||
| ``` | ||||||
| export SLASHML_API_KEY=[token] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this only works for macs and unix, will not work in windows. Specify how to set it in the terminal in different OSes. |
||||||
| ``` | ||||||
| or including it in your python code as follows: | ||||||
| ``` | ||||||
| import os | ||||||
| os.environ["SLASHML_API_KEY"] = "slashml_api_token" | ||||||
| ``` | ||||||
|
|
||||||
| If the user preferes using the API calls directly, the documentation is available [here](https://www.slashml.com/dashboard). | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one seems a sudden jump, in thought Should be a separate section. |
||||||
| ## Availlable service providers | ||||||
|
|
||||||
| ### Speech-to-text | ||||||
|
|
||||||
| AssemblyAI | ||||||
| AWS | ||||||
| Whisper (OpenAI) | ||||||
|
|
||||||
| ### Summarization | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove summarization from this PR. |
||||||
| hugging-face summarization based on Meta... include links | ||||||
| # Quickstart tutorial | ||||||
|
|
||||||
| ## Introduction | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation is not finalized, remove the extra contents. |
||||||
|
|
||||||
| ### Start with initializing the service | ||||||
|
|
||||||
| ### Specify your service provider | ||||||
|
|
||||||
| In this step, benchmarking will help you decide which service provider is the best for you. | ||||||
| For speech-to-text: "assembly", "aws", "whisper" | ||||||
| For summarization: "hugging-face", "openai" | ||||||
|
|
||||||
|
|
||||||
| et voilà, Next steps: | ||||||
| - pip install slashml | ||||||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you have to push the chnages, the license at |
||
|
|
||
| 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. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| requests==2.28.1 |
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No API key provided, there are limits to the usage.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for now yes, |
||
|
|
||
| elif response.status_code == 429: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import slashml | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| import os | ||
| 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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: "assembly", "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) | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
we call them endpoints or services, not apps.