Download tools/youtube_transcript.py from dmfelder/DF_Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 899 Bytes
-
https://huggingface.co/spaces/dmfelder/DF_Final_Assignment_Template/resolve/main/tools/youtube_transcript.py
- Command line
-
hf download hf://spaces/dmfelder/DF_Final_Assignment_Template/tools/youtube_transcript.py
-
curl -L -o youtube_transcript.py https://huggingface.co/spaces/dmfelder/DF_Final_Assignment_Template/resolve/main/tools/youtube_transcript.py
899 Bytes
| from langchain_core.tools import tool | |
| from loguru import logger | |
| from youtube_transcript_api import YouTubeTranscriptApi | |
| def youtube_transcript(video_id: str) -> str: | |
| """ | |
| Fetches the transcript of a YouTube video using its video ID. | |
| Args: | |
| video_id (str): The unique identifier of a YouTube video, e.g., '12345' from https://www.youtube.com/watch?v=12345. | |
| Returns: | |
| str: The transcript of the specified YouTube video as bullet points. | |
| """ | |
| logger.info(f"use youtube_transcript with param: {video_id}") | |
| try: | |
| transcript = YouTubeTranscriptApi.get_transcript(video_id) | |
| bullet_points = '\n'.join(f"- {entry['text']}" for entry in transcript) | |
| return bullet_points | |
| except Exception as e: | |
| logger.error(f"Failed to fetch transcript: {e}") | |
| return f"Error: {str(e)}" | |