DEV Community

Cover image for Revolutionize Your Writing Process with Lyzr's Book Writing Assistant
Prajjwal Sule
Prajjwal Sule

Posted on

Revolutionize Your Writing Process with Lyzr's Book Writing Assistant

In the realm of literature, the journey from idea to publication can be arduous. Lyzr, a frontrunner in AI-powered solutions, unveils its latest breakthrough: the Book Writing Assistant. This innovative tool is poised to revolutionize the way authors craft their masterpieces, providing indispensable support and inspiration at every step of the writing process.

The Book Writing Assistant by Lyzr is your ultimate AI muse, offering unparalleled assistance in various aspects of book creation, from generating captivating titles to designing stunning book covers. With its intuitive interface and cutting-edge AI models, this tool empowers authors and aspiring writers to unleash their creativity and bring their literary visions to life.


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

Let's dive into setting up the project for Lyzr's Book Writing Assistant

Clone the App: Start by cloning the Book Writing Assistant app repository.

   git clone https://github.com/PrajjwalLyzr/Book-Writing-Assistant
Enter fullscreen mode Exit fullscreen mode

Create a Virtual Environment: Set up a virtual environment and activate it.

   python3 -m venv venv
   source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

Set Environment Variables: Create a .env file and add your OpenAI API key.

   OPENAI_API_KEY = "Paste your openai api key here"
Enter fullscreen mode Exit fullscreen mode

Install Dependencies: Install the required dependencies.

   pip install lyzr-automata streamlit python-dotenv
Enter fullscreen mode Exit fullscreen mode

Project Structure

Book-Writing-Assistant


├── app.py

├── README.md

├── .gitignore

└── requirements.txt
Enter fullscreen mode Exit fullscreen mode

Core Components of the Book Writing Assistant

Imports necessary libraries like os, PIL, streamlit, and modules from Lyzr’s automata. It also loads the OpenAI API key from environment variables. The API_KEY is retrieved using os.getenv. This key is crucial for accessing OpenAI’s services.

import os
import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent, Task, Logger
from lyzr_automata.tasks.task_literals import InputType, OutputType
from lyzr_automata.pipelines.linear_sync_pipeline import LinearSyncPipeline
from dotenv import load_dotenv

load_dotenv()

API_KEY = os.getenv('OPENAI_API_KEY')
Enter fullscreen mode Exit fullscreen mode

Setup the OpenAI models for Book Writing Assistant

Initializes two instances of the OpenAIModel class, which facilitate interactions with OpenAI’s models. The first instance, open_ai_model_image, is configured to work with the DALL-E model, designed for image generation tasks. It specifies parameters such as the API key, the number of samples to generate (n), and the model name.

open_ai_model_image = OpenAIModel(
    api_key=API_KEY,
    parameters={
        "n": 1,
        "model": "dall-e-3",
    },
)


open_ai_model_text = OpenAIModel(
    api_key= API_KEY,
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.5,
        "max_tokens": 1500,
    },
)
Enter fullscreen mode Exit fullscreen mode

Kernel of Book Writing Assistant Application

Lyzr Automata is a sophisticated multi-agent automation framework designed to keep things simple, with a focus on workflow efficiency and effectiveness. It enables the creation of multiple agents that are coupled with specific tasks.

def book_writing_assistant(genre):

    writer_agent = Agent(
        prompt_persona="You are an expert book writer and a graphic designer, good at writing books on a single keyword as well as making attractive cover pages for your books, you can also provide the chapters regarding the any topic",
        role=" book writer",
    )


    title_generation = Task(
        name="Book Title Creator",
        agent=writer_agent,
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
        model=open_ai_model_text,
        instructions="Use the description provided and write some set of titles for the book. Use your creativity. [IMPORTANT!] Setup the events in a detailed manner",
        log_output=True,
        enhance_prompt=False,
        default_input=genre
    )


    chapter_generation = Task(
        name="Book Chapters Creator",
        agent=writer_agent,
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
        model=open_ai_model_text,
        instructions="Use the description provided and write some set book chapters and well give the blueprint of how to write the book on the provided description. Use your creativity. [IMPORTANT!] Setup the events in a detailed manner",
        log_output=True,
        enhance_prompt=False,
        default_input=genre
    )


    book_writing_tips =  Task(
        name="Book Writing Tips",
        agent=writer_agent,
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
        model=open_ai_model_text,
        instructions="Use the description provided and give the 4-5 bullet points in 20-30 words of book writing tips on the provided description. Use your creativity. [IMPORTANT!] Setup the events in a detailed manner",
        log_output=True,
        enhance_prompt=False,
        default_input=genre
    )



    book_cover_image = Task(
        name="Book Cover Image Creation",
        output_type=OutputType.IMAGE,
        input_type=InputType.TEXT,
        model=open_ai_model_image,
        log_output=True,
        instructions="Generate an Image which is suitable to the given description. Capture every detail. Minimalistic style. [IMPORTANT!] Avoid any text or numbers in the image.",
    )


    logger = Logger()


    main_output = LinearSyncPipeline(
        logger=logger,
        name="Book Writing Assistant",
        completion_message="Book Writing Assistant Generated all things!",
        tasks=[
            title_generation,
            chapter_generation,
            book_writing_tips,
            book_cover_image,
        ],
    ).run()


    return main_output
Enter fullscreen mode Exit fullscreen mode

It comes up with potential titles for the book based on what the writer wants to write about. Makes a plan for what each chapter of the book could be about, helping the writer organize their ideas.

Executing the Application

To run Lyzr's Book Writing Assistant:

if __name__ == "__main__":
    style_app() 
    book_brief = st.text_input("Enter about the book, a title or a genre")
    button=st.button('Submit')
    if (button==True):

        generated_output = book_writing_assistant(book_brief)

        # DISPLAY OUTPUT
        title_output = generated_output[0]['task_output']
        st.header('Suggested Titles')
        st.write(title_output)
        st.markdown('---')

        chapter_output = generated_output[1]['task_output']
        st.header("Suggested Chapter's")
        st.write(chapter_output)
        st.markdown('---')

        writing_tips = generated_output[2]['task_output']
        st.header('Writing Tips')
        st.write(writing_tips)
        st.markdown('---')

        image_file_name = generated_output[3]['task_output'].local_file_path
        st.header('Book Cover Page')
        st.image(image_file_name, caption='Book Writing Assistant - Lyzr') 
Enter fullscreen mode Exit fullscreen mode

With Lyzr's Book Writing Assistant, the daunting task of writing a book is transformed into an inspiring and fulfilling journey. Embrace the power of AI to unleash your creativity and bring your literary dreams to fruition.

References

Top comments (1)

Collapse
 
philip_tgreene_702ba5af profile image
Philip T. Greene • Edited

Lyzr's Book Writing Assistant streamlines the writing process by providing AI-driven support for structure, editing, and idea generation, making it ideal for authors. Coupling this tool with book promotion services for authors can greatly enhance both the writing and marketing phases, ensuring your work reaches a wider audience.