DEV Community

Cover image for I wrote this AI tool under 50 lines of code that makes PPT slides automatically 🔥🚀
Sunil Kumar Dash for Composio

Posted on

I wrote this AI tool under 50 lines of code that makes PPT slides automatically 🔥🚀

TL;DR

Everyone hates making presentation slides; if you are not, you should. But hey, that’s not how the world works. It does not matter if you are an academic or in industry. Power-point presentations are inevitable.

Still, it is boring. As also said by the wise Mr. Dwight Schrute.

Dwight Schrute on Powerpoint

So, I built an AI-powered tool to create PPTs from datasets automatically.

Here is what it does.

  • The tool can access Google Sheets to retrieve data.
  • Transform the raw data into actionable insights by generating charts and critical points using a Python-pptx library.
  • Automatically creates visually appealing slides based on the data.

Tech Stack

Here are the libraries we will need to accomplish this.

  • Composio: This is for integrating Google Sheets and a code interpreter.
  • CrewAI: Framework for building automated AI applications.

Composio - The tooling platform for AI apps

Here is a quick introduction to Composio.

It is an open-source platform offering tooling solutions for building AI apps. It lets you integrate third-party applications like GitHub, Jira, Linear, and Slack to create AI software engineers, GitHub PR agents and many more.

Composio houses over 100 tools and integrations, allowing developers to build comprehensive AI automation software.

Guy Struggling at a beach

Please help us with a star. 🥹

It would help us to create more articles like this 💖

Star the Composio repository ⭐


CrewAI - Framework for building AI automation

CrewAi is an open-source framework for building powerful AI agents with ease. It supports all the popular LLM inference providers, such as OpenAI, Anthropic, Google, Groq, and more.

Learn more about CrewAI here.


Workflow Overview

Here is what the Agent will do.

  • Fetch data from a Google spreadsheet.
  • Understand the context of the dataset.
  • Create plots and graphs by executing codes using a code interpreter.
  • Finally, it creates PowerPoint slides using the python-pptx library.

Powepoint(PPT) agent workflow


Let’s get started!

Begin by creating a virtual environment, like with any Python project.

python -m venv ppt-agent
cd ppt-agent
source bin/activate
Enter fullscreen mode Exit fullscreen mode

Next, install the following dependencies.

composio-crewai
langchain-openai
python-dotenv
Enter fullscreen mode Exit fullscreen mode
  • Composio-core: The core library for integrating tools and applications with AI applications.
  • langchain-openai: For accessing OpenAI models.
  • python-dotenv: For loading .env variables to the local shell environment.

Next, Create a .env file and add environment variables for the OpenAI API key.

OPENAI_API_KEY=your API key
Enter fullscreen mode Exit fullscreen mode

To create an OpneAI API key, go to the official site and create an API key in the dashboard.

OpenAI API key


Set up Composio

Next, you need to log in and authenticate with Composio.

composio login
Enter fullscreen mode Exit fullscreen mode

This will open a tab asking you to log in. You can log in with GitHub, Gmail, or any Email ID.

Composio Login Page

Upon logging in, a screen with a key will appear.

Composio Authentication Key

Copy it and paste it into the terminal.

Now, update apps.

composio apps update
Enter fullscreen mode Exit fullscreen mode

Next, integrate Google Sheet.

composio add googlesheet
Enter fullscreen mode Exit fullscreen mode

You will be prompted to grant permission. Approve it, and you are all set.

Google Sheet permission page

Once you have added the integration, you can monitor it from your Composio dashboard.

Composio dashboard for integrations


Coding the AI Agent

Now that everything is in place let’s get to the coding part.

As I said, this single-file code has barely 50 lines. So, let’s get started.

First, import the libraries and modules and load the .env variables to the shell environment.

from tabnanny import verbose
from urllib import response
from composio_crewai import ComposioToolSet, App, Action
from crewai import Crew, Agent, Task, Process
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv
from pathlib import Path
import os
load_dotenv()
Enter fullscreen mode Exit fullscreen mode

Instantiate GPT-4o.

llm = ChatOpenAI(model='gpt-4o')
Enter fullscreen mode Exit fullscreen mode

Get the ID of the Google Sheet that you want to use here. You can find that from the URL of your sheet.

Google Sheet ID

GOOGLE_SHEET_ID = '1i8OwCM_o2E4tmpZ18-2Jgu8G42ntPWoUgGhfbcyxnoo'
Enter fullscreen mode Exit fullscreen mode

Now, initialize a Composio Toolset instance and all the actions from the Code interpreter tool and Google Sheets.

composio_toolset = ComposioToolSet(output_dir=Path("/Users/composio/Desktop/sample-projects/ppt_builder"))
tools = composio_toolset.get_tools(actions=[Action.CODEINTERPRETER_EXECUTE_CODE,
                                            Action.CODEINTERPRETER_GET_FILE_CMD,
                                            Action.CODEINTERPRETER_RUN_TERMINAL_CMD,
                                            Action.GOOGLESHEETS_BATCH_GET])
Enter fullscreen mode Exit fullscreen mode

Here is a summary of Actions.

  • Action.CODEINTERPRETER_EXECUTE_CODE: Executes and interprets code to perform calculations or data transformations.
  • Action.CODEINTERPRETER_GET_FILE_CMD: Retrieves and processes files from specified locations or directories.
  • Action.CODEINTERPRETER_RUN_TERMINAL_CMD: Executes terminal or shell commands directly on the system.
  • Action.GOOGLESHEETS_BATCH_GET: Fetches data from Google Sheets in batches for further processing or analysis.

Next, define the PPT agent using CrewAI.

ppt_agent = Agent(
    role="Google Sheets Assistant",
    goal="Read Google Sheets Data",
    backstory=f"""
            You are an AI assistant specialising in creating PowerPoint presentations using the Python-PPTX library. 
            Your task is to analyze the Google Sheets data from the provided spreadsheet ID: {GOOGLE_SHEET_ID}. 
            Extract critical insights and generate relevant charts based on this data. 
            Finally, create a well-structured presentation that includes these charts and any necessary images, ensuring the formatting is professional and visually appealing. 
            Only the spreadsheet ID should be passed as input parameters when utilising the Google Sheets tool.
            NOTE: The user usually passes small sheets, so try to read the whole sheet at once and not via ranges.
    """,
    tools=tools,
)
Enter fullscreen mode Exit fullscreen mode

The agent is denied with parameters like role, goal, and backstory. This additional information helps the LLM better respond during task execution. It provides further information.

Next, define the task.

agent_task = Task(
    description=f"""
    Create a ppt on the google sheets: {GOOGLE_SHEET_ID}. 
    Create a sandbox
    First, retrieve the sheet's content, and then pip installs the python-pptx using a code interpreter.
    After that, run the code to create graphs from the data.
    Then, write the code using Python-pptx to create a PowerPoint.

    Ensure that the ppt is detailed and has proper formatting 
    that makes it look good. The graphs in it should be factual. 
    NOTE: Mostly, the user passes small sheets, so try to read the whole sheet at once and not via ranges.
    """,
    expected_output="Sheet was read, graphs were plotted, and Presentation was created",
    tools=tools,
    agent=ppt_agent,
    verbose=True,
)
Enter fullscreen mode Exit fullscreen mode

The task is the most crucial part of the program. Here is what each parameter means.

  • Description: This is a detailed guide to the LLM model and its functions. It is a step-by-step guide for all the actions the LLM needs to take to accomplish the job.
  • Expected Output is defined as the final output expected from the LLM.
  • Tools are all the Actions we defined earlier to help the model accomplish the task.
  • The agent is the PPT agent we defined in the previous section.
  • Verbose is set to True to output detailed process output.

Finally, define the Crew and run it.

crew = Crew(
    agents=[ppt_agent],
    tasks=[agent_task],
    process=Process.sequential,
)

response= crew.kickoff()
Enter fullscreen mode Exit fullscreen mode

The Crew has the PPT agent, task, and process set to sequential.

Putting everything together

from tabnanny import verbose
from urllib import response
from composio_crewai import ComposioToolSet, App, Action
from crewai import Crew, Agent, Task, Process
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv
from pathlib import Path
import os
load_dotenv()

llm = ChatOpenAI(model='gpt-4o')
#Settings.llm = Groq(model="llama3-groq-70b-8192-tool-use-preview")
#llm = Groq(model="llama3-groq-70b-8192-tool-use-preview")

GOOGLE_SHEET_ID = '1i8OwCM_o2E4tmpZ18-2Jgu8G42ntPWoUgGhfbcyxnoo'
#GOOGLE_SHEET_LINK + 'https://docs.google.com/spreadsheets/d/1i8OwCM_o2E4tmpZ18-2Jgu8G42ntPWoUgGhfbcyxnoo/edit?gid=0#gid=0z'
composio_toolset = ComposioToolSet(output_dir=Path("/Users/composio/Desktop/sample-projects/ppt_builder"))
tools = composio_toolset.get_tools(actions=[Action.CODEINTERPRETER_EXECUTE_CODE,
                                            Action.CODEINTERPRETER_GET_FILE_CMD,
                                            Action.CODEINTERPRETER_RUN_TERMINAL_CMD,
                                            Action.GOOGLESHEETS_BATCH_GET])

ppt_agent = Agent(
    role="Google Sheets Assistant",
    goal="Read Google Sheets Data",
    backstory=f"""
            You are an AI assistant specialising in creating PowerPoint presentations using the Python-PPTX library. 
            Your task is to analyze the Google Sheets data from the provided spreadsheet ID: {GOOGLE_SHEET_ID}. 
            Extract critical insights and generate relevant charts based on this data. 
            Finally, create a well-structured presentation that includes these charts and any necessary images, ensuring the formatting is professional and visually appealing. 
            Only the spreadsheet ID should be passed as input parameters when utilising the Google Sheets tool.
            NOTE: The user usually passes small sheets, so try to read the whole sheet at once and not via ranges.
    """,
    tools=tools,
)

agent_task = Task(
    description=f"""
    Create a ppt on the google sheets: {GOOGLE_SHEET_ID}. 
    Create a sandbox
    First, retrieve the sheet's content, and then pip installs the python-pptx using a code interpreter.
    After that, run the code to create graphs from the data.
    Then, write the code using Python-pptx to create a PowerPoint.

    Ensure that the ppt is detailed and has proper formatting 
    that makes it look good. The graphs in it should be factual. 
    NOTE: Mostly, the user passes small sheets, so try to read the whole sheet at once and not via ranges.
    """,
    expected_output="Sheet was read, graphs were plotted, and Presentation was created",
    tools=tools,
    agent=ppt_agent,
    verbose=True,
)

crew = Crew(
    agents=[ppt_agent],
    tasks=[agent_task],
    process=Process.sequential,
)

response= crew.kickoff()
Enter fullscreen mode Exit fullscreen mode

Now, run the code and see the agent in action.

python main.py
Enter fullscreen mode Exit fullscreen mode

Watch the AI agent's steps to create the final PPT in the terminal logs.

  • The agent retrieves data from the Google Spreadsheet using the GOOGLESHEETS_BATCH_GET action.
  • It understands the data context by analyzing the retrieved information.
  • The agent utilizes the CODEINTERPRETER_EXECUTE_CODE action to plot graphs based on the data.
  • Finally, it leverages the python-pptx library to create PowerPoint slides automatically and saves them to the designated path.

The complete code can be found here on GitHub

Here is an example of the agent in action.👇


What's Next?

In this article, you built an AI tool to create a PowerPoint presentation automatically from Spreadsheet. However, these are a bit of simple PPT slides for the real world. To make a more powerful agent, you can iterate over it and add more tools and multiple data formats (PDF, CSV, Webpages, etc).

This can be a great product in itself, and I can see actual people using something like this in their real jobs.

If you build over Composio, tag us on socials; we would love to feature you in our Cookbook and Newsletter with over 10k readers.

Get started with Composio ⚡

Top comments (1)

Collapse
 
anna_lapushner profile image
anna lapushner

This is really useful! You too can now create professional looking presentations. So awesome; really amazing !!!