Boost Your Filmmaking Workflow: Create Storyboards and Write Scenes using Lyzr-Automata
Tags: chatgpt, machinelearning, python, deeplearning
Published: 2024-03-27 04:45:37

Ever stare at your script or storyboard feeling like nothing clicks? We all hit our creative rut and some point. But what if you can make use of AI to break free? In this blog post, we’ll take a look how **Lyzr-Automata** can help us with it.

## Setup
Create a folder, set up a virtual environment and activate it. Create `.env` file with your _OPENAI_API_KEY_. Then install the following libraries to get started.
### Libraries

- `streamlit`: for building the web app interface.
- `lyzr_automata` : for implementing our AI models, and tasks.
- `dotenv`: for loading environment variables (API key).

```
lyzr-automata==0.1.2
streamlit==1.32.2
python-dotenv==1.0.1
```
## Getting Started
**1.Import Libraries**

```python
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
import os

import streamlit as st

load_dotenv()

# LOAD OUR API KEY
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
```
**2. Setup interface using Streamlit**
- `st.text_area` — Text area to enter scene description ([Link](https://docs.streamlit.io/library/api-reference/widgets/st.text_area))
- `st.button` — Button to submit input ([Link](https://docs.streamlit.io/library/api-reference/widgets/st.button))
- `st.write` — Display text ([Link](https://docs.streamlit.io/library/api-reference/write-magic/st.write))
- `st.image` — Display an image ([Link](https://docs.streamlit.io/library/api-reference/media/st.image))

```python
input_scene = st.text_area("Enter Scene Description")

button=st.button('Submit')
if (button==True):
    # CALL FUNCTION TO GENERATE OUTPUT
    generated_output = storyboard_generator(input_scene)
    
    # DISPLAY OUTPUT
    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='Storyboard')
```
**3. Create our AI Models**
- `OpenAIModel` — Create our models using OpenAI Key and specify the model type and name.

```python
# DALLE 3 Image Model
open_ai_model_image = OpenAIModel(
    api_key=OPENAI_API_KEY,
    parameters={
        "n": 1,
        "model": "dall-e-3",
    },
)
```
```python
# GPT 4 Text Model
open_ai_model_text = OpenAIModel(
    api_key= OPENAI_API_KEY,
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.5,
        "max_tokens": 1500,
    },
)
```
**4. Storyboard Generator Function**
- `Agent` — _screenplay_writer_agent_, create a Lyzr Agent for text creation and set persona.
- `Task` — _screenplay_content_task_, create Lyzr Task with scene description input, instructions and Text Agent. Define Input and Output types as well.
- `Task` — _storyboard_creation_task_, create another Lyzr Task with scene description input, instructions and Image Model.
- `LinearSyncPipeline` — Pass the Text Task first followed by the Image Task, enabling them to execute in sequence and ensure flow of data.

```python
def storyboard_generator(input_content):
    # Screenplay Writer Agent
    screenplay_writer_agent = Agent(
        prompt_persona="You are an intelligent Screenplay writer good at writing a short and detailed scene",
        role="Screenplay writer",
    )

    # Write Screenplay Task
    screenplay_content_task = Task(
        name="Screenplay Content Creator",
        agent=screenplay_writer_agent,
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
        model=open_ai_model_text,
        instructions="Use the scene description provided and write 4 shots for a movie in 200 words. Use your creativity. [IMPORTANT!] Setup the location and characters in a detailed manner",
        log_output=True,
        enhance_prompt=False,
        default_input=input_content
    )

    # Generate Storyboard
    storyboard_creation_task = Task(
        name="Storyboard Image Creation",
        output_type=OutputType.IMAGE,
        input_type=InputType.TEXT,
        model=open_ai_model_image,
        log_output=True,
        instructions="Generate a set of 4 storyboard drawings for the given scene description. Capture every detail. Minimalistic style. [IMPORTANT!] Avoid any text or numbers in the image.",
    )

    logger = Logger()
    # Linear Pipeline to run tasks
    main_output = LinearSyncPipeline(
        logger=logger,
        name="Generate Storyboard",
        completion_message="Storyboard Generated!",
        tasks=[
            screenplay_content_task,
            storyboard_creation_task,
        ],
    ).run()

    return main_output
```
**5. Run App**

```
streamlit run <app_name.py>
```
## OUTPUT
_My Input = “a man and woman argue in an alley while i watch it and walk past”_

![Output Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qudt5hp6rmrp0yxu1q26.png)
## Flow Diagram

![Flow diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wnvgzmr4nf78jkfl5985.jpg)

Want to create more of such amazing AI Workflows? Visit our website at **[GitHub](https://github.com/LyzrCore/lyzr-automata)** to learn more about Lyzr-Automata!

Also checkout Lyzr SDKs at **[GitHub](https://github.com/LyzrCore/lyzr)**

**Lyzr Website**: [Lyzr.ai](https://www.lyzr.ai/)
**Lyzr Community Channel**: [Discord](https://discord.com/invite/nm7zSyEFA2)

**Code**: https://github.com/LyzrCore/lyzr-automata/tree/main/examples/storyboard_generator
**Video Walkthrough**: https://tella.video/storyboard-generator-8fpi