video-to-audio / app.py
pierreguillou's picture
Create app.py
77f0587
raw
history blame
668 Bytes
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()