Codebuff's Dev Blog

Youtube AI Summary

· PYTHON, AI, Ollama

Summarize youtube content with AI using local llm

This Python script converts YouTube video transcripts into well-structured summarized posts using a local LLM. It automates the process of fetching video details, extracting transcripts, and summarizing the content. You can find the project on GitHub: GitHub Repository.

Features

Prerequisites

Installation

  1. Clone this repository or copy the script.
  2. Install the required dependencies:
    pip install youtube-transcript-api pytubefix ollama
    
  3. Install and configure Ollama to run locally.

Usage

To run the script, execute the following command in your terminal:

python script_name.py <YouTube_URL>

Example:

python script_name.py https://www.youtube.com/watch?v=dQw4w9WgXcQ

How It Works

  1. The script fetches the title and transcript of the specified YouTube video.
  2. The transcript is passed to an AI model (like deepseek-r1) running locally via Ollama.
  3. The AI summarizes the transcript into a structured and formatted post.
  4. The generated post is saved as a Markdown file using the video title as the filename.

Example Output

If the video title is My Sample Video, the script creates a file called My Sample Video.md containing the blog post.

Local AI Model Usage

This script is designed to work with local AI models using Ollama. Ensure you have a model like deepseek-r1 available locally by downloading it via Ollama:

ollama pull deepseek-r1:7B

Ollama Model Configuration

The model is specified in the summarize_text() function:

response: ChatResponse = chat(
     model="deepseek-r1:7B",
     messages=[
          {"role": "user", "content": prompt},
     ]
)

You can adjust the model based on your preferences.

Error Handling

If any errors occur, the script logs the details and exits gracefully. Ensure you provide a valid YouTube URL and have internet access to fetch transcripts.

Troubleshooting

Contributing

Feel free to submit issues or pull requests to enhance this project.