DEV Community

Cover image for Automating YouTube Script Writing with Lyzr Automata
harshit-lyzr
harshit-lyzr

Posted on

Automating YouTube Script Writing with Lyzr Automata

In today’s digital age, content creation is king. Whether you’re a seasoned content creator or just starting your journey on platforms like YouTube, crafting engaging scripts is essential to captivate your audience. However, brainstorming and writing scripts can be time-consuming and challenging, especially when you’re striving to strike the right tone and cover specific topics.

But what if I told you there’s a tool that can streamline this process for you? Introducing the Lyzr YouTube Script Writer — an innovative solution that leverages artificial intelligence (AI) to generate compelling scripts tailored to your needs.

Features
Topic Customization: Simply input your desired topic into the Lyzr YouTube Script Writer, and let the AI-powered model do the rest.
Tone Selection: Tailor the tone of your script to match your audience and brand persona. Choose from options like Formal, Casual, Professional, Confident, and more.
Objective Definition: Clarify the objective of your script to ensure it aligns with your content strategy and goals.
Script Generation: With just a click of a button, Lyzr generates a well-crafted script that caters to both beginners and advanced viewers.

Lyzr AI Dev Community

Check out the Lyzr AI Dev Community community on Discord – hang out with 636 other members and enjoy free voice and text chat.

favicon discord.com

Code Walk-Through:
Imports and Setup:

import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent,Task
from lyzr_automata.pipelines.linear_sync_pipeline import LinearSyncPipeline
from PIL import Image
from dotenv import load_dotenv
import os

load_dotenv()
api = os.getenv("OPENAI_API_KEY")
Enter fullscreen mode Exit fullscreen mode

The code starts by importing necessary libraries:
streamlit as st: Used for building the Streamlit web app interface.
Modules from lyzr_automata: Used for building and running the Lyzr agent pipeline, including OpenAIModel, Agent, Task, and LinearSyncPipeline.
PIL.Image: Used for image processing.
dotenv: Used for loading environment variables from a .env file.
os: Used for interacting with the operating system.
load_dotenv is called to load environment variables from a .env file, likely containing the OpenAI API key.

User Interface and Inputs:

open_ai_text_completion_model = OpenAIModel(
    api_key=api,
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.2,
        "max_tokens": 1500,
    },
)
options=["Formal","Casual","Professional","Confident","Simplified","Academic","friendly","funny"]
topic = st.sidebar.text_area("What is the topic of your script?")
objective=st.sidebar.text_input("What is the objective of your script?")
tone = st.sidebar.selectbox("Select a tone of voice", options=options)
Enter fullscreen mode Exit fullscreen mode

An OpenAIModel object is created with the loaded API key and specified parameters for text completion, including the model (gpt-4-turbo-preview), temperature, and maximum number of tokens.
A list of tone options (“Formal”, “Casual”, etc.) is defined.
The sidebar allows users to:
Enter their script topic in a text area using st.sidebar.text_area.
Enter the objective of their script using st.sidebar.text_input.
Select a desired tone from the list using st.sidebar.selectbox.
A “Generate” button is created using st.sidebar.button.

Script Generation Logic:

if st.sidebar.button("Generate"):
    youtuber_agent = Agent(
        role="Youtube expert",
        prompt_persona=f"You are an Expert YOUTUBE SCRIPTWRITER. Your task is to DEVELOP a COMPELLING and ENGAGING script for an upcoming YouTube video."
    )

    prompt=f"Generate a script covering {topic} in a {tone} manner and objective of script is {objective}. The script should cater to both beginners and advanced viewers."

    script_generation_task  =  Task(
        name="Get Youtube Script",
        model=open_ai_text_completion_model,
        agent=youtuber_agent,
        instructions=prompt,
    )

    youtube_script_title=Task(
        name="Get Youtube Script",
        model=open_ai_text_completion_model,
        agent=youtuber_agent,
        instructions=f"Generate a script title covering {topic} in a {tone} manner and objective of script is {objective}",
    )

    output = LinearSyncPipeline(
            name="Youtube script Generation",
            completion_message="Script Generated",
            tasks=[youtube_script_title,script_generation_task],
    ).run()
Enter fullscreen mode Exit fullscreen mode

If the “Generate” button is clicked:
A Lyzr Agent named “Youtube expert” is created with a persona describing its role as a Youtube scriptwriter.
A prompt string is defined based on user inputs, specifying:
Topic of the script.
Desired tone.
Objective of the script.
Target audience (both beginners and advanced viewers).
Two Tasks are created using Task:
script_generation_task: Uses the OpenAI model, Youtube expert agent, and the prompt to generate the actual script content.
youtube_script_title: Uses the OpenAI model, Youtube expert agent, and a modified prompt (focusing on title generation) to generate a script title.
A LinearSyncPipeline named "Youtube script Generation" is created that runs both tasks sequentially:
First, it generates the script title using youtube_script_title.
Then, it generates the script content using script_generation_task.

Output Display:

st.markdown(output[0]['task_output'])
Enter fullscreen mode Exit fullscreen mode

The pipeline output is retrieved, which contains the generated script title from the first task.
The script title is displayed using st.markdown.
The Lyzr YouTube Script Writer empowers content creators to streamline their workflow and produce captivating scripts efficiently. By harnessing the power of AI, you can focus your energy on delivering engaging content while letting Lyzr handle the heavy lifting of script writing.

Ready to elevate your YouTube content? Give Lyzr a try today and experience the future of automated script writing.

try it now: https://lyzr-youtube-script-writer.streamlit.app/

For more information explore the website: Lyzr

Top comments (0)