import gradio as gr import yt_dlp as youtube_dl def download_youtube_video(youtube_url): """Downloads a YouTube video using yt_dlp and returns the downloaded file path.""" try: ydl_opts = { 'format': 'best', 'outtmpl': '%(title)s.%(ext)s', } with youtube_dl.YoutubeDL(ydl_opts) as ydl: result = ydl.extract_info(youtube_url, download=True) video_title = result.get('title', None) video_ext = result.get('ext', None) downloaded_file = f"{video_title}.{video_ext}" return downloaded_file except Exception as e: print("An error occurred:", e) return None def app(video_link): video_path = download_youtube_video(video_link) return video_path interface = gr.Interface( fn=app, inputs=gr.Textbox(label="Enter YouTube link 🔗 To Download Video⬇️ "), outputs=gr.Textbox(label="Downloaded Video Path") ) if __name__ == "__main__": interface.launch(debug=True)