Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import youtube_dl
|
| 3 |
+
|
| 4 |
+
def download_subs_gradio(url, lang="en"):
|
| 5 |
+
opts = {
|
| 6 |
+
"skip_download": True,
|
| 7 |
+
"writesubtitles": "%(name)s.vtt",
|
| 8 |
+
"subtitlelangs": lang
|
| 9 |
+
}
|
| 10 |
+
try:
|
| 11 |
+
with youtube_dl.YoutubeDL(opts) as yt:
|
| 12 |
+
yt.download([url])
|
| 13 |
+
return "Subtitles downloaded successfully."
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"An error occurred: {e}"
|
| 16 |
+
|
| 17 |
+
interface = gr.Interface(
|
| 18 |
+
fn=download_subs_gradio,
|
| 19 |
+
inputs=["text", "text"],
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="YouTube Subtitle Downloader",
|
| 22 |
+
description="Enter a YouTube video URL and a subtitle language (e.g., 'en')."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
interface.launch()
|