Library written by Width.Ai. Streamlines the utilization of GPT models for automatic PowerPoint content generation. Also offers semantic searches on slide content, enabling you to quickly pinpoint relevant information
Project description
PowerPoint-Generative-AI
This library streamlines the utilization of GPT models for automatic PowerPoint content generation. It further offers a class for loading PowerPoints and performing semantic searches on slide content, enabling you to quickly pinpoint relevant information.
Setup
conda create -n 'powerpoint' python=3.10
conda activate powerpoint
pip install -r requirements.txt
How to use
from powerpoint_generative_ai import PowerPointGenerator, PowerPointAnalyzer
# set up two classes
ppt_gen = PowerPointGenerator(openai_key="...", model="gpt-4")
ppt_analyzer = PowerPointAnalyzer(openai_key="...", pinecone_key="...", pinecone_index="...", pinecone_env="...")
# Prompts to generate powerpoints for
USER_TEXTS = [
"""create a six slide powerpoint about the growing obesity rate and its effect on health insurance premiums. here is some data for a chart:
x axis: 2010, 2012, 2014, 2016, 2018, 2020, 2022, 2024
US: 5%, 10%, 15%, 20%, 25%, 30%, 35%, 40%
UK: 3%, 6%, 9%, 12%, 15%, 18%, 21%, 24%
RU: 2%, 4%, 6%, 8%, 10%, 12%, 14%, 16%
FR: 7%, 14%, 21%, 28%, 35%, 42%, 49%, 56%
IT: 1%, 2%, 3%, 4%, 5%, 6%, 7%, 8%""",
"""Create a five slide powerpoint about street racing in america, here is some data about insurance claims related to street racing in america for a bar chart:
x axis: 2010, 2012, 2014, 2016, 2018, 2020, 2022, 2024
insurance claims: 12, 84, 100, 103, 109, 114, 120, 127"""
]
# generate powerpoints
powerpoint_files = [ppt_gen.create_powerpoint(user_input=user_text) for user_text in USER_TEXTS]
# load powerpoints into pinecone
ppt_analyzer.load(file_paths=powerpoint_files)
# search on the slides indexed in pinecone and return the metadata metadata
relevant_slides = ppt_analyzer.search_for_relevant_slides(query="insurance rates")
Custom Embeddings Function
By default, PowerPointAnalyzer
utilizes OpenAI's text-embedding-ada-002
embeddings. However, an optional parameter custom_embeddings_function
allows the use of a user-defined embeddings solution in place of OpenAI's.
This function should follow the following signature:
def custom_embeddings_function(texts: List[str]) -> List:
# The function takes in a list of strings to calculate the embeddings for
# ...
# Return a list of lists that represent the embeddings of the input texts
# This can then be used when instantiating an analyzer class like this
ppt_analyzer = PowerPointAnalyzer(openai_key="...", pinecone_key="...", pinecone_index="...", pinecone_env="...", custom_embeddings_function=custom_embeddings_function)
Generating Alt-Text for Images
The PowerPointGenerator
has a function create_alt_text_for_powerpoint
. It takes two parameters; ppt_path
(the path to the powerpoint) and device
. The device
param has a few options, namely (cuda
, mps
, cpu
). The function generates alt-text for images, sets them as the descr
attribute (alt text), then saves them back to the path it read it from. Here is an example snippet using the function:
from powerpoint_generative_ai.ppt_generator import PowerPointGenerator
ppt_gen = PowerPointGenerator(openai_key="...", model="gpt-4")
ppt_gen.create_alt_text_for_powerpoint(ppt_path="/path/to/slide_deck.pptx", device="mps")
The generated captions will also be logged for the user to see what has been generated.
Cleaning up index
ppt_analyzer.pinecone_index.delete(delete_all=True)
ppt_analyzer.pinecone_index.describe_index_stats()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file powerpoint_generative_ai-0.1.8-py3-none-any.whl
.
File metadata
- Download URL: powerpoint_generative_ai-0.1.8-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8733979b178880730848b895dc4d94dce2fdbd7e796ca78a4777b6bb3f866721 |
|
MD5 | e2765e8bba2d7a073b69e988c71d9677 |
|
BLAKE2b-256 | 9ac1720140f5a6b9b7bbbb7588f0b4c47fe574f8f7dcbe03a3a3afd1218e7427 |