import whisper from pytube import YouTube from transformers import pipeline import gradio as gr import os import re model = whisper.load_model("base") # model = pipeline(model="AlexMo/FIFA_WC22_WINNER_LANGUAGE_MODEL") summarizer = pipeline("summarization") def getAudio(url): link = YouTube(url) video = link.streams.filter(only_audio=True).first() file = video.download(output_path=".") base, ext = os.path.splitext(file) file_ext = base + '.mp3' os.rename(file, file_ext) return file_ext def getText(url): if url != '': output_text_transcribe = '' res = model.transcribe(getAudio(url)) return res['text'].strip() def getSummary(article): header = ' '.join(re.split(r'(?<=[.:;])\s', article)[:5]) b = summarizer(header, min_length=15, max_length=120, do_sample=False) b = b[0]['summary_text'].replace(' .', '.').strip() return b with gr.Blocks() as demo: gr.Markdown( "

Free Fast YouTube URL Video to Text using OpenAI's Whisper Model

") gr.Markdown( "
Enter the link of any YouTube video to generate a text transcript of the video and then create a summary of the video transcript.
") gr.Markdown( "
'Whisper is a neural net that approaches human level robustness and accuracy on English speech recognition.'
") gr.Markdown( "
Generating the transcript takes 5-10 seconds per minute of the video
") input_text_url = gr.Textbox(placeholder='Youtube video URL', label='URL') result_button_transcribe = gr.Button('1. Transcribe') output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript') result_button_summary = gr.Button('2. Create Summary') output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary') result_button_transcribe.click(getText, inputs=input_text_url, outputs=output_text_transcribe) result_button_summary.click(getSummary, inputs=output_text_transcribe, outputs=output_text_summary) demo.launch(debug=True)