import gradio as gr import yt_dlp def download_audio(url): ydl_opts = { 'format': 'm4a/bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', }] } with yt_dlp.YoutubeDL(ydl_opts) as ydl: info_dict = ydl.extract_info(url, download=True) video_url = info_dict['url'] return video_url iface = gr.Interface(fn=download_audio, inputs=gr.Textbox(label="YouTube Video URL"), outputs=gr.Audio(label="Output Audio", type="filepath"), allow_flagging="never" ) iface.launch()