Automating PowerPoint Creation with Python, AnythingLLM, and python-pptx

Creating presentations is often a time-consuming task. Writing slide titles, formatting bullet points, and arranging content can quickly become repetitive. But with the help of local large language models (LLMs), AnythingLLM, and Python’s python-pptx library, you can automatically generate professional PowerPoint presentations.

In this blog, I’ll show you step by step how to integrate these tools to save time and boost productivity.


Why Automate PowerPoint with AI?

Instead of typing everything manually, you can:

  • Use AnythingLLM to generate structured content for your slides.

  • Store and retrieve knowledge from your local knowledge base.

  • Automatically create and export a PowerPoint file with Python + python-pptx.

This workflow is ideal for developers, students, researchers, and anyone who frequently needs to prepare presentations.

Step 1: Install python-pptx

The first step is installing the python-pptx library. Run the following command in your terminal:

pip install python-pptx

This library allows you to create and edit PowerPoint presentations directly in Python.


Step 2: Generate Slide Content with AnythingLLM

You can connect to AnythingLLM’s API and ask it to generate structured content for your slides.
For example, requesting a presentation about Cybersecurity Basics might return something like this:

[
  {
    "title": "Introduction to Cybersecurity",
    "content": [
      "Definition of Cybersecurity",
      "Why it matters",
      "Common threats"
    ]
  },
  {
    "title": "Key Security Practices",
    "content": [
      "Use strong passwords",
      "Enable multi-factor authentication",
      "Regular updates"
    ]
  }
]

This JSON format makes it simple to pass data directly into Python.

Step 3: Create a PowerPoint with Python

Here’s the Python code to turn the structured data into an actual PowerPoint file:

import requests
import json
from pptx import Presentation #pip install python-pptx
import re

workspace_id = 'my-first-workspace'
API_KEY = 'YEHMNNK-93F49J8-J23HT90-N71F0P0'
API_URL = f'http://localhost:3001/api/v1/workspace/{workspace_id}/chat'
headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {API_KEY}'
}
prompt = '''
    Please help Powerpoint for the topic of artificial intelligence.
    The format should be JSON. You can follow the example below:
    [
    {'title':'The title of the first slide','content':['point 1', 'point 2']},
    {'title':'The title of the second slide','content':['point 1', 'point 2']},]},
    ]
'''
data = {
    'message':prompt,
    'mode':'chat'
}
response = requests.post(API_URL, headers=headers, json=data)
if response.status_code == 200:
    result1 = response.json()['textResponse']

    pattern1 = r'<think>.*?</think>'
    result2 = re.sub(pattern1, '', result1)
    pattern2 = r'```json(.*?)```'
    result3 = re.findall(pattern2, result2, flags=re.DOTALL)[0]
    result4 =  re.sub(r'-\s+"', '"', result3)
    print(result4)
    try:
        slides = json.loads(result4)
    except:
        slides = [{'title':'error'}, {'content':[result4]}]

    prs = Presentation()
    for slide in slides:
        layout = prs.slide_layouts[1]
        s = prs.slides.add_slide(layout)
        s.shapes.title.text = slide['title']
        s.placeholders[1].text = '\n'.join(slide['content'])
    prs.save('AI.pptx')
    print("PPT is generated")

else:
    print(response.status_code)

Step 4: Open and Present

Run the script, and you’ll get a file called Cybersecurity.pptx.
Open it in Microsoft PowerPoint, LibreOffice, or Google Slides—and you’ll see that your slides are ready to go!


Workflow Recap

  1. Generate structured content with AnythingLLM (using your local LLM and knowledge base).

  2. Pass content to Python and use python-pptx to create slides.

  3. Export the PowerPoint and present it immediately.

This workflow gives you AI-powered presentations in just minutes, while keeping full control over your data using local deployment.


Final Thoughts

By combining local LLMs, AnythingLLM, and Python automation, you can transform how you prepare presentations.
This approach saves time, keeps your workflow private, and makes your slides more dynamic and scalable.

In future articles, I’ll cover how to enhance these slides further—adding images, charts, and custom formatting with Python.

Related Articles

Step-by-Step Guide to Installing WordPress with Bitnami

Read Article
Tips for Exploiting Local File Inclusion (LFI) Vulnerabilities

Read Article
Steps for Web Information Gathering

Read Article

Comments

Leave a Comment

No comments yet. Be the first to comment!