shubham7080 commited on
Commit
3548a91
·
verified ·
1 Parent(s): 616cc02

Create youtube_transcription_tool.py

Browse files
Files changed (1) hide show
  1. tools/youtube_transcription_tool.py +24 -0
tools/youtube_transcription_tool.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import Tool
2
+ from youtube_transcript_api import YouTubeTranscriptApi
3
+
4
+
5
+ class YouTubeTranscriptionTool(Tool):
6
+ """
7
+ Tool to fetch the transcript of a YouTube video given its URL.
8
+ Args:
9
+ video_url (str): YouTube video URL.
10
+ Returns:
11
+ str: Transcript of the video as a single string.
12
+ """
13
+
14
+ name = "youtube_transcription"
15
+ description = "Fetches the transcript of a YouTube video given its URL"
16
+ inputs = {
17
+ "video_url": {"type": "string", "description": "YouTube video URL"},
18
+ }
19
+ output_type = "string"
20
+
21
+ def forward(self, video_url: str) -> str:
22
+ video_id = video_url.strip().split("v=")[-1]
23
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
24
+ return " ".join([entry["text"] for entry in transcript])