import yt_dlp import os import gradio as gr from transformers import pipeline import whisper def get_audio(url): try: # Configure yt-dlp options ydl_opts = { 'format': 'bestaudio/best', # Choose best quality audio 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192', }], 'outtmpl': 'audio_download.%(ext)s', # Output template 'quiet': True, # Less output 'no_warnings': True # No warnings } # Download the audio with yt_dlp.YoutubeDL(ydl_opts) as ydl: ydl.download([url]) return 'audio_download.mp3' # Return the filename except Exception as e: raise gr.Error(f"Error downloading audio: {str(e)}") # Load models model = whisper.load_model("base") summarizer = pipeline("summarization") def get_text(url): try: audio_file = get_audio(url) result = model.transcribe(audio_file) # Cleanup try: os.remove(audio_file) except: pass return result['text'] except Exception as e: return f"Error: {str(e)}" def get_summary(url): try: article = get_text(url) summary = summarizer(article) return summary[0]['summary_text'] except Exception as e: return f"Error: {str(e)}" # Create Gradio interface with gr.Blocks() as demo: gr.Markdown("