How to use AI to create a PowerPoint presentation?

blog preview

Creating effective PowerPoint presentations is an important skill for professionals and students alike. Well-designed slides can help engage your audience and clearly communicate your message. While it still takes careful planning and an understanding of your audience to make a great presentation, AI might be able to help with the more time consuming, but less important aspects of the process.

Large Language Models (LLMs) like GPT-4, developed by companies like OpenAI, are one example of an AI technology that could potentially assist with presentation creation. These models can generate human-like text based on prompts, which might be useful for brainstorming content ideas or fleshing out speaker notes.

While these Use-Cases are quite mainstream - using ChatGPT to generate presentation ideas, it's ability to generate code snippets might be useful to not only create the text snippets for a presentation - but the full presentation itself.

In this blog post we are going to explore the capabilities of using GPT-4 to create a fully-fledged PowerPoint presentation. Not only that - we are also showing you how to leverage GPT-4 to use your company's PowerPoint template and therefore stick to your company's design guidelines.

How to use GPT-4 to create a PowerPoint presentation

What we are going to build

To demonstrate and validate GPT-4s capabilities in creating PowerPoint presentations and even using corporate design guidelines, we are going to build a small python script that generates a PowerPoint presentation based on given prompts.

While this might already impress some of our readers, the more experienced AI professionals might rightfully ask: "How do you make sure that the PowerPoint presentation is about the right topic?". This is a more than valid question - as GPT-4 in general might not know the specifics of your company or topic - and therefore might hallucinate some content.

To mitigate this risk - and in general provide GPT-4 with the information it needs - we are going to connect our PowerPoint generator with a small Retrieval Augmented Generation pipeline. As the latter allows us to safely and reliably connect GPT-4 with our company's data.

Outline for using GPT-4 to create PowerPoint presentations

The system we are going to implement is summarized in the following steps:

  1. We create a small python script that connects to the OpenAI API and allows us to get answers from GPT-4 by providing a prompt.

  2. We create a small Retrieval Augmented Generation pipeline which allows us to retrieve relevant information and data from our company's data sources.

  3. We create a prompt that asks GPT-4 to generate a PowerPoint presentation based on provided information. We ask GPT-4 to use a package called python-pptx to create the PowerPoint presentation.

    python-pptx is a python package that allows you to create PowerPoint presentations programmatically. It is a great tool to create PowerPoint presentations from scratch or to modify existin presentations.

  4. We connect the 3 previous components as follows:

    a. We use the user prompt - so the specification of what the presentation should be about - to query the Retrieval Augmented Generation pipeline.

    b. We use the output of the Retrieval Augmented Generation pipeline and send it to GPT-4. We use a prompt asking to generate a python-pptx-powered python script that creates a PowerPoint presentation.

    c. We execute the generated python script and create the PowerPoint presentation.

  5. As an add-on, we'll evaluate, whether we are able to use existing PowerPoint templates to create the presentation - and stick to corporate design guidelines.

Retrieval Augmented Generation enhanced PowerPoint creation with AIRetrieval Augmented Generation enhanced PowerPoint creation with AI

Preparation

As we make use of the programming capabilities of GPT-4, we require a working python 3.11 environment. We recommend using a virtual environment to keep your dependencies clean.

Other then that, you just need:

  • A PowerPoint 2007 or newer installation
  • A PowerPoint template file
  • An OpenAI api key

Install the required python packages by running:

1
2pip install python-pptx llama_index

Implementation of the PowerPoint generator

As creating the presentation itself is the most critical part, we are going to start with that aspect.

To not overwhelm the AI with too many tasks in one go, we divide the challenge into two parts:

  • Structuring the information into presentation material
  • Using that material to create the presentation
  1. Import the required packages:
1from llama_index.core import PromptTemplate
2from llama_index.llms.openai import OpenAI
3from llama_index.core import SimpleDirectoryReader
4from llama_index.core import VectorStoreIndex
5import json
6import re
  1. Create a prompt template that asks GPT-4 to structure the provided information into presentation material:

    1 prompt = """
    2 You are a power point presentation specialist. You are asked to create
    3 the content for a presentation about {topic}.
    4 You have been given the following information to create a presentation:
    5 ---
    6 {information}.
    7 ---
    8 Structure the information in a way that it can be put in a power point
    9 presentation. Each slide should have a title and content, with the content
    10 being a summary of the information provided. Each slide should have one or
    11 more sentences that capture the key points of the information.
    12 Return the structured information as a JSON as follows.
    13 Your answer should only contain the JSON - no markdown formatting.
    14 """
    15 prompt_template = PromptTemplate(prompt)
    16 prompt_examples = """
    17 Example:
    18 {"slides": [
    19 {"title": "Slide 1", "content": "Content for slide 1"},
    20 {"title": "Slide 2", "content": "Content for slide 2"},
    21 {"title": "Slide 3", "content": "Content for slide 3"},
    22 ]}
    23 """

    NOTE: There are several ways for asking GPT-4 to return JSON objects. One of them would be function calling or llama_index' structured prediction functionalities. However, as of time of this writing, there was a problem with GPT-4 where function calling was not working reliably, that's why we opted for the few-shot prompt above.

  2. Let's create some test information and test topic to test the prompt. We will change this later on to use the output of the retrieval augmented generation pipeline.

    1test_topic = "the benefits of exercise"
    2test_information = """
    3Exercise plays a crucial role in maintaining both physical and mental health.
    4Engaging in regular physical activity can significantly reduce the risk of
    5chronic diseases such as heart disease, diabetes, and obesity. It also enhances
    6muscular strength, flexibility, and endurance. Beyond physical benefits, exercise
    7contributes to improved mental health by reducing symptoms of depression and anxiety,
    8boosting mood through the release of endorphins, and improving cognitive function.
    9It fosters a sense of well-being and can be a great way to manage stress.
    10Overall, incorporating exercise into one's daily routine is a key factor in
    11achieving a healthier and more balanced lifestyle.
    12"""
    13
    14content_prompt = (
    15 prompt_template.format(topic=test_topic, information=test_information)
    16 + prompt_examples
    17)
  3. Create the LLM inference code

    1api_key = os.getenv("OPENAI_API_KEY")
    2llm = OpenAI(model="gpt-4o", api_key=api_key)
    3llm.complete(content_prompt, True)

    The output of this call should be a JSON formatted text, containing a list of slides with titles and content.

  4. Create another LLM inference pipeline, that uses these information to create a PowerPoint slide-deck.

    1powerpoint_prompt = """
    2You are a PowerPoint presentation specialist. You'll get a list of slides, each
    3slide containing a title and content. You need to create a PowerPoint presentation
    4based on the provided slides.
    5But there is a catch: Instead of creating the presentation, provide python code
    6that generates the PowerPoint presentation based on the provided slides.
    7Use the package python-pptx to create the PowerPoint presentation.
    8The presentation should be visually appealing and professionally designed.
    9
    10If the slides content contains more than one information, make bullet points.
    11Save the presentation as 'presentation.pptx'.
    12
    13Your answer should only contain the python code, no explanatory text.
    14
    15Slides:
    16
    17"""
    18
    19presentation_code = llm.complete(powerpoint_prompt + str(slides), True).text
    20
    21match = re.findall(r"python\n(.*?)\n```", presentation_code, re.DOTALL)
    22python_code = match[0]
  5. Execute the generated python code to create the PowerPoint presentation.

    1exec(python_code)

    This will create a file called presentation.pptx in the current working directory. Have a look at the file to see the generated presentation.

    Quite impressive right? We are able to generate PowerPoint presentations based on a given topic and information - all automatically from an AI.

So far so good, up until now we know how to utilize GPT-4 to create a PowerPoint presentation, when presented with a topic and some information.

Next, instead of providing hard-coded information, let's use the retrieval augmented generation pipeline to provide the information to GPT-4.

Implement the retrieval augmented generation pipeline

In this next section, we are going to simulate our companies data repository by using a simple directory. We assume, our companies documents are all stored there.

We are going to use the llama_index package to index the documents and retrieve the relevant information for the topic we want to create presentations for.

As example document we are using a very well-known Paul Graham essay about his life - and ask GPT-4 to create a presentation on Paul Graham.

  1. Download the sample document

    1mkdir -p 'data/paul_graham/'
    2wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'
  2. Load all files in our directory

    1reader = SimpleDirectoryReader(
    2 input_files=["./data/paul_graham/paul_graham_essay.txt"]
    3 )
    4docs = reader.load_data()
    5index = VectorStoreIndex.from_documents(docs)
  3. Now that we created our vector store, we can use it to retrieve information relevant for our presentation. For that, let's set up our embedding model as well as our vector retriever.

    NOTE: In this guide we assume you know how RAG works. For a primer to what RAG is and how it works, see here

    1 docs = reader.load_data()
    2 embed_model = OpenAIEmbedding(api_key=api_key)
    3 Settings.embed_model = embed_model
    4 index = VectorStoreIndex.from_documents(docs)
    5
    6 retriever = index.as_retriever(similarity_top_k=5)
  4. And finally, we can define our topic, and find all relevant information for it.

    1 topic = "Paul Grahams life and what he worked on"
    2 relevant_information = retriever.retrieve(topic)

    relevant_information contains information related to the specified topic about Paul Grahams life.

Combining the RAG pipeline with PowerPoint creation

We are getting somewhere, aren't we? We know, how to create presentations and we know how to efficiently retrieve information for this presentation. Let's stick it together. This is rather easy, as we can reuse code from the previous sections.

1# Continue from previous chapter
2information = "\n---\n".join([res.text for res in response])
3
4content_prompt = (
5 prompt_template.format(topic=topic, information=information) + prompt_examples
6)
7
8slides = json.loads(llm.complete(content_prompt, True).text)
9
10
11powerpoint_prompt = """
12You are a PowerPoint presentation specialist. You'll get a list of slides, each
13slide containing a title and content. You need to create a PowerPoint presentation
14based on the provided slides.
15But there is a catch: Instead of creating the presentation, provide python code
16that generates the PowerPoint presentation based on the provided slides.
17Use the package python-pptx to create the PowerPoint presentation.
18The presentation should be visually appealing and professionally designed.
19
20If the slides content contains more than one information, make bullet points.
21
22Your answer should only contain the python code, no explanatory text.
23
24Slides:
25
26"""
27
28presentation_code = llm.complete(powerpoint_prompt + str(slides), True).text
29
30match = re.findall(r"python\n(.*?)\n```", presentation_code, re.DOTALL)
31python_code = match[0]
32
33exec(python_code)

Isn't that amazing? We just created a quite monumental presentation about Paul Grahams life in about 10 seconds.

I'll give you that - it's not the most enticing presentation of all time and it probably needs some minor refinements. But - it's definitely incredibly helpful to get a presentation with all relevant (and factual correct!) information as a starting point.

One thing however which is kinda annoying and hinders further productive use is the lack of styling and corporate design. Let's fix this quickly.

Use GPT-4 to create PowerPoint presentation with corporate design

So, the holy grail, creating PowerPoint presentation with corporate design. First things first, we will now convince GPT-4 to design a PowerPoint presentation based on our written input.

However, we will be able to use a PowerPoint template as base presentation - GPT-4 then adds the content to this template. This is factually the same result - a presentation designed in our corporate design language.

  1. Create a PowerPoint template and save it in your current working directory as 'template.pptx'.

  2. Slighly change the PowerPoint creation prompt as follows

    1powerpoint_prompt = """
    2You are a PowerPoint presentation specialist. You'll get a list of slides, each
    3slide containing a title and content. You need to create a PowerPoint presentation
    4based on the provided slides.
    5But there is a catch: Instead of creating the presentation, provide python code
    6that generates the PowerPoint presentation based on the provided slides.
    7Use the package python-pptx to create the PowerPoint presentation.
    8In your code, use a file called 'template.pptx' as the template for the presentation
    9and stick to the template's design.
    10
    11If the slides content contains more than one information, make bullet points.
    12
    13Your answer should only contain the python code, no explanatory text.
    14
    15Slides:
    16
    17"""
    18
    19presentation_code = llm.complete(powerpoint_prompt + str(slides), True).text
    20
    21match = re.findall(r"python\n(.*?)\n```", presentation_code, re.DOTALL)
    22python_code = match[0]
    23
    24exec(python_code)
  3. Run the code again.

That's it. All we needed was to tell GPT-4 to actually use our template - and it happily obliged. I like it when life's that simple.

And the output looks absolutely stunning. We have a presentation about Paul Graham in our corporate design language. And all of that in less than 10 seconds.

Paul Graham presentation in corporate designPaul Graham presentation in corporate design

NOTE: If you get an error "Package not found" when running the last line in the code example, its because the "template.pptx" is not in the same location as where you run the script. Make sure to move the template to the correct location.

Conclusion

In summary, using AI tools like GPT-4 to create PowerPoint presentations can save time and ensure that slides follow your company's design templates. This blog post showed a reliable way to use GPT-4 to automatically make presentations that look good and have relevant content, based on your company's slide templates. By using AI to help make presentations, you can spend more time on delivering your message instead of manually putting together slides. AI can generate content that fits the context and, when combined with fact-checking against reliable sources, will produce slides that are not only visually appealing but also accurate and on-topic. This method saves time and uses AI's capabilities to improve the overall quality of business presentations. As AI keeps advancing, using it for common work tasks like making PowerPoint slides is changing how we create and share information, making AI a valuable tool for professional communication.

As AI keeps getting better, it will keep being used for everyday tasks like this. It will make things more efficient and also give us new ways to be creative and personalize how we share ideas through presentations.

Further Reading

Interested in how to train your very own Large Language Model?

We prepared a well-researched guide for how to use the latest advancements in Open Source technology to fine-tune your own LLM. This has many advantages like:

  • Cost control
  • Data privacy
  • Excellent performance - adjusted specifically for your intended use
More information on our managed RAG solution?
To Pondhouse AI
More tips and tricks on how to work with AI?
To our Blog