from transformers import pipeline from youtube_transcript_api import YouTubeTranscriptApi import gradio as gr def summarize(Youtube_Video_Link): video_id = Youtube_Video_Link.split("=")[1] try: transcript = YouTubeTranscriptApi.get_transcript(video_id) summarizer = pipeline('summarization',model='sshleifer/distilbart-cnn-12-6') input_text = "" for i in transcript: input_text += ' ' + i['text'] num_iters = int(len(input_text)/1000) summarized_text = [] for i in range(0, num_iters + 1): start = 0 start = i * 1000 end = (i + 1) * 1000 print("input text \n" + input_text[start:end]) out = summarizer(input_text[start:end]) out = out[0] out = out['summary_text'] print("Summarized text\n"+out) summarized_text.append(out) output_text=' '.join(summarized_text) return output_text except: return "Some Error has occurred either with Video link passed is invalid or No Captions present for this video" title = "YouTube Live 😎 Video Summarization" examples = [("https://www.youtube.com/watch?v=zKvd1JwJ4Po"),("https://www.youtube.com/watch?v=9izcbNYmP8M"),] text1 = ( "