import whisper
from pytubefix import YouTube
from pytubefix.cli import on_progress
from transformers import pipeline
import gradio as gr
import os
model = whisper.load_model("base")
summarizer = pipeline("summarization")
def get_audio(url):
yt = YouTube(url, on_progress_callback=on_progress)
audio_stream = yt.streams.get_audio_only()
out_file = audio_stream.download(mp3=True) # This will directly download as mp3
return out_file # Returns the path to the mp3 file
def get_text(url):
result = model.transcribe(get_audio(url))
return result['text']
def get_summary(url):
article = get_text(url)
b = summarizer(article)
b = b[0]['summary_text']
return b
with gr.Blocks() as demo:
gr.Markdown("
Youtube video transcription with OpenAI's Whisper
")
gr.Markdown("Enter the link of any youtube video to get the transcription of the video and a summary of the video in the form of text.")
gr.Markdown("Update: This app is using the pytubefix library to fetch audio of the youtube URL. Currently YouTube is blocking the requests. So you will see the app showing error. Check this app on [Colab Notebook](https://colab.research.google.com/drive/1CTRog4BQJqeY8_-5sxAYzmc0c9z4xV6z?usp=sharing).")
with gr.Tab('Get the transcription of any Youtube video'):
with gr.Row():
input_text_1 = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
output_text_1 = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
result_button_1 = gr.Button('Get Transcription')
with gr.Tab('Summary of Youtube video'):
with gr.Row():
input_text = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
output_text = gr.Textbox(placeholder='Summary text of the Youtube Video', label='Summary')
result_button = gr.Button('Get Summary')
result_button.click(get_summary, inputs = input_text, outputs = output_text)
result_button_1.click(get_text, inputs = input_text_1, outputs = output_text_1)
demo.launch(debug=True)