Designing Interior Using Lyzr Automata and Dalle 3
Published: 2024-05-03 05:19:15

Are you looking to revamp your living space but struggling to visualize your ideas? Introducing the Lyzr Interior Designer, an innovative solution powered by Lyzr Automata and Streamlit. With just a few clicks, transform your vision into stunning interior designs tailored to your preferences. Let's delve into how this app works and how it can revolutionize your home decor experience.

The Lyzr Interior Designer simplifies the interior design process by harnessing the capabilities of Lyzr Automata, an Agentic AI platform. Users can specify their preferred style, room type, and any additional instructions through an intuitive interface built with Streamlit. The app then leverages the power of OpenAI's models to generate custom interior designs based on these inputs.

**Features and Benefits**
Personalized Designs: Tailor your interior design to reflect your individual style and preferences, whether you prefer a sleek modern look or a cozy tropical vibe.
Effortless Process: Say goodbye to the hassle of endless design iterations. The Lyzr Interior Designer streamlines the design process, allowing you to effortlessly generate inspiring interiors in minutes.
AI-Powered Creativity: Harness the power of artificial intelligence to explore endless design possibilities. Lyzr Automata's advanced algorithms ensure each design is both innovative and visually captivating.
Interactive Experience: With an intuitive user interface built on Streamlit, navigating the design process is seamless and enjoyable. Visualize your ideas in real-time and make informed decisions about your space.

**Setting Up the Environment**
**Imports:**

```
pip install lyzr_automata streamlit python-dotenv
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
from dotenv import load_dotenv
from lyzr_automata.tasks.task_literals import InputType, OutputType
import os

load_dotenv()
api = os.getenv("OPENAI_API_KEY")
```
streamlit as st: for building the Streamlit web app interface.
lyzr_automata libraries for working with Lyzr Automata, including:
Agent and Task: for defining roles and tasks within the automation process.
LinearSyncPipeline: to run a sequence of tasks in a linear fashion.
OpenAIModel: to interact with the OpenAI API for image generation
PIL.Image: for handling image processing.
dotenv: for loading environment variables (likely containing the OpenAI API key).
load_dotenv() reads environment variables from a .env file (likely containing the API key).
api stores the retrieved OpenAI API key from the environment.

**User Input:**

```
style = st.sidebar.selectbox("Style", ("Modern","Minimalistic","Tropical","Coastal","Futuristic","Cyberpunk"))
room = st.sidebar.selectbox("Room", ("Living Room","Bedroom","Bathroom","Outdoor Garden","House Exterior"))
instruction = st.sidebar.text_area("Enter your Instruction: ")
```
style = st.sidebar.selectbox: Creates a dropdown menu for selecting design style (Modern, Minimalistic, etc.).
room = st.sidebar.selectbox: Creates a dropdown menu for selecting the room type (Living Room, Bedroom, etc.).
instruction = st.sidebar.text_area: Creates a text area for users to enter specific design instructions.

**generate_image function:**

```
def generate_image(style, room_type, insights):
    artist_agent = Agent(
        prompt_persona="You are an Interior Designer.Your Task Is to generate Interior from given Instructions.",
        role="Artist",
    )

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

    interior_task = Task(
        name="Art Image Creation",
        output_type=OutputType.IMAGE,
        input_type=InputType.TEXT,
        model=open_ai_model_image,
        agent=artist_agent,
        log_output=True,
        instructions=f"""Your Task Is To Generate Interior Design.

            Follow Below Instructions for Interior Design:
            {style} style ({room_type}) with {insights}
            """,
    )

    output = LinearSyncPipeline(
        name="Generate Interior",
        completion_message="Interior Generated!",
        tasks=[
            interior_task
        ],
    ).run()
    return output[0]['task_output'].url
```
This function takes style, room_type, and insights (currently unused) as input and generates an image using Lyzr Automata.
artist_agent: Defines an agent with a specific persona and role ("Artist") for interacting with the model.
open_ai_model_image: Creates an OpenAI model object using the provided API key and sets parameters for Dall-E-3.
interior_task: Defines the task details:
name: "Art Image Creation".
output_type: Output format (set to OutputType.IMAGE).
input_type: Input format (set to InputType.TEXT).
model: The OpenAI model object created earlier.
agent: The artist agent defined earlier.
log_output: Set to True to log the model output.
instructions: A formatted string containing style, room type, and instructions (including placeholder for insights).
LinearSyncPipeline: Creates a pipeline named "Generate Interior" with a completion message and a list containing the defined interior_task.
.run(): Executes the pipeline, running the defined task.
The function returns the URL of the generated image from the task output.

**Button and Image Display:**

```
if st.sidebar.button("Generate"):
    solution = generate_image(style, room, instruction)
    st.image(solution)
```
if st.sidebar.button("Generate"): Creates a button in the sidebar labeled "Generate".
If the button is clicked:
solution = generate_image(style, room, instruction): Calls the generate_image function with user-selected options.
st.image(solution): Displays the generated image on the app page.

try it now: [https://lyzr-interior-designer.streamlit.app/](https://lyzr-interior-designer.streamlit.app/)
For more information explore the website: [Lyzr](https://www.lyzr.ai/)