Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from pytube import YouTube
|
| 3 |
+
|
| 4 |
+
def get_youtube_transcript(video_url):
|
| 5 |
+
try:
|
| 6 |
+
yt = YouTube(video_url)
|
| 7 |
+
caption = yt.captions.get_by_language_code('en') # You can adjust the language code
|
| 8 |
+
if caption:
|
| 9 |
+
transcript = caption.generate_srt_captions() # Or .generate_vtt_captions() for VTT format
|
| 10 |
+
return transcript
|
| 11 |
+
else:
|
| 12 |
+
return "No English transcript found for this video."
|
| 13 |
+
except Exception as e:
|
| 14 |
+
return f"An error occurred: {e}"
|
| 15 |
+
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=get_youtube_transcript,
|
| 18 |
+
inputs=gr.Textbox(label="Enter YouTube Video URL"),
|
| 19 |
+
outputs=gr.Textbox(label="YouTube Transcript"),
|
| 20 |
+
title="YouTube Transcript Extractor",
|
| 21 |
+
description="Paste a YouTube video link to get its transcript."
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
iface.launch()
|