DEV Community

Cover image for Simplify Instagram Content Creation with Caption Studio by Lyzr.ai
Prajjwal Sule
Prajjwal Sule

Posted on

Simplify Instagram Content Creation with Caption Studio by Lyzr.ai

In the digital age, Instagram has emerged as a powerful platform for individuals and businesses alike to connect with their audience. However, creating engaging content can be a daunting task. Enter Caption Studio by Lyzr.ai, an AI-powered tool designed to streamline the process of generating creative captions and images for Instagram posts.

In this article, we'll explore how Caption Studio simplifies content creation for Instagram, making it easier for users to craft catchy captions and eye-catching images.

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

Lyzr offers an agent-centric approach to rapidly developing LLM (Large Language Model) applications with minimal code and time investment. Even if you’re unfamiliar with the GenAI stack, Lyzr empowers you to build your AI applications effortlessly.

Setting up the Project

Let's start by setting up the project for Caption Studio:

Clone the Caption Studio app repository

   git clone https://github.com/PrajjwalLyzr/Caption-Studio
Enter fullscreen mode Exit fullscreen mode

Create a virtual environment and activate it

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

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 the required dependencies

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

Project Structure

The project structure consists of the following files:

Caption-Studio


├── app.py

├── README.md

├── .gitignore

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

An entry point for an application ‘app.py’

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
from PIL import Image
import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent, Task
from lyzr_automata.tasks.task_literals import InputType, OutputType
from lyzr_automata.pipelines.linear_sync_pipeline  import  LinearSyncPipeline
from lyzr_automata import Logger
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 Caption Studio

Initializes two instances of the OpenAIModel class, which facilitates 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 Caption Studio 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 ig_caption_studio(input_content):
    social_media_manager_agent = Agent(
        prompt_persona="You are an expert social media manager good at writing a short and catchy instagram captions, as well creating the intagram images",
        role="social media manager",
    )

    instagram_caption_task = Task(
        name="Instagram Caption Creator",
        agent=social_media_manager_agent,
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
        model=open_ai_model_text,
        instructions="Use the description provided and write some set of catchy 5-7 Instagram captions in 20-30 words. Use your creativity. [IMPORTANT!] Setup the events in a detailed manner",
        log_output=True,
        enhance_prompt=False,
        default_input=input_content
    )

    instagram_image_task = Task(
        name="Instagram Image Creation",
        output_type=OutputType.IMAGE,
        input_type=InputType.TEXT,
        model=open_ai_model_image,
        log_output=True,
        instructions="Generate an Instagram image for 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="Caption Generator",
        completion_message="IG Caption and Image Generated!",
        tasks=[
            instagram_caption_task,
            instagram_image_task,
        ],
    ).run()

    return main_output
Enter fullscreen mode Exit fullscreen mode

Executing the Application

To run the Caption Studio application:

if __name__ == "__main__":
    caption_brief = st.text_area("Enter about caption")
    button = st.button('Submit')
    if button:
        generated_output = ig_caption_studio(caption_brief)
        text_output = generated_output[0]['task_output']
        st.write(text_output)
        image_file_name = generated_output[1]['task_output'].local_file_path
        st.image(image_file_name, caption='Caption Studio')
Enter fullscreen mode Exit fullscreen mode

Caption Studio by Lyzr.ai revolutionizes Instagram content creation, making it easier and more efficient. With AI-powered tools like Caption Studio, users can create captivating captions and images with ease.

References

Top comments (0)