Spaces:
Sleeping
Sleeping
add script for YoutubeTranscriptTool
Browse files- youtube_transcript_tool.py +24 -0
youtube_transcript_tool.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import Tool
|
| 2 |
+
|
| 3 |
+
class YoutubeTranscriptTool(Tool):
|
| 4 |
+
name = "YouTubeTransciptTool"
|
| 5 |
+
description = "This tool extracts transcripts from YouTube videos."
|
| 6 |
+
|
| 7 |
+
inputs = {
|
| 8 |
+
"url": {
|
| 9 |
+
"type": "string",
|
| 10 |
+
"description": "the URL for the YouTube video, like https://www.youtube.com/watch?v=1htKBjuUWec",
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
output_type = "string"
|
| 15 |
+
|
| 16 |
+
def forward(self, url: str) -> str:
|
| 17 |
+
"""
|
| 18 |
+
Extracts the transcript from the YouTube video.
|
| 19 |
+
|
| 20 |
+
https://python.langchain.com/docs/integrations/document_loaders/youtube_transcript/
|
| 21 |
+
"""
|
| 22 |
+
loader = YoutubeLoader.from_youtube_url(url, add_video_info=False)
|
| 23 |
+
document = loader.load()
|
| 24 |
+
return document[0].page_content
|