Implementation of coding to create interactive transcript and PDF analysis with lizar chatbot framework

In this tutorial, we introduce a trimmed approach to the process and analysis, using YouTube Video Transcripts LorAn advanced AI-driven structure designed to facilitate interaction with textual data. The benefit of the intuitive chatbot interface of the lizer with YouTube-transcript-API and FPDF, users can easily convert video content into structured PDF documents and conduct a sensible analysis through dynamic interactions. Ideal for researchers, teachers and content makers, LYZR accelerates the process of gaining meaningful insights, creating summarizes, and creating creative questions directly from multimedia resources.

!pip install lyzr youtube-transcript-api fpdf2 ipywidgets
!apt-get update -qq && apt-get install -y fonts-dejavu-core

We have set the atmosphere required for the tutorial. The first command establishes the required Python libraries, including LYZR, LYZR, YouTube-transcript-API, FPDF2 for PDF Generation for Transcript Extraction, FPDF2 and Interactive Chat interface for transcript extraction. The second command ensures that the Sans FNT Nut is installed on the system to support the full Unicode text rendering in the generated PDF files.

import os
import openai


openai.api_key = os.getenv("OPENAI_API_KEY")
os.environ('OPENAI_API_KEY') = "YOUR_OPENAI_API_KEY_HERE"

We configure the OpenAI API Key Access Case for Tutorial. We import OS and openAI modules, then receive the API key from the environment variables (or set it directly via OS.environ). This setup is required to take advantage of the powerful models of OpenAI in the LYZR framework.

import json
from lyzr import ChatBot
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound, CouldNotRetrieveTranscript
from fpdf import FPDF
from ipywidgets import Textarea, Button, Output, Layout
from IPython.display import display, Markdown
import re

Check the perfect notebook here

We import libraries needed for tutorial. These include JSOn for data handling, AI-powered chat capabilities for Lezer’s chatb OTTT and Transcript Ka Rectic from YouTube videos. Also, it brings FPDF for PDF generation, to render the markdown content in IPWidgates and Ipython.Display notebook for interactive UI components. Module is also imported again for regular expression operations in text processing tasks.

def transcript_to_pdf(video_id: str, output_pdf_path: str) -> bool:
    """
    Download YouTube transcript (manual or auto) and write it into a PDF
    using the system-installed DejaVuSans.ttf for full Unicode support.
    Fixed to handle long words and text formatting issues.
    """
    try:
        entries = YouTubeTranscriptApi.get_transcript(video_id)
    except (TranscriptsDisabled, NoTranscriptFound, CouldNotRetrieveTranscript):
        try:
            entries = YouTubeTranscriptApi.get_transcript(video_id, languages=('en'))
        except Exception:
            print(f"(!) No transcript for {video_id}")
            return False
    except Exception as e:
        print(f"(!) Error fetching transcript for {video_id}: {e}")
        return False


    text = "\n".join(e('text') for e in entries).strip()
    if not text:
        print(f"(!) Empty transcript for {video_id}")
        return False


    pdf = FPDF()
    pdf.add_page()


    font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
    try:
        if os.path.exists(font_path):
            pdf.add_font("DejaVu", "", font_path)
            pdf.set_font("DejaVu", size=10)
        else:
            pdf.set_font("Arial", size=10)
    except Exception:
        pdf.set_font("Arial", size=10)


    pdf.set_margins(20, 20, 20)
    pdf.set_auto_page_break(auto=True, margin=25)


    def process_text_for_pdf(text):
        text = re.sub(r'\s+', ' ', text)
        text = text.replace('\n\n', '\n')


        processed_lines = ()
        for paragraph in text.split('\n'):
            if not paragraph.strip():
                continue


            words = paragraph.split()
            processed_words = ()
            for word in words:
                if len(word) > 50:
                    chunks = (word(i:i+50) for i in range(0, len(word), 50))
                    processed_words.extend(chunks)
                else:
                    processed_words.append(word)


            processed_lines.append(' '.join(processed_words))


        return processed_lines


    processed_lines = process_text_for_pdf(text)


    for line in processed_lines:
        if line.strip():
            try:
                pdf.multi_cell(0, 8, line.encode('utf-8', 'replace').decode('utf-8'), align='L')
                pdf.ln(2)
            except Exception as e:
                print(f"(!) Warning: Skipped problematic line: {str(e)(:100)}...")
                continue


    try:
        pdf.output(output_pdf_path)
        print(f"(+) PDF saved: {output_pdf_path}")
        return True
    except Exception as e:
        print(f"(!) Error saving PDF: {e}")
        return False

Check the perfect notebook here

This function converts the function, transcript_tu_pdf, YouTube video transcript into clean, readable PDF documents. It receives a transcript using Utubatranscriptpepti, to avoid issues such as long words to break the PDF layout, graces exceptions such as unavailable transcripts, and format the text. The function also confirms the appropriate Unicode support using Dijavuson FENt Nut (if available) and makes the text best for PDF rendering by splitting excessive long words and maintaining continuous margins. PDF is successfully produced or false if mistakes occur.

def create_interactive_chat(agent):
    input_area = Textarea(
        placeholder="Type a question…", layout=Layout(width="80%", height="80px")
    )
    send_button = Button(description="Send", button_style="success")
    output_area = Output(layout=Layout(
        border="1px solid gray", width="80%", height="200px", overflow='auto'
    ))


    def on_send(btn):
        question = input_area.value.strip()
        if not question:
            return
        with output_area:
            print(f">> You: {question}")
            try:
                print("<< Bot:", agent.chat(question), "\n")
            except Exception as e:
                print(f"(!) Error: {e}\n")


    send_button.on_click(on_send)
    display(input_area, send_button, output_area)

Check the perfect notebook here

This function, creat_interaver_chat, creates a simple and interactive chat interface inside the colab. The use of IPVIJATS provides users to write questions to the text input field (tectaret turia), a send button to trigger the chat (button) and output field (output) to display the conversation. When the user clicks, the entered question passes to the Leisure Chatb OTT agent, which produces and displays the response. This enables users to join dynamic Q&A sessions based on transcript analysis, creating interaction such as live communication with the AI ​​model.

def main():
    video_ids = ("dQw4w9WgXcQ", "jNQXAC9IVRw")
    processed = ()


    for vid in video_ids:
        pdf_path = f"{vid}.pdf"
        if transcript_to_pdf(vid, pdf_path):
            processed.append((vid, pdf_path))
        else:
            print(f"(!) Skipping {vid} — no transcript available.")


    if not processed:
        print("(!) No PDFs generated. Please try other video IDs.")
        return


    first_vid, first_pdf = processed(0)
    print(f"(+) Initializing PDF-chat agent for video {first_vid}…")
    bot = ChatBot.pdf_chat(
        input_files=(first_pdf)
    )


    questions = (
        "Summarize the transcript in 2–3 sentences.",
        "What are the top 5 insights and why?",
        "List any recommendations or action items mentioned.",
        "Write 3 quiz questions to test comprehension.",
        "Suggest 5 creative prompts to explore further."
    )
    responses = {}
    for q in questions:
        print(f"(?) {q}")
        try:
            resp = bot.chat(q)
        except Exception as e:
            resp = f"(!) Agent error: {e}"
        responses(q) = resp
        print(f"(/) {resp}\n" + "-"*60 + "\n")


    with open('responses.json','w',encoding='utf-8') as f:
        json.dump(responses,f,indent=2)
    md = "# Transcript Analysis Report\n\n"
    for q,a in responses.items():
        md += f"## Q: {q}\n{a}\n\n"
    with open('report.md','w',encoding='utf-8') as f:
        f.write(md)


    display(Markdown(md))


    if len(processed) > 1:
        print("(+) Generating comparison…")
        _, pdf1 = processed(0)
        _, pdf2 = processed(1)
        compare_bot = ChatBot.pdf_chat(
            input_files=(pdf1, pdf2)
        )
        comparison = compare_bot.chat(
            "Compare the main themes of these two videos and highlight key differences."
        )
        print("(+) Comparison Result:\n", comparison)


    print("\n=== Interactive Chat (Video 1) ===")
    create_interactive_chat(bot)

Check the perfect notebook here

Our main () function serves as the main driver for the entire tutorial pipeline. It processes the list of YouTube video IDs, converting the transcript available to PDF files using the transcript_to_pdf function. Once the PDF is generated, the LYZR PDF-chat agent is first launched on PDF, which can answer predefined questions such as the model to summarize the material, identify insights and produce quiz questions. Answers Answers.In the Jesson file is stored and formatted in the Markdown Report (Report.MD). If multiple PDFs are made, the function compares their main differences between videos using the LYZR agent. Finally, it starts an interactive chat interface with the user, enabling a dynamic conversation based on the transcript content, displaying the power of lizer for seamless PDF analysis and AI-operated interactions.

if __name__ == "__main__":
    main()

We ensure that the main () function runs only when the script is operated directly, when it is imported as a module. It is the best practice in Python scripts to control the execution flu.

In conclusion, as shown in this tutorial, integrating the lizar in our workflow, we can easily convert YouTube videos into a sensible, active Jnowledge. Leiser's intelligent PDF-chat capacity makes the main themes easier to produce Ka Rectic and wide summarizes, and also enables attractive, interactive research of content through intuitive conversation interface. Adoption of LYZR empower users to unclass the infidelity and significantly increase productivity when working with video transcripts, whether for academic research, educational purposes or creative content analysis.


Check the notebook here. All credit for this research goes to researchers of this project. Also, feel free to follow us Twitter And don't forget to join us 95K+ ML Subredit And subscribe Our newsletter.


Asif Razzaq is the CEO of MarketechPost Media Inc. as a visionary entrepreneur and engineer, Asif is committed to increasing the possibility of artificial intelligence for social good. Their most recent effort is the inauguration of the artificial intelligence media platform, MarktecPost, for its depth of machine learning and deep learning news for its depth of coverage .This is technically sound and easily understandable by a large audience. The platform has more than 2 million monthly views, showing its popularity among the audience.

Scroll to Top