import whisper from pytube import YouTube 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) video = yt.streams.filter(only_audio=True).first() out_file = video.download(output_path=".") base, ext = os.path.splitext(out_file) new_file = base + '.mp3' os.rename(out_file, new_file) return new_file def get_text_from_url(url): result = model.transcribe(get_audio(url)) return result['text'] def get_text_from_file(file): # Assuming the uploaded file is already in MP3 format result = model.transcribe(file.name) return result['text'] def get_summary_from_url(url): article = get_text_from_url(url) b = summarizer(article) return b[0]['summary_text'] def get_summary_from_file(file): article = get_text_from_file(file) b = summarizer(article) return b[0]['summary_text'] def process_url(url): transcription = get_text_from_url(url) summary = get_summary_from_url(url) return summary, transcription def process_file(file): transcription = get_text_from_file(file) summary = get_summary_from_file(file) return summary, transcription with gr.Blocks() as demo: gr.Markdown("