Spaces:
Running
Running
Rivalcoder
commited on
Commit
·
5b9992a
1
Parent(s):
c6f2536
[Edit]
Browse files- app.py +14 -29
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,34 +1,19 @@
|
|
1 |
-
import yt_dlp
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
def
|
5 |
-
ydl_opts = {
|
6 |
-
'skip_download': True,
|
7 |
-
'writesubtitles': True,
|
8 |
-
'subtitleslangs': [lang],
|
9 |
-
'writeautomaticsub': True,
|
10 |
-
'quiet': True,
|
11 |
-
'forcejson': True
|
12 |
-
}
|
13 |
-
|
14 |
try:
|
15 |
-
|
16 |
-
|
17 |
-
subtitles = info.get('subtitles') or info.get('automatic_captions')
|
18 |
-
if subtitles and lang in subtitles:
|
19 |
-
subtitle_url = subtitles[lang][0]['url']
|
20 |
-
return f"✅ Captions Found:\n{subtitle_url}"
|
21 |
-
return "⚠️ No captions found for this language."
|
22 |
except Exception as e:
|
23 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
fn=get_captions,
|
27 |
-
inputs=[
|
28 |
-
gr.Textbox(label="YouTube Video URL"),
|
29 |
-
gr.Textbox(value="en", label="Language Code (e.g., en, es, fr)")
|
30 |
-
],
|
31 |
-
outputs="text",
|
32 |
-
title="YouTube Caption Extractor",
|
33 |
-
description="Paste a YouTube video URL and get the direct link to the captions (auto or uploaded)."
|
34 |
-
).launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
3 |
|
4 |
+
def fetch_transcript(video_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
try:
|
6 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
7 |
+
return '\n'.join([f"{entry['text']}" for entry in transcript])
|
|
|
|
|
|
|
|
|
|
|
8 |
except Exception as e:
|
9 |
+
return f"Error: {str(e)}"
|
10 |
+
|
11 |
+
iface = gr.Interface(
|
12 |
+
fn=fetch_transcript,
|
13 |
+
inputs=gr.Textbox(label="YouTube Video ID"),
|
14 |
+
outputs=gr.Textbox(label="Transcript"),
|
15 |
+
title="YouTube Transcript Fetcher",
|
16 |
+
description="Enter a YouTube video ID to fetch its transcript."
|
17 |
+
)
|
18 |
|
19 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
gradio
|
2 |
-
|
|
|
1 |
gradio
|
2 |
+
youtube_transcript_api
|