File size: 668 Bytes
77f0587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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()