from youtube_transcript_api import YouTubeTranscriptApi from youtube_transcript_api.formatters import TextFormatter from transformers import pipeline import re import gradio pipe = pipeline("summarization", model="Falconsai/text_summarization") def summary(text_transcript): output = pipe(text_transcript) return output[0]['summary_text'] def get_youtube_transcript(link): video_id= extract_youtube_id(link) if not video_id: return "Video ID could not be extracted" try: transcript= YouTubeTranscriptApi.get_transcript(video_id) # fetches the trancript formatter= TextFormatter() text_transcript = formatter.format_transcript(transcript) # This will format the transcript summarized_text = summary(text_transcript) return summarized_text except Exception as e: return f"An error has occured: {e}"