Spaces:
Running
Running
Rivalcoder
commited on
Commit
·
49c84c9
1
Parent(s):
ab498f8
[Edit]
Browse files
app.py
CHANGED
@@ -13,7 +13,6 @@ 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 |
-
# 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,14 +20,14 @@ def fetch_transcript(video_id: str):
|
|
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=
|
|
|
31 |
)
|
32 |
|
33 |
-
# Launch the Gradio app
|
34 |
-
iface.launch()
|
|
|
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 |
except Exception as e:
|
21 |
return f"Error fetching transcript: {str(e)}"
|
22 |
|
23 |
+
# Gradio Interface for API (no UI)
|
|
|
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=False,
|
29 |
+
api=True # This flag turns the interface into an API
|
30 |
)
|
31 |
|
32 |
+
# Launch the Gradio app in API mode
|
33 |
+
iface.launch(share=True) # share=True allows external access to the API
|