YouTube Transcript Summarizer
The YouTube Transcript Summarizer is an AI-powered tool designed to convert YouTube video transcripts into concise, insightful summaries. This project leverages advanced AI technologies, including large language models (LLMs) and the Streamlit framework, to create a simple, user-friendly interface for summarizing videos based on transcripts.
Project Overview
The goal of this project is to streamline the process of understanding long and complex YouTube video transcripts. Whether for academic purposes, professional needs, or casual learning, the summarizer efficiently extracts key points, themes, and conclusions, reducing the time required to grasp the video's essence.
Key Features
- Transcript Extraction: Automatically fetches the transcript of any YouTube video using its URL.
- Summarization: Generates summaries tailored to different difficulty levels: Beginner-Friendly, Intermediate, and Advanced/Technical.
- Customizable Length: Users can adjust the summary length with a slider.
- Translation: Translates summaries into multiple languages (English, German, Dutch) while maintaining the original format (bullet points or paragraphs).
- User-Friendly Interface: Built using Streamlit, the tool is accessible and easy to use for both technical and non-technical users.
Technical Architecture
The YouTube Transcript Summarizer combines several technologies to deliver a seamless experience:
1. Transcript Retrieval
The project uses the YouTubeTranscriptApi
Python library to extract transcripts from YouTube videos. It handles different YouTube URL formats and ensures that the transcript is properly formatted for processing.
2. Summarization with OpenAI API
The summarization process leverages OpenAI's GPT-based models (e.g., GPT-3.5 or GPT-4). Users can customize the summary format (bullet points or paragraphs), difficulty level, and length:
- Beginner-Friendly: Simplified summaries for younger or non-technical audiences.
- Intermediate: Balanced summaries with moderate technical details.
- Advanced/Technical: Detailed summaries using technical terminology for professional audiences.
3. Translation
The tool uses OpenAI's API to translate summaries into selected languages (German, Dutch, or English). It ensures the translation retains the original format (bullet points or paragraphs) for consistency.
Workflow
- Input: User enters a YouTube video URL.
- Transcript Retrieval: The tool fetches the transcript using the YouTubeTranscriptApi library.
- Summary Generation: The transcript is summarized based on user-selected settings (difficulty level, format, and length).
- Translation (Optional): The summary is translated into the chosen language.
- Output: The summarized and translated content is displayed in the Streamlit app.
Technologies Used
- YouTubeTranscriptApi: A Python library for extracting YouTube video transcripts.
- Streamlit: A Python framework for building user-friendly web applications.
- OpenAI API: GPT-based language models for summarization and translation.
- Python: The core programming language used for development.
Benefits
- Time-Saving: Reduces the effort required to understand lengthy video content.
- Accessibility: Makes video content accessible to non-native speakers through translation.
- Customizable: Allows users to adjust summaries based on their specific needs and preferences.
- Efficiency: Automates the tedious process of manually extracting insights from video transcripts.
Python Code Explanation
1. Importing Libraries
The script starts by importing essential libraries:
youtube_transcript_api
: Extracts YouTube video transcripts.
streamlit
: Creates the interactive user interface for the app.
openai
: Provides access to OpenAI's GPT models for summarization and translation.
dotenv
: Loads environment variables securely, such as the OpenAI API key.
os
: Handles file system interactions and environment variables.
2. Loading the API Key
The OpenAI API key is loaded using the load_dotenv
function, ensuring secure access without hardcoding sensitive information into the script.
3. Extracting Transcripts
The extract_transcript
function handles transcript retrieval:
- Accepts a YouTube URL as input.
- Parses the video ID from various URL formats.
- Uses
YouTubeTranscriptApi
to fetch the transcript and combines it into a single string.
- Returns either the transcript or an error message.
4. Summarization
The summarize_text
function generates summaries using OpenAI's ChatCompletion API:
- Accepts the transcript, summary format, length, and difficulty level as inputs.
- Constructs a custom prompt based on user-selected options.
- Limits the output length using the
max_tokens
parameter.
- Handles errors gracefully and returns the summary.
5. Translation
The translate_text
function translates summaries into selected languages:
- Ensures the translation maintains the original format (bullet points or paragraphs).
- Uses a language map to handle supported languages.
- Generates a prompt for OpenAI's API to produce the translation.
6. Streamlit Interface
The Streamlit UI allows users to:
- Enter the YouTube video link in a text box.
- Adjust summary settings such as length, difficulty level, and output format (bullet points or paragraphs).
- Select a target language for translation if needed.
- View the extracted transcript and generated summary within the app interface.
The app displays the video thumbnail as a quick confirmation of the correct video link and provides error messages for invalid inputs or issues during transcript retrieval.
7. Error Handling
The code includes robust error-handling mechanisms to ensure smooth functionality:
- Invalid YouTube URLs trigger an error message prompting the user to correct their input.
- Errors during API calls (e.g., summarization or translation) are captured and displayed to the user.
- If the transcript length exceeds a certain limit, a warning is shown, and the transcript is truncated to fit the token constraints of the OpenAI API.
8. Dynamic Session Management
The app leverages Streamlit's session state to optimize performance and user experience:
- Transcript Caching: The transcript is fetched only once per session to reduce redundant API calls and improve efficiency.
- Video ID Tracking: Ensures that the correct transcript is associated with the provided video link throughout the session.
Conclusion
This project demonstrates the integration of advanced AI tools, such as OpenAI's GPT models and the YouTubeTranscriptApi, into a user-friendly web application. By automating transcript summarization and translation, it addresses real-world needs for quick and accessible insights into video content.
Here’s the link to the live app: YouTube Transcript Summarizer.
Explore the code and contribute to its development on GitHub.
Back