Download tool.py from flashdata-dev/youtube-transcript-research-flashdata: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/flashdata-dev/youtube-transcript-research-flashdata/resolve/main/tool.py
- Command line
-
hf download hf://spaces/flashdata-dev/youtube-transcript-research-flashdata/tool.py
-
curl -L -o tool.py https://huggingface.co/spaces/flashdata-dev/youtube-transcript-research-flashdata/resolve/main/tool.py
1.45 kB
| from smolagents import Tool | |
| class FlashDataTool(Tool): | |
| name = 'youtube_transcript' | |
| description = 'Retrieve existing YouTube transcript text and timestamped segments by video ID and language. Automatic captions are selected by default. Defaults to existing English automatic captions. No speech recognition, translation or fallback to another track; unavailable tracks fail. Uses paid FlashData API credits. Never automatically retry an uncertain submission; check Jobs first.' | |
| inputs = {'auto': {'description': 'True requests automatic captions; false requests manually authored ' | |
| 'captions. Default: True.', | |
| 'nullable': True, | |
| 'type': 'boolean'}, | |
| 'language': {'description': 'Requested caption language code. pattern: ^[A-Za-z0-9-]{1,35}$. ' | |
| "Default: 'en'.", | |
| 'nullable': True, | |
| 'type': 'string'}, | |
| 'video_id': {'description': '11-character YouTube video ID or a YouTube video URL.', | |
| 'type': 'string'}} | |
| output_type = 'object' | |
| def forward(self, video_id: str, language: str = 'en', auto: bool = True) -> dict: | |
| from langchain_flashdata import FlashDataYouTubeTranscript | |
| values = {'video_id': video_id, 'language': language, 'auto': auto} | |
| return FlashDataYouTubeTranscript().invoke({key: value for key, value in values.items() if value is not None}) | |