pierreguillou commited on
Commit
77f0587
1 Parent(s): d0b9711

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import yt_dlp
3
+
4
+ def download_audio(url):
5
+ ydl_opts = {
6
+ 'format': 'm4a/bestaudio/best',
7
+ 'postprocessors': [{
8
+ 'key': 'FFmpegExtractAudio',
9
+ 'preferredcodec': 'mp3',
10
+ }]
11
+ }
12
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
13
+ info_dict = ydl.extract_info(url, download=True)
14
+ video_url = info_dict['url']
15
+ return video_url
16
+
17
+ iface = gr.Interface(fn=download_audio,
18
+ inputs=gr.Textbox(label="YouTube Video URL"),
19
+ outputs=gr.Audio(label="Output Audio", type="filepath"),
20
+ allow_flagging="never"
21
+ )
22
+ iface.launch()