DEV Community

harshit-lyzr
harshit-lyzr

Posted on

AI Agents for Effortless Mindmap Generation

Creating detailed and organized mindmaps can be a tedious and time-consuming task, especially when done manually. For educators, project managers, or anyone in need of a clear visualization of their ideas and plans, the need for an efficient and automated solution is evident. How can we leverage advanced AI technologies to streamline this process and generate mindmaps quickly and effectively?

Mindmap Generator, a Streamlit application that harnesses the power of Lyzr Automata and OpenAI’s GPT-4 to automate mindmap creation. By simply entering a topic, users can generate a comprehensive mindmap that outlines key areas and subtopics, saving valuable time and effort. This solution leverages AI agents to ensure the generated content is accurate, relevant, and well-structured.

What is Lyzr?
Lyzr Automata is an advanced AI-driven automation platform that enables users to create intelligent agents and pipelines to automate a wide range of tasks. It integrates with popular AI models, such as OpenAI’s GPT-4, to provide powerful natural language processing and generation capabilities.

Key Features of the Mindmap Generator
Intuitive User Interface: The Mindmap Generator app features a clean and user-friendly interface, making it easy for you to input your desired topic and generate a mindmap.
Seamless OpenAI Integration: The app seamlessly integrates with OpenAI’s API, allowing you to leverage the power of advanced language models like GPT-4 to generate high-quality mindmaps.
Customizable Mindmap Structure: The app provides a predefined mindmap format that you can use as a starting point, but you can also customize the structure to fit your specific needs.
Visually Appealing Mindmaps: The generated mindmaps are visually appealing and easy to understand, helping you organize your thoughts and ideas in a more effective manner.
Streamlined Workflow: By automating the mindmap generation process, the app saves you time and effort, allowing you to focus on the content and structure of your mindmap rather than the manual creation process.

Setting Up the Environment
Imports:
Imports necessary libraries: streamlit, libraries from lyzr_automata

pip install lyzr_automata streamlit
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode

Sidebar Configuration

api = st.sidebar.text_input("Enter our OPENAI API KEY Here", type="password")
if api:
    openai_model = OpenAIModel(
        api_key=api,
        parameters={
            "model": "gpt-4-turbo-preview",
            "temperature": 0.2,
            "max_tokens": 1500,
        },
    )
else:
    st.sidebar.error("Please Enter Your OPENAI API KEY")
Enter fullscreen mode Exit fullscreen mode

if api:: Checks if an API key is entered.

openai_model = OpenAIModel(): If a key is entered, creates an OpenAIModel object with the provided API key, model parameters (gpt-4-turbo-preview, temperature, max_tokens).
else: If no key is entered, displays an error message in the sidebar.

mindmap_generator function:

def mindmap_generator(topic):
    mindmap_agent = Agent(
        prompt_persona=f"You are an Expert in system design.",
        role="System Designer",
    )

    mindmap_task = Task(
        name="content writer",
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
        model=openai_model,
        agent=mindmap_agent,
        log_output=True,
        instructions=f"""
        Generate a Mindmap in given format for {topic}.
        mindmap in top is compulsory.
        format:
        "
        mindmap
          school_management
            administration
                staff_management
                    recruitment
                    training
                    scheduling
                student_management
                    enrollment
                    attendance
                    discipline
                facilities_management
                    maintenance
                    safety
                    supplies
            academics
                curriculum_development
                    syllabus_planning
                    material_selection
        "

        ONLY GENERATE MINDMAP CODE NOTHING ELSE APART FROM IT
        """,
    )

    output = LinearSyncPipeline(
        name="Mindmap Generation",
        completion_message="Mindmap Generated!",
        tasks=[
            mindmap_task
        ],
        ).run()
    return output[0]['task_output']
Enter fullscreen mode Exit fullscreen mode

This function defines the core logic for generating mindmaps.

An Agent object is created using Agent with a prompt persona describing the role and expertise ("You are an Expert in system design."/"System Designer").
A Task object is created using Task specifying various attributes:
name: "content writer" (descriptive name for the task).
output_type: OutputType.TEXT (specifies the task's output format).
input_type: InputType.TEXT (specifies the task's expected input format).
model: The openai_model object created earlier (defines the AI model to be used).
agent: The mindmap_agent object (defines the persona for task execution).
log_output: True (enables logging of the task's output).
instructions: This is a multi-line string containing detailed instructions for the AI model. It specifies the task as generating a mindmap in a specific format for a given topic. It emphasizes that only mindmap code should be generated and excludes other information.
A LinearSyncPipeline object is created using LinearSyncPipeline with:
name: "Mindmap Generation" (descriptive name for the pipeline).
completion_message: "Mindmap Generated!" (message displayed upon task completion).
tasks: A list containing the single mindmap_task defined earlier.
The run method of the pipeline is called, executing the defined task and returning the output.
The function returns the first element’s (task_output) from the pipeline output, which is the generated mindmap text.

User Input and Button:

topic = st.text_input("Enter Topic")

if st.button("Generate"):
    solution = mindmap_generator(topic)
    st.markdown(solution)
Enter fullscreen mode Exit fullscreen mode

topic = st.text_input("Enter Topic"): Creates a text input field for the user to enter the presentation topic.
if st.button("Generate"): Creates a button labeled "Generate". When clicked, this block executes:
solution = presentation_maker(topic): Calls the presentation_maker function with the entered topic.
st.markdown(solution): Displays the generated Python code as markdown, allowing for proper formatting and code highlighting.

Visualizing the Mind Map via Mermaid

  1. Navigate to Mermaid Live Editor: Access the Mermaid Live Editor online.

Mermaid Live Editor

  1. Insert the Notation: Enter the mindmap notation generated by ChatGPT into the editor.

  2. Render the SVG: Click on the render function. Once visualized, you can opt to save the graphic in SVG format.

Mindmap generated by OpenAI

try it now: https://github.com/harshit-lyzr/mindmap_generator

For more information explore the website: Lyzr

Contibute to Our Project: https://github.com/LyzrCore/lyzr-automata

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

This is baffling.

A mind map is a way to get your own thoughts down in a visual representation. This, by definition, is something that doesn't lend itself to automation... especially by AI, that understands essentially nothing - let alone your own thought processes.

If you find making a mind map 'tedious', I would seriously question your reasons for making it.