Download transcript.py from Sukhmanpreet/Voice_Transformation_Technology: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/Sukhmanpreet/Voice_Transformation_Technology/resolve/main/transcript.py
- Command line
-
hf download hf://spaces/Sukhmanpreet/Voice_Transformation_Technology/transcript.py
-
curl -L -o transcript.py https://huggingface.co/spaces/Sukhmanpreet/Voice_Transformation_Technology/resolve/main/transcript.py
1.49 kB
| from deepgram import ( | |
| DeepgramClient, | |
| PrerecordedOptions, | |
| FileSource | |
| ) | |
| import httpx | |
| from sumy.parsers.plaintext import PlaintextParser | |
| from sumy.nlp.tokenizers import Tokenizer | |
| from sumy.summarizers.lsa import LsaSummarizer | |
| def deepgram(buffer_data,language): | |
| # STEP 1 Create a Deepgram client using the API key | |
| deepgram = DeepgramClient('5da1cbb9a0b27337e1ae7dc141b48c6775912ed2') | |
| payload: FileSource = { | |
| "buffer": buffer_data, | |
| } | |
| #STEP 2: Configure Deepgram options for audio analysis | |
| options = PrerecordedOptions( | |
| model="nova-2", | |
| smart_format=True, | |
| language=language, | |
| diarize=True | |
| ) | |
| myTimeout = httpx.Timeout(300, connect=10.0) | |
| # STEP 3: Call the transcribe_file method with the text payload and options | |
| response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options,timeout=myTimeout) | |
| text=response['results']['channels'][0]['alternatives'][0]['paragraphs']['transcript'] | |
| return text | |
| def summarize_text(text): | |
| # Initialize parser | |
| parser = PlaintextParser.from_string(text, Tokenizer("english")) | |
| # Initialize LSA Summarizer | |
| summarizer = LsaSummarizer() | |
| # Summarize the document with 3 sentences | |
| summary = summarizer(parser.document, 3) | |
| # Convert summary sentences to string | |
| summary_text = " ".join([str(sentence) for sentence in summary]) | |
| return summary_text |