Spaces:
Sleeping
Sleeping
Rivalcoder
commited on
Commit
·
0df7414
1
Parent(s):
caa912d
[Edit]
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ ytt_api = YouTubeTranscriptApi(
|
|
| 13 |
# Function to fetch and format YouTube transcript using the video ID
|
| 14 |
def fetch_transcript(video_id: str):
|
| 15 |
try:
|
|
|
|
| 16 |
transcript_obj = ytt_api.fetch(video_id)
|
| 17 |
# Extract and join only the text fields from FetchedTranscriptSnippet objects
|
| 18 |
full_text = " ".join([snippet.text for snippet in transcript_obj.snippets])
|
|
@@ -20,14 +21,14 @@ def fetch_transcript(video_id: str):
|
|
| 20 |
except Exception as e:
|
| 21 |
return f"Error fetching transcript: {str(e)}"
|
| 22 |
|
| 23 |
-
|
|
|
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=fetch_transcript,
|
| 26 |
inputs=gr.Textbox(label="Enter YouTube Video ID"),
|
| 27 |
outputs=gr.Textbox(label="Transcript"),
|
| 28 |
-
live=
|
| 29 |
-
api=True # This flag turns the interface into an API
|
| 30 |
)
|
| 31 |
|
| 32 |
-
# Launch the Gradio app
|
| 33 |
-
iface.launch(
|
|
|
|
| 13 |
# Function to fetch and format YouTube transcript using the video ID
|
| 14 |
def fetch_transcript(video_id: str):
|
| 15 |
try:
|
| 16 |
+
# Fetch transcript
|
| 17 |
transcript_obj = ytt_api.fetch(video_id)
|
| 18 |
# Extract and join only the text fields from FetchedTranscriptSnippet objects
|
| 19 |
full_text = " ".join([snippet.text for snippet in transcript_obj.snippets])
|
|
|
|
| 21 |
except Exception as e:
|
| 22 |
return f"Error fetching transcript: {str(e)}"
|
| 23 |
|
| 24 |
+
|
| 25 |
+
# Gradio Interface
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=fetch_transcript,
|
| 28 |
inputs=gr.Textbox(label="Enter YouTube Video ID"),
|
| 29 |
outputs=gr.Textbox(label="Transcript"),
|
| 30 |
+
live=True
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
+
# Launch the Gradio app
|
| 34 |
+
iface.launch()
|