-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 develop transcription translation summarisation pipeline #7
Merged
J-Dymond
merged 13 commits into
main
from
1-develop-transcription-translation-summarisation-pipeline
Sep 27, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4e41b11
:hot_pepper::notebook: first notebook exploration for TTS pipeline
eddableheath 51740fb
:hot_pepper::notebook: updated TTS pipeline notebook
eddableheath 6fc4538
:hot_pepper::alembic: got building blocks of TTS pipeline working
eddableheath 50a4e8f
:hot_pepper::notebook: refactored individual steps of the TTS pipelin…
eddableheath c6608d9
:hot_pepper::notebook: refactored individual steps of the TTS pipelin…
eddableheath 57d8282
:hot_pepper::notebook: added TTS pipeline class to notebook
eddableheath f2d74a5
:hot_pepper::sparkles: pulled out TSS pipeline from notebook into src
eddableheath 8348bf9
:hot_pepper: added script with example use of TTS pipeline
eddableheath 271c0f8
:hot_pepper::bricks: updated pyproject.toml
eddableheath ff906ca
:hot_pepper::bricks: updated pyproject.toml
eddableheath 1d8cdd9
:hot_pepper: various small changs
eddableheath 67c7b7a
:hot_pepper: final commit for this branch I think
eddableheath 2b5f2c5
Merge branch 'main' into 1-develop-transcription-translation-summaris…
J-Dymond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
An example use of the transcription, translation and summarisation pipeline. | ||
""" | ||
|
||
import numpy as np | ||
from datasets import Audio, load_dataset | ||
|
||
from arc_spice.pipelines.TTS_pipeline import TTSpipeline | ||
|
||
|
||
def main(TTS_params): | ||
"""main function""" | ||
TTS = TTSpipeline(TTS_params) | ||
TTS.print_pipeline() | ||
ds = load_dataset( | ||
"facebook/multilingual_librispeech", "french", split="test", streaming=True | ||
) | ||
ds = ds.cast_column("audio", Audio(sampling_rate=16_000)) | ||
input_speech = next(iter(ds))["audio"] | ||
# arrays = [] | ||
# n = 5 | ||
# for idx, data in enumerate(iter(ds)): | ||
# arrays.append(data["audio"]["array"]) | ||
# if idx == n: | ||
# break | ||
# arrays = np.concatenate(arrays) | ||
TTS.run_pipeline(input_speech["array"]) | ||
TTS.print_results() | ||
|
||
|
||
if __name__ == "__main__": | ||
TTS_pars = { | ||
"transcriber": { | ||
"specific_task": "automatic-speech-recognition", | ||
"model": "openai/whisper-small", | ||
}, | ||
"translator": { | ||
"specific_task": "translation_fr_to_en", | ||
"model": "facebook/mbart-large-50-many-to-many-mmt", | ||
}, | ||
"summariser": { | ||
"specific_task": "summarization", | ||
"model": "facebook/bart-large-cnn", | ||
}, | ||
} | ||
main(TTS_params=TTS_pars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
Class for the transcription, translation and summarisation pipeline. | ||
""" | ||
|
||
from transformers import pipeline | ||
|
||
|
||
class TTSpipeline: | ||
""" | ||
Class for the transcription, translation, summarisation pipeline. | ||
|
||
pars: | ||
- {'top_level_task': {'specific_task': str, 'model_name': str}} | ||
""" | ||
|
||
def __init__(self, pars) -> None: | ||
self.pars = pars | ||
self.transcriber = pipeline( | ||
pars["transcriber"]["specific_task"], pars["transcriber"]["model"] | ||
) | ||
self.translator = pipeline( | ||
pars["translator"]["specific_task"], pars["translator"]["model"] | ||
) | ||
self.summariser = pipeline( | ||
pars["summariser"]["specific_task"], pars["summariser"]["model"] | ||
) | ||
self.results = {} | ||
|
||
def print_pipeline(self): | ||
"""Print the models in the pipeline""" | ||
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") | ||
print(f"Transcriber model: {self.pars['transcriber']['model']}") | ||
print(f"Translator model: {self.pars['translator']['model']}") | ||
print(f"Summariser model: {self.pars['summariser']['model']}") | ||
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") | ||
|
||
def run_pipeline(self, x): | ||
"""Run the pipeline on an input x""" | ||
transcription = self.transcriber(x) | ||
self.results["transcription"] = transcription["text"] | ||
translation = self.translator(transcription["text"]) | ||
self.results["translation"] = translation[0]["translation_text"] | ||
summarisation = self.summariser(translation[0]["translation_text"]) | ||
self.results["summarisation"] = summarisation[0]["summary_text"] | ||
|
||
def print_results(self): | ||
"""Print the results for quick scanning""" | ||
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") | ||
for key, val in self.results.items(): | ||
print("-------------") | ||
print(f"{key} result is: \n {val}") | ||
print("-------------") | ||
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is "specific_task" here the task as its named in the huggingface API?