How to Create an LLM-Powered app to Convert Text to Presentation Slides: GenSlide — A Step-by-step… (2024)

How to Create an LLM-Powered app to Convert Text to Presentation Slides: GenSlide — A Step-by-step… (3)

In this post, I am going to share how you can create a simple yet powerful application that uses LLMs to convert your written content into concise PowerPoint slides. The good part: You even run your own LLM service, so

  • you keep your data private, and
  • no cost to call LLM APIs.

Reaching the power of GenSlide is straightforward. Follow these steps to set up and run this tool on your machine.

Begin by creating the project folder in your local machine:

mkdir GenSlide

After completing all the steps, the final file structure would look like this:

GenSlide
├── frontend
│ ├── llm_call.py
│ ├── slide_deck.py
│ ├── slide_gen.py
│ └── ui.py
├── llm-service
│ ├── consts.py
│ └── gpt.py
└── requirements.txt

The first file we create contains packages list. Create a file named requirements.txt. Add the following package dependencies to the file.

pillow==10.3.0
lxml==5.2.2
XlsxWriter==3.2.0
python-pptx==0.6.23
gpt4all==2.7.0
Flask==2.2.5
Flask-Cors==4.0.0
streamlit==1.34.0

Specifically, we’re leveraging the gpt4all package to run a large language model (LLM) server on a local machine. To dive deeper into gpt4all, refer to their official documentation.

We also use streamlit package to create the user interface.

Next, create a virtual environment and install the necessary packages:

python -m venv ./venv
source ./venv/bin/activate
pip install -r requirements.txt

Note: Ensure that you are using a Python version other than 3.9.7, as streamlit is incompatible with that version. For this tutorial I used Python version 3.12.

Our LLM service should be able to receive a text as input and generate a summary of the key points of the text as output. It should organize the output in a list of JSON objects. We’ll specify these details in the prompt definition. Let’s first create a folder for LLM service.

mkdir llm-service

We arrange the implementation into two .py files in this folder.

  1. consts.py

Here we need to define the name of LLM model we want to use. You can see the list of models that can be used here: https://docs.gpt4all.io/gpt4all_python/home.html#load-llm. Meta’s Llama model performs good for this task.

LLM_MODEL_NAME = "Meta-Llama-3-8B-Instruct.Q4_0.gguf"

We also define the prompt message here that includes the instructions to the LLM as well as some examples of the desired output. We ask the output to be in JSON format, so it would be easier for us to process and create a presentation.

PROMPT = """
Summarize the input text and arrange it in an array of JSON objects to to be suitable for a powerpoint presentation.
Determine the needed number of json objects (slides) based on the length of the text.
Each key point in a slide should be limited to up to 10 words.
Consider maximum of 5 bullet points per slide.
Return the response as an array of json objects.
The first item in the list must be a json object for the title slide.
This is a sample of such json object:
{
"id": 1,
"title_text": "My Presentation Title",
"subtitle_text": "My presentation subtitle",
"is_title_slide": "yes"
}
And here is the sample of json data for slides:
{"id": 2, title_text": "Slide 1 Title", "text": ["Bullet 1", "Bullet 2"]},
{"id": 3, title_text": "Slide 2 Title", "text": ["Bullet 1", "Bullet 2", "Bullet 3"]}

Please make sure the json object is correct and valid.
Don't output explanation. I just need the JSON array as your output.
"""

2. gpt.py

Here we want to create a Flask application that receives HTTP POST requests from the clients and call the LLM model to extract the summary in a JSON representation.

First things first; import dependencies.

from flask import Flask, request
from flask_cors import CORS
import traceback
import logging
import os
from consts import LLM_MODEL_NAME, PROMPT

from gpt4all import GPT4All

Define the host IP, port, Flask app and allow Cross-Origin Resource Sharing.

logger = logging.getLogger()

HOST = '0.0.0.0'
PORT = 8081

app = Flask(__name__)
CORS(app)

Define a base folder to store the LLM model. Here with “MODEL_PATH” environment variable we overwrite the default location of models set by gpt4all. Now the models will be stored in the project folder under “gpt_models/gpt4all/”. When GPT4All class is instantiated for the first time, it will look for the model_name in the model_path (it’s argument), if not found, will look into MODEL_PATH. If not found, it will start to download the model.

try:
base_folder = os.path.dirname(__file__)
base_folder = os.path.dirname(base_folder)
gpt_models_folder = os.path.join(base_folder, "gpt_models/gpt4all/")
if not os.path.exists(gpt_models_folder):
os.makedirs(gpt_models_folder, exist_ok=True)
model_folder = os.environ.get("MODEL_PATH", gpt_models_folder)
llm_model = GPT4All(model_name=LLM_MODEL_NAME, model_path=model_folder)
except Exception:
raise ValueError("Error loading LLM model.")

Define a function to call the generate() function of the LLM model and return the response. We may set optional parameters such as temperature and max_tokens.

def generate_text(content):
prompt = PROMPT + f"\n{content}"

with llm_model.chat_session():
output = llm_model.generate(prompt, temp=0.7, max_tokens=1024)
output = output.strip()

return output

Define a POST API to receive clients’ requests. Requests come in the form of JSON objects {“content”:”…”}. We will use this “content” value and call the generate_text() method defined above. If everything goes well, we send the output along with an 200 HTTP (OK) status code. Otherwise an “Error” message and status code 500 is returned.

@app.route('/api/completion', methods=['POST'])
def completion():
try:
req = request.get_json()
words = req.get('content')
if not words:
raise ValueError("No input word.")
output = generate_text(words)
return output, 200
except Exception:
logger.error(traceback.format_exc())
return "Error", 500

Run the Flask app.

if __name__ == '__main__':
# run web server
app.run(host=HOST,
debug=True, # automatic reloading enabled
port=PORT)

Frontend is where we get the user’s input and interact with the LLM service and finally create the PowerPoint slides.

Inside the project folder, create a folder named frontend.

mkdir frontend

The implementation falls into 4 Python files.

  1. llm_call.py

This would be where we send the POST requests to the LLM server. We set our LLM server on localhost port 8081. We enclose the input text into a JSON object with the key “content”. The output of the call should be a JSON string.

import requests

URL = "http://127.0.0.1:8081"

CHAT_API_ENDPOINT = f"{URL}/api/completion"

def chat_completion_request(content):
headers = {'Content-type': 'application/json'}
data = {'content': content}

req = requests.post(url=CHAT_API_ENDPOINT, headers=headers, json=data)
json_extracted = req.text
return json_extracted

2. slide_deck.py

Here we use pptx package to create PowerPoint slides. The list of JSON objects contains the information to add slides to the presentation. For detailed information about pptx package refer to their documentation.

import os

from pptx import Presentation
from pptx.util import Inches

class SlideDeck:

def __init__(self, output_folder="generated"):
self.prs = Presentation()
self.output_folder = output_folder

def add_slide(self, slide_data):
prs = self.prs
bullet_slide_layout = prs.slide_layouts[1]
slide = prs.slides.add_slide(bullet_slide_layout)
shapes = slide.shapes

# Title
title_shape = shapes.title
title_shape.text = slide_data.get("title_text", "")

# Body
if "text" in slide_data:
body_shape = shapes.placeholders[1]
tf = body_shape.text_frame
for bullet in slide_data.get("text", []):
p = tf.add_paragraph()
p.text = bullet
p.level = 0

if "p1" in slide_data:
p = tf.add_paragraph()
p.text = slide_data.get("p1")
p.level = 1

if "img_path" in slide_data:
cur_left = 6
for img_path in slide_data.get("img_path", []):
top = Inches(2)
left = Inches(cur_left)
height = Inches(4)
pic = slide.shapes.add_picture(img_path, left, top, height=height)
cur_left += 1

def add_title_slide(self, title_page_data):
# title slide
prs = self.prs
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
if "title_text" in title_page_data:
title.text = title_page_data.get("title_text")
if "subtitle_text" in title_page_data:
subtitle.text = title_page_data.get("subtitle_text")

def create_presentation(self, title_slide_info, slide_pages_data=[]):
try:
file_name = title_slide_info.get("title_text").\
lower().replace(",", "").replace(" ", "-")
file_name += ".pptx"
file_name = os.path.join(self.output_folder, file_name)
self.add_title_slide(title_slide_info)
for slide_data in slide_pages_data:
self.add_slide(slide_data)

self.prs.save(file_name)
return file_name
except Exception as e:
raise e

3. slide_gen.py

Let’s break it into smaller snippets.

Here, after importing necessary packages, create a folder to store the generated .pptx files.

import json
import os

from slide_deck import SlideDeck
from llm_call import chat_completion_request

FOLDER = "generated"

if not os.path.exists(FOLDER):
os.makedirs(FOLDER)

Then define these two methods:

  • A method to invoke chat_completion_request and send the request to the LLM and parse the JSON string,
  • A method that gets the output of previous method and instantiate a SlideDeck to fill in the PowerPoint slides.
def generate_json_list_of_slides(content):
try:
resp = chat_completion_request(content)
obj = json.loads(resp)
return obj
except Exception as e:
raise e

def generate_presentation(content):
deck = SlideDeck()
slides_data = generate_json_list_of_slides(content)
title_slide_data = slides_data[0]
slides_data = slides_data[1:]
return deck.create_presentation(title_slide_data, slides_data)

4. ui.py

We create a simple UI with an input text box. User can type in or copy/paste their text there and hit enter to start the slide generation. Upon completion of slide generation, a message is printed at the end of input text box. streamlit is very handy here.

import traceback
import streamlit as st

from slide_gen import generate_presentation

def create_ui():
st.write("""
# Gen Slides
### Generating powerpoint slides for your text
""")

content = st.text_area(label="Enter your text:", height=400)
try:
if content:
filename = generate_presentation(content)
st.write(f"file {filename} is generated.")
except Exception:
st.write("Error in generating slides.")
st.write(traceback.format_exc())

if __name__ == "__main__":
create_ui()

Navigate to the llm-service folder and run the gpt.py file:

cd llm-service
python gpt.py

Note: The first time you run this, the LLM model will be downloaded, which may take several minutes to complete.

Now, it’s time to bring up the UI. Navigate to the frontend folder and run the ui.py file using Streamlit:

cd ..
cd frontend
streamlit run ui.py

This command will launch the UI in your default web browser.

With the UI up and running, follow these simple steps to generate your presentation:

1. Input Text: In the provided text box, input the content you’d like to transform into a presentation. Here is the sample you may use:

Artificial Intelligence is an idea that has been captivating society since the mid-20th century.
It began with science fiction familiarizing the world with the concept but the idea wasn't fully seen in the scientific manner until Alan Turing, a polymath, was curious about the feasibility of the concept.
Turing's groundbreaking 1950 paper, "Computing Machinery and Intelligence," posed fundamental questions about machine reasoning similar to human intelligence, significantly contributing to the conceptual groundwork of AI.
The development of AI was not very rapid at first because of the high costs and the fact that computers were not able to store commands.
This changed during the 1956 Dartmouth Summer Research Project on AI where there was an inspiring call for AI research, setting the precedent for two decades of rapid advancements in the field.

2. Generate Slides: Once you enter the text (followed by Command ⌘ + Enter keys in Mac), GenSlide will process it and create the presentation .pptxfile.

3. Access Your Slides: The newly created PowerPoint file will be saved in thefrontend/generatedfolder.

How to Create an LLM-Powered app to Convert Text to Presentation Slides: GenSlide — A Step-by-step… (4)
How to Create an LLM-Powered app to Convert Text to Presentation Slides: GenSlide — A Step-by-step… (5)

Congratulations! The ability to automate slide generation is not just a technical achievement; it’s a time-saving marvel for professionals and students alike. For the next steps, the application can be extended to read the text from other formats like PDF files, MS Word documents, web pages and more. I would be happy to hear how you use or extend this project.

For further enhancement and contributions, feel free to explore the repository on GitHub.

How to Create an LLM-Powered app to Convert Text to Presentation Slides: GenSlide — A Step-by-step… (2024)

FAQs

How do you turn text into presentation slides? ›

Open the document you want to transform into a presentation in Word for the web. Make sure that it contains only text. The headings in the document will become the slide headings in the presentation. Go to File > Export > Export to PowerPoint presentation.

How do you convert PowerPoint slides to text? ›

Open the PPT file in PowerPoint and select File > Export from the menu bar. Name your file in the Save As text box and designate a location on your local disk to store it. Under File Format, select the Rich Text Format (. rtf) option.

What is the AI tool to convert text to slides? ›

SlidesAI.io - Create Slides With AI - Google Workspace Marketplace. AI-Powered tool that transforms any text into visually appealing slides, saving you hours of time and effort. Choose from a variety of presentation types and colour presets. If playback doesn't begin shortly, try restarting your device.

What program is used to create presentations made up of a collection of slides containing text and other forms of media? ›

PowerPoint presentations work like slide shows. To convey a message or a story, you break it down into slides. Think of each slide as a blank canvas for the pictures and words that help you tell your story.

Is there a free AI that converts Word to PowerPoint? ›

Is there a free AI to create PPT from Word docs? Yes, Plus AI offers a free Word to PPT converter that will read a Word doc and transform it into a Google Slides or PowerPoint presentation.

How do I make a slideshow of text? ›

How do I add text to a slideshow? Most slideshow maker tools allow you to add text wherever you need to on each slide. Simply hover your cursor over the area you want to include text and click to add it in, or add a text box on top of your background.

How do you generate text in PowerPoint? ›

Formula for generating random text:

The formula is '=rand()'. You can also have the random text in Latin. The formula is '=lorem()'. The default amount of random text is 3 paragraphs with 5 sentences each.

How to convert PowerPoint to Word for free? ›

How to Convert PPT to Word Online
  1. Go to the online Converter tool.
  2. Upload or drop your PPT file.
  3. Wait while we convert your file to a PDF.
  4. Click on “Export As” from the panel on the right.
  5. Choose the “Word (.docx)” option.
  6. Voilà! You can now download or share your file.
May 15, 2023

How to generate script from PPT? ›

Top 10 tips on how to write a script for PowerPoint presentation
  1. Finalize the storyboard. ...
  2. Follow the KISS rule. ...
  3. Make sure your script for presentation introduction is engaging. ...
  4. Aim for well-structured content. ...
  5. Stick to the slide content. ...
  6. Add pause breaks. ...
  7. Use engaging language. ...
  8. Don't forget about calls to action.
Sep 18, 2023

What tool converts text to PowerPoint? ›

Choose 'Text to PPT'

Inside the AI PPT Tools, you will find the "Text to PPT" option. This tool takes the text you provide and turns it into a PowerPoint presentation. It's perfect for converting your written notes or any important points into slides.

Is Slide AI free? ›

Presentations don't need to be a chore anymore – the AI Presentation Maker is here to save the day! This powerful technology will create impressive slides with just a few clicks, so you can impress your audience with zero stress. The best part – it's 100% free!

What is the best free app for making PowerPoint presentations? ›

There are many free alternatives to PowerPoint, including Canva, Prezi, Slide Bean, Google Slides, Zoho Show, Haiku Deck, LibreOffice, SlideDog, WPS Office, Keynote, Microsoft Sway, Visme Basic, Renderforest, and Calligra Stage.

What is replacing PowerPoint? ›

10 PowerPoint alternatives to level up your presentations [2024]
  • Mentimeter.
  • Google Slides.
  • Keynote.
  • Prezi.
  • Canva.
  • Beautiful.ai.
  • Visme.
  • Zoho Show.
Jun 6, 2024

What application is best used for creating a presentation? ›

Software Options for Beginners
  • Microsoft PowerPoint. Microsoft PowerPoint provides pre-built templates and layouts spanning styles, themes, and design elements that allow beginners to quickly begin creating presentation slides. ...
  • Google Slides. ...
  • Canva. ...
  • Apple Keynote. ...
  • Adobe Express. ...
  • Adobe Illustrator. ...
  • Prezi. ...
  • Zoho Show.

How do you make a text presentation in PowerPoint? ›

You can add text to a PowerPoint slide or a slide master by inserting a text box and typing inside that box. You can then format that text by selecting the text or the entire box. You can also add text to placeholders and shapes.

How do you do text to speech slides? ›

To use text to speech (TTS) in PowerPoint, you need to activate the feature. Go to the 'Quick Access Toolbar,' choose 'More Commands,' and then select 'Speak' from the list.

How do I turn text into Google Slides? ›

Step-by-step process to convert Google Docs to Google Slides
  1. Step 1: Install the Plus AI for Google Slides add-on. ...
  2. Step 2: Open your Google Doc and copy all of the contents. ...
  3. Step 3: Open the Text to Presentation mode in Plus AI. ...
  4. Step 4: Paste your Google Doc into Plus AI and click Generate Presentation.
Oct 31, 2023

Top Articles
Alkalisch dieet: een overzicht van alkalische voedingsmiddelen
Disgraced TN police chief received explicit photos of Maegan Hall on burner phone: court docs
Gasbuddy Joliet
Msc Open House Fall 2023
Coverwood Terriers For Sale
7076605599
Redbox Locations Walmart
Hailie Deegan News, Rumors, & NASCAR Updates
Relic Gate Nms
888-490-1703
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
Sam's Club Key Event Dates 2023 Q1
Martimelons
Inside the Rise and Fall of Toys ‘R’ Us | HISTORY
Walking through the Fire: Why nothing stops Jesus’ love for you - Ann Voskamp
Craigslist Manhattan Ks Personals
Kroger Liquor Hours
Fandango Movies And Shows
New from Simply So Good - Cherry Apricot Slab Pie
Lucio Surf Code
Rockcastle County Schools Calendar
Open jazz : podcast et émission en replay | France Musique
Craiglist Rhode Island
Chi Trib Weather
No Prob-Llama Plotting Points
Axolotls for Sale - 10 Online Stores You Can Buy an Axolotl - Axolotl Nerd
Movierulz.com Kannada 2024 Download: Your Ultimate Guide
Retire Early Wsbtv.com Free Book
Haktuts.in Coin Master 50 Spin Link
Panic! At The Disco - Spotify Top Songs
How 'Tuesday' Brings Death to Life With Heart, Humor, and a Giant Bird
When Is Meg Macnamara Due
Uhauldealer.com Login Page
Mike Temara
South Carolina Title Transfer Does Sc Require Notary Seal For Auto Title Transfer
Craigslist Cars And Trucks By Owner Seattle
Journal articles: 'New York (State). First Congregational Church' – Grafiati
Snowy Hydro Truck Jobs in All Sydney NSW - Sep 2024 | SEEK
Brian Lizer Life Below Zero Next Generation
Stark Cjis Court Docket
Lagniappemobile
How to Survive (and Succeed!) in a Fast-Paced Environment | Exec Learn
Fandafia
Rockin That Orange Jumpsuit Columbia County
Sam's Club Hiring Near Me
El Pulpo Auto Parts Houston
The Swarthmorean, 1932-05 | TriCollege Libraries Digital Collections
Fintechzoommortgagecalculator.live Hours
Guy Ritchie's The Covenant Showtimes Near Century 16 Eastport Plaza
How Long Ago Was February 28 2023
Cb2 South Coast Plaza
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 5831

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.