DEV Community

Cover image for Generate PowerPoint Presentation with OpenAI- The Future of Slide Decks
harshit-lyzr
harshit-lyzr

Posted on

Generate PowerPoint Presentation with OpenAI- The Future of Slide Decks

Presentations are pivotal in various corporate settings, from pitching ideas to stakeholders and conducting training sessions to reporting quarterly results. They serve as visual aids that enhance the understanding and retention of information. A good presentation can significantly influence decisions, motivate teams, and drive projects forward. Given their impact, ensuring presentations are engaging, informative, and professional is crucial.

However, the challenge lies in the time and effort required to create such presentations. Crafting a presentation involves several steps, including content generation, design, formatting, and revision. This process can be particularly daunting for those who lack design skills or are pressed for time. This is where the "Presentation Maker" app comes into play.

Creating presentations can be a time-consuming task, especially when it comes to generating content and ensuring that it's both engaging and informative. This is where the power of automation comes into play. By leveraging Lyzr Automata and OpenAI, we've developed a streamlined application that automates the creation of presentation slides, allowing users to focus on refining and delivering their content.

Lyzr Automata and OpenAI
Lyzr Automata is a powerful tool designed for automating various tasks, and when combined with OpenAI's capabilities, it becomes a formidable solution for generating presentation content. Our application utilizes these technologies to create a seamless experience for users.

Key Features:
User-Friendly Interface: The application is built using Streamlit, providing a clean and intuitive interface. Users can easily input their OpenAI API key and topic of interest.
Automated Content Generation: By defining specific tasks for content creation and Python code generation, the application automates the process of drafting slide content and generating the corresponding Python-pptx code.
Customizable and Extendable: Users can tweak the OpenAI parameters and the task instructions to fit their specific needs, making the solution highly customizable.

Step-by-Step Process
Input OpenAI API Key: Users input their OpenAI API key through a secure sidebar text input. This ensures that the application can access OpenAI's models to generate content.
Enter Topic: Users provide the topic for their presentation. This topic serves as the basis for generating slide content.
Generate Presentation: Upon clicking the "Generate" button, the application initiates a series of tasks:

Content Writing: The first task generates a slide header and bullet points based on the provided topic.
Python Code Generation: The second task takes the generated content and produces Python-pptx code to create a slide.
Display the Output: The final Python code is displayed on the interface, ready for users to run and create their presentation slides.

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.

presentation_maker Function:

def presentation_maker(topics):
    content_agent = Agent(
        prompt_persona=f"You are a Content writer.",
        role="Content writer",
    )

    content_task = Task(
        name="content writer",
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
        model=openai_model,
        agent=content_agent,
        log_output=True,
        instructions=f"""
        write a Header and 4 bullet points for given {topics}.
        Bullet point is not more then 10 words.
        """,
    )

    python_agent = Agent(
        prompt_persona=f"You are a Python Developer.",
        role="Python Developer",
    )

    python_task = Task(
        name="content writer",
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
        model=openai_model,
        agent=python_agent,
        input_tasks=[content_task],
        log_output=True,
        instructions=f"""
            We have provided with header and 4 bullet points.
            please generate python-pptx code for a single slide with this header & bullet points.
            Separate the bullet points into separate texts.
            Do not set font size.
            Only generate code nothing else.
            """,
    )

    output = LinearSyncPipeline(
        name="Presentation Generation",
        completion_message="Presentation Generated!",
        tasks=[
            content_task,
            python_task
        ],
        ).run()
    return output[1]['task_output']
Enter fullscreen mode Exit fullscreen mode

Defines the core logic for generating Python code for a presentation slide:
content_agent: Creates an Agent object representing a content writer persona.
content_task: Creates a Task object with the following properties:
name: "content writer"
output_type: OutputType.TEXT (textual output)
input_type: InputType.TEXT (textual input)
model: openai_model (the OpenAI model object)
agent: content_agent (the content writer agent)
log_output: True (logs task output for debugging)
instructions: Prompts the model to create a header and 4 bullet points for the given topic, with each bullet point not exceeding 10 words.
python_agent: Creates an Agent object representing a Python developer persona.
python_task: Creates a Task object with the following properties:
name: "content writer" (same name as before, likely due to a typo)
output_type: OutputType.TEXT (Python code as text)
input_type: InputType.TEXT (text input from the content_task)
model: openai_model
agent: python_agent
input_tasks: List containing the content_task
LinearSyncPipeline:
Creates a LinearSyncPipeline object named output.
Sets the completion_message to be displayed when the pipeline finishes execution.
Defines a list of tasks to be run in sequence:
content_task: Creates the header and bullet points.
python_task: Generates the Python code based on the task output.
.run(): Executes the LinearSyncPipeline with the defined tasks.
return output[1]['task_output']: Returns the output (Python code) generated by the second task (python_task).

User Input and Button:

topic = st.text_input("Enter Topic")

if st.button("Generate"):
    solution = presentation_maker(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.

Image description

Enhancing Productivity
This automated approach to presentation creation significantly enhances productivity. Instead of manually researching and drafting content, users can quickly generate a structured outline and corresponding slide code. This leaves more time for refining the presentation's delivery and design aspects.

Future Possibilities
The current implementation focuses on generating content and code for a single slide. However, the framework can be extended to create multi-slide presentations, incorporate different content types, and even include design elements such as themes and layouts. With ongoing advancements in AI and automation tools, the possibilities for enhancing presentation creation are vast.

try it now: https://github.com/harshit-lyzr/presentation_maker
For more information explore the website: Lyzr
Contibute to Our Project: https://github.com/LyzrCore/lyzr-automata

Top comments (0)