diff --git a/openbb_terminal/forecast/whisper_view.py b/openbb_terminal/forecast/whisper_view.py index e623c6a8b06..5fd51cfbae9 100644 --- a/openbb_terminal/forecast/whisper_view.py +++ b/openbb_terminal/forecast/whisper_view.py @@ -15,6 +15,9 @@ from openbb_terminal.rich_config import console import warnings import os import whisper +from transformers import pipeline + + from openbb_terminal.forecast.whisper_utils import ( slugify, str2bool, @@ -39,6 +42,7 @@ def get_audio(urls): "verbose": True, "format": "bestaudio", "outtmpl": os.path.join(temp_dir, "%(id)s.%(ext)s"), + "external_downloader_args": ["-loglevel", "panic"], "postprocessors": [ { "preferredcodec": "mp3", @@ -72,6 +76,9 @@ def transcribe_and_summarize( output_dir: str = "/Users/martinbufi/OpenBBTerminal/openbb_terminal/forecast/whisper_output", ): + # Use the pipeline to summarize the text + summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") + console.print("Transcribing and summarizing...") print(f"video: {video}") if model_name.endswith(".en"): @@ -99,7 +106,18 @@ def transcribe_and_summarize( for segment in result["segments"]: all_text += segment["text"] - print(all_text) + original_text_length = len(all_text) + + summary = summarizer(all_text) + + summary_text = summary[0]["summary_text"] + summary_text_length = len(summary_text) + percent_reduction = round( + (1 - (summary_text_length / original_text_length)) * 100, 2 + ) + + print(f"Summary (reduction {percent_reduction})") + print(summary_text) if subtitles_format == "vtt": vtt_path = os.path.join(output_dir, f"{slugify(title)}.vtt")