DEV Community

Cover image for Streamline Your YouTube Watching with an AI-Powered Summarizer by Lyzr Low-Code Agent
Prajjwal Sule
Prajjwal Sule

Posted on

Streamline Your YouTube Watching with an AI-Powered Summarizer by Lyzr Low-Code Agent

In today's digital age, YouTube serves as a vast repository of information, with countless videos covering a wide array of topics. However, sifting through lengthy videos to find the information you need can be time-consuming and inefficient. But what if there was a way to access key insights and summaries without having to watch the entire video? Enter Lyzr's YouTube Summarizer, a powerful tool designed to provide users with quick access to essential information extracted from YouTube videos.

Let's see how you can build this LLM by your own with the help of Lyzr's Low-Code Agents.


Welcome to Lyzr! | Lyzr Documentation

Explore the limitless possibilities of Generative AI with Lyzr, an enterprise alternative to popular Generative AI SaaS products. Lyzr offers a robust and secure solution for building and launching your own enterprise-grade Generative AI applications with speed and confidence.

favicon docs.lyzr.ai

Setting Up the Project Initials

Clone the YouTube Summarizer app repository
Link- YouTube Summarizer

Set up a virtual environment

python3 -m venv venv
source venv/bin/activate

Enter fullscreen mode Exit fullscreen mode

Create an environment file named .env and add your OpenAI API key and Weaviate cluster URL and API key

OPENAI_API_KEY = “Your_OpenAI_API_Key”
VECTOR_STORE_URL = “Your_Weaviate_Cluster_URL"
VECTOR_STORE_API = "Your_Weaviate_Cluster_API"

Enter fullscreen mode Exit fullscreen mode

Install the required dependencies

pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Project Structure

The YouTube Summarizer project structure looks as follows

YouTube-Summarizer

├── utils/
   ├── __init__.py
   └── utils.py

├── app.py

├── README.md

├── .env

├── .gitignore

└── requirements.txt

Enter fullscreen mode Exit fullscreen mode

The utils directory contains utility functions used throughout the application, while app.py serves as the main entry point for the YouTube Summarizer application.

Quick Look of YouTube Summarizer

Summarizing YouTube Videos

The summarizer function utilizes Lyzr's QABot to extract key information from a YouTube video, we'll write this code inside the utils.py file.

def summarizer(agent):
    summary = agent.query("What is this video about? Can you explain in a short paragraph?")
    keypoints = agent.query('Provide 3-5 key points from this video?')
    content_analysis = agent.query('Write any examples or case studies mentioned in the video? If so, what are they?')
    audience_engagement = agent.query("""
                                        "How does the speaker engage with the audience in the video?"
                                        "Are there any interactive elements or calls to action in the video?"
                                        """)

    additional_information = agent.query("""
                                        "Are there any references or citations provided in the video?"
                                        "Can you identify any trends or patterns in the content of the video?"
                                        """)

    if summary is not None:
        st.subheader('Video Summary')
        st.write(summary.response)
        st.write(keypoints.response)
        if len(content_analysis.response) > 150:
            st.subheader('Content Analysis')
            st.write(content_analysis.response)
            if len(audience_engagement.response) > 150:
                st.subheader('Audience Engagement')
                st.write(audience_engagement.response)
                if len(additional_information.response) > 150:
                    st.header('Additional Information')
                    st.write(additional_information.response)

Enter fullscreen mode Exit fullscreen mode

This function queries the QABot agent to extract a short summary, key points, content analysis, audience engagement details, and additional information from the video. Responses exceeding 150 characters are displayed using Streamlit's st.write() function.

Creating the Entry point for our Application

Now we will write all the core functionalities inside the main file called as app.py, this file work as a entry point for our YouTube-Summarizer app.

import os
from PIL import Image
from utils import utils
import streamlit as st
from urllib.parse import urlparse, parse_qs
from dotenv import load_dotenv; load_dotenv()
from lyzr import QABot

# Youtube Summarizer Application

# replace this with your openai api key or create an environment variable for storing the key.
os.environ["OPENAI_API_KEY"] = os.getenv('OPENAI_API_KEY')
Enter fullscreen mode Exit fullscreen mode

First we started with the importing of basic libraries, here the QABot from lyzr will help us to achieve our goal. Then, we need to setup the openai api key from fetching it from the .env file.

Parsing YouTube Video ID

In the app.py file, the youtube_video_id function parses a YouTube video URL to extract the video ID

def youtube_video_id(url):
    parsed_url = urlparse(url)
    query_params = parse_qs(parsed_url.query)
    video_id = query_params.get('v')
    if video_id:
        return video_id[0]  # Returns the YouTube video ID
    else:
        return None

Enter fullscreen mode Exit fullscreen mode

This function takes a YouTube video URL as input and returns the video ID if found, or None otherwise.

Configuring Vector Store

The vector_store_configuration function generates configuration parameters required for interacting with a Weaviate vector store

def vector_store_configuration(id):
    vector_store_params = {
        "vector_store_type": "WeaviateVectorStore",
        "url": os.getenv('VECTOR_STORE_URL'),
        "api_key": os.getenv('VECTOR_STORE_API'),
        "index_name": f"Video{id}IndexName"
    }

    return vector_store_params

Enter fullscreen mode Exit fullscreen mode

This function constructs a dictionary containing the type of vector store, its URL, API key, and a custom index name based on the video ID.

Initiating Summarization

The lyzr_yt_summarizer function initializes the YouTube summarizer agent

def lyzr_yt_summarizer(youtube_id, vector_params):
    yt_summarizer = QABot.youtube_qa(
            urls=[youtube_id],
            vector_store_params=vector_params
        )

    return yt_summarizer

Enter fullscreen mode Exit fullscreen mode

This function initializes the QABot with the YouTube video ID and vector store parameters, enabling it to process and analyze the video content.

With the few lines of code, we have successfully implemented the LLM agent for creating youtube video's summary, this is possible because of lyzr's Agent, we can build our LLM application with the ease without having deep technical understanding of Generative AI and LLM's, we just need to call the lyzr agent and all the things are taken care by agent itself.

Running the Application

The summarizer function is invoked from the utils module, which generates and displays a summary of the YouTube video based on the initialized summarizer agent.

if __name__ == "__main__":
    style_app()
    yt_url = st.text_input("Paste YouTube video URL here")
    if st.button("Summarize"):
        if len(yt_url) > 0:
            youtube_id = youtube_video_id(url=yt_url)
            if youtube_id is not None:
                vector_config = vector_store_configuration(id=youtube_id)
                summarizer_agent = lyzr_yt_summarizer(youtube_id=youtube_id, vector_params=vector_config)
                utils.summarizer(agent=summarizer_agent)
            else:
                st.error('Please provide a valid YouTube video URL')
        else:
            st.error('Please paste the YouTube video URL')

Enter fullscreen mode Exit fullscreen mode

Upon clicking the "Summarize" button, the application verifies the presence of a valid URL, extracts the video ID, configures the vector store parameters, initializes the YouTube summarizer agent, and generates a summary of the video content.

Conclusion

With Lyzr's YouTube Summarizer, you can now access key insights and summaries from YouTube videos quickly and efficiently. Say goodbye to long hours of video-watching and hello to informed decision-making with just a few clicks. Try out the YouTube Summarizer today and unlock efficiency in your YouTube watching experience!

References

For further exploration and engagement, refer to Lyzr's website, book a demo, or join the community channels on Discord and Slack.
YouTube Summarizer: GitHub
Lyzr Website: https://www.lyzr.ai/
Book a Demo: https://www.lyzr.ai/book-demo/
Lyzr Community Channels: Discord, Slack

Top comments (0)