Spaces:
Sleeping
Sleeping
File size: 1,124 Bytes
a08fec1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import os
from smolagents import Tool
from supadata import Supadata
class SupadataTool(Tool):
name = "supadata_tool"
description = "Get the YouTube video URL and generate transcription describing the video content. If you need to know what the video is about, use this tool."
inputs = {
"url": {
"type": "string",
"description": "Full YouTube video URL",
}
}
output_type = "string"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.supadata = Supadata(api_key=os.getenv("SUPADATA_API_KEY"))
def forward(self, url):
video_id = self._extract_video_id(url)
transcript = self.supadata.youtube.transcript(video_id=video_id, lang="en")
return transcript.content
@staticmethod
def _extract_video_id(url):
if not url.startswith('https://'):
return url
if 'youtube.com/watch?v=' in url:
return url.split('watch?v=')[1].split('&')[0]
elif 'youtu.be/' in url:
return url.split('youtu.be/')[1].split('?')[0]
return url
|