|

AI Project: Build a YouTube Video Summarizer (Whisper + Hugging Face)

3D isometric illustration of a video player sending audio waves through a Whisper AI module and a Hugging Face processor to generate a concise summary document.

We’ve learned Transcription (Whisper) and Summarization separately. Now, let’s combine them to solve a real problem: watching long YouTube videos. In this post, we’ll build a Python YouTube Summarizer to make this process much easier.

We will build a script that takes a YouTube URL and outputs a short text summary.

Step 1: Installation

We need yt-dlp to download audio, plus our AI libraries. Note: You need ffmpeg installed on your system.

pip install yt-dlp openai-whisper transformers torch

Step 2: The Code

This script has three stages: Download -> Transcribe -> Summarize.

import yt_dlp
import whisper
from transformers import pipeline
import os

# --- CONFIGURATION ---
VIDEO_URL = "https://www.youtube.com/watch?v=YOUR_VIDEO_ID" # Pick a short video (< 5 mins)
AUDIO_FILE = "audio.mp3"

# --- 1. DOWNLOAD AUDIO ---
print("Downloading audio...")
ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
    'outtmpl': 'audio', # Saves as audio.mp3
}

with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    ydl.download([VIDEO_URL])

# --- 2. TRANSCRIBE (Speech-to-Text) ---
print("Transcribing audio (loading Whisper)...")
model = whisper.load_model("base")
result = model.transcribe(AUDIO_FILE)
full_text = result["text"]

print(f"Transcript length: {len(full_text)} characters")

# --- 3. SUMMARIZE (Text-to-Text) ---
print("Summarizing text...")
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

# We might need to chunk the text if it's too long, but for short videos:
# (max_length is the length of the summary)
summary = summarizer(full_text[:3000], max_length=150, min_length=50, do_sample=False)

print("\n--- VIDEO SUMMARY ---")
print(summary[0]['summary_text'])

# Cleanup
os.remove(AUDIO_FILE)

Step 3: The Result

You can now paste in a URL for a tech talk or news clip, wait a minute, and get a perfect paragraph explaining what happened!


Key Takeaways

  • The article explains how to build a Python YouTube Summarizer to handle long video content.
  • First, install necessary tools like yt-dlp and ensure ffmpeg is on your system.
  • The script involves three stages: Download, Transcribe, and Summarize.
  • Users can input any YouTube URL to receive a concise summary of the content.
  • This solution is ideal for summarising tech talks and news clips efficiently.

Python Pro Hub readers also found these helpful:

Similar Posts

Leave a Reply