Building Idea Generator with Lyzr SDK
Tags: ai, opensource, creativity, lyzr
Published: 2024-04-24 10:44:28

Are you looking for innovative ways to spark creativity and generate fresh ideas? Imagine having an AI-powered assistant at your fingertips, ready to **brainstorm ideas** tailored to your needs. With advancements in artificial intelligence and streamlined development frameworks like Streamlit, creating such a tool is within reach.

In this blog, we’ll walk through the process of building an Idea Generator App using **Lyzr’s Automata and Streamlit**, empowering users to explore a universe of possibilities with just a few clicks.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/icfjfxqev6kt9v041hog.png)

Creativity knows no bounds, but sometimes, a little nudge in the right direction can make all the difference. Our **Idea Generator** App aims to provide that nudge, harnessing the power of AI to generate tailored ideas based on user input. Whether you’re brainstorming for a project, seeking inspiration for a blog post, or exploring new business opportunities, this app has you covered.

**Why use Lyzr SDK’s?**

With Lyzr SDKs, crafting your own **GenAI** application is a breeze, requiring only a few lines of code to get up and running swiftly.

[Checkout the Lyzr SDK’s](https://docs.lyzr.ai/homepage)

**Lets get Started!**

Create a new file **app.py** and use that

```
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
import os
```
This code snippet imports essential modules and packages for building a Streamlit application integrated with **Lyzr’s Automata**. It includes Streamlit for web app development, the OpenAIModel class from Lyzr’s Automata ai_models package for interaction with OpenAI’s GPT-based model, Agent and Task classes for defining agents and tasks, LinearSyncPipeline class for sequential task execution, PIL’s Image class for image handling, and the os module for accessing environment variables.

Subsequently, it initializes the **OpenAI API key** using Streamlit’s secrets management. By accessing the specific key stored securely in Streamlit’s secrets, where the OpenAI API key is securely stored, it replaces the placeholder “OPENAI_API_KEY”. This ensures secure access to the OpenAI API within the Streamlit application.

```
# Set the OpenAI API key
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
open_ai_text_completion_model = OpenAIModel(
    api_key=st.secrets["apikey"],
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.2,
        "max_tokens": 1500,
    },
)
```
This line of code initializes an instance of the OpenAIModel class from the Lyzr Automata package. It configures the model with the API key obtained from Streamlit secrets, granting access to OpenAI’s services. The parameters specify the settings for the AI model, including the specific model to use (“**gpt-4-turbo-preview**”), the temperature parameter for controlling the randomness of the model’s predictions, and the maximum number of tokens allowed in the model’s output (**set to 1500 tokens**).

```
idea = st.text_input("Enter here")

idea_generator = Agent(
    role='Expert Idea Generator',
    prompt_persona=f'You are an Expert IDEATION CONSULTANT. Your task is to generate relevant ideas based on the given {idea}.'
)

task1 = Task(
   name="Generate Ideas",
   model=open_ai_text_completion_model,
   agent=idea_generator,
   instructions=f"""
 Your task is to GENERATE CREATIVE and RELEVANT responses for a given {idea}.

Adhere to this step-by-step guide to ensure you deliver EXCELLENT RESULTS:

1. CAREFULLY READ and COMPREHEND the provided {idea} to FULLY UNDERSTAND its ESSENCE.

2. ANALYZE the CONTEXT of the given {idea}, ensuring your responses are TAILORED and FUNCTIONAL for the user's specific needs.

3. BRAINSTORM a LIST of 5-10 ORIGINAL and APPLICABLE ideas that are in harmony with the given {idea}. Present these ideas PROMINENTLY as a LIST, with BRIEF yet INFORMATIVE descriptions of 1-2 sentences for each.

4. ENSURE that your list of brainstormed ideas is the FOCAL POINT of your response.

5. WRITE with CLARITY and CONCISENESS to maintain the reader's ENGAGEMENT and INTEREST throughout your response.

""",
 )

if st.button("Generate"):
    output = LinearSyncPipeline(
        name="Idea Generation Pipeline",
        completion_message="pipeline completed",
        tasks=[task1],
    ).run()
```
In this section of the code, the user is prompted to input their idea through a text input field using Streamlit’s text_input function. Subsequently, an Agent object named **idea_generator** is instantiated, representing an "**Expert Idea Generator**." This agent is assigned a prompt persona instructing it to generate relevant ideas based on the user's input.

A Task object named task1 is defined, specifying the task of generating ideas. This task is associated with the previously defined idea_generator agent and utilizes an **open_ai_text_completion_model** for idea generation. The task instructions are provided as a formatted multi-line string, outlining a step-by-step guide for generating creative and relevant responses based on the user's input idea.

If the user clicks the “**Generate”** button, a LinearSyncPipeline named "Idea Generation Pipeline" is executed, comprising the defined task (task1). The pipeline executes sequentially, generating ideas based on the user's input and the specified instructions.

With our **Idea Generator App** up and running, users have a powerful tool at their disposal for unlocking creativity and exploring new ideas. Whether you’re a writer, entrepreneur, or innovator, the possibilities are endless.

**App link**: https://idea-generator-lyzr.streamlit.app/

**Source Code**: https://github.com/isakshay007/Idea-Generator

**Connect with Lyzr**
To learn more about **Lyzr and its SDK’s**, visit our website or get in touch with our team:

**Website**: [Lyzr.ai](https://www.lyzr.ai/)
**Book a Demo**: [Book a Demo](https://www.lyzr.ai/book-demo/)
**Discord**: [Join our Discord community](https://discord.com/invite/nm7zSyEFA2)
**Slack**: [Join our Slack channel](https://anybodycanai.slack.com/join/shared_invite/zt-2a7fr38f7-_QDOY1W1WSlSiYNAEncLGw#/shared-invite/email)