Source: https://github.com/aipoch/medical-research-skills
When to Use
- You need to generate a new
.pptx deck from a short prompt or structured outline (e.g., "5 slides about machine learning").
- You want to update an existing presentation by adding slides or editing text without manually opening PowerPoint.
- You need to extract structured information from a deck (e.g., slide titles) for indexing, review, or QA.
- You want to export slides to images (thumbnails) or PDF for previews, sharing, or downstream processing.
- You need to insert images into slides (local files or downloaded assets) as part of automated reporting.
Key Features
- Presentation creation: Create new
.pptx files and populate them with slides.
- Slide authoring: Add slides with titles, body text, and images.
- Text editing: Modify text content on existing slides.
- Image support: Insert and handle images (including basic manipulation via Pillow).
- Template support: Start from existing
.pptx templates and extend them.
- Export options: Export slides as images (thumbnails) and optionally export to PDF (via external tooling).
- Information extraction: Read slide metadata such as slide titles.
Dependencies
- Python:
>=3.7
- python-pptx:
>=0.6.21
- Pillow:
>=9.0.0 (image handling)
- requests:
>=2.28.0 (downloading remote images)
- Optional (advanced export): LibreOffice
>=7.0 (e.g., PPTX → PDF conversion)
Example Usage
# pip install python-pptx Pillow requests
from pptx import Presentation
from pptx.util import Inches
from PIL import Image
import requests
from io import BytesIO
def create_presentation(output_path: str) -> None:
prs = Presentation()
# Slide 1: Title slide
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Machine Learning"
slide.placeholders[1].text = "A 5-slide overview generated programmatically"
# Slide 2: Bullets
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "What is Machine Learning?"
tf = slide.shapes.placeholders[1].text_frame
tf.clear()
tf.text = "A field of AI focused on learning patterns from data"
for bullet in [
"Supervised learning",
"Unsupervised learning",
"Reinforcement learning",
]:
p = tf.add_paragraph()
p.text = bullet
# Slide 3: Add an image (downloaded)
img_url = "https://upload.wikimedia.org/wikipedia/commons/4/44/Neural_network.svg"
resp = requests.get(img_url, timeout=30)
resp.raise_for_status()
# Ensure the image is in a format python-pptx can embed reliably
img = Image.open(BytesIO(resp.content)).convert("RGBA")
buf = BytesIO()
img.save(buf, format="PNG")
buf.seek(0)
slide = prs.slides.add_slide(prs.slide_layouts[5]) # Title Only
slide.shapes.title.text = "Neural Networks (Illustration)"
slide.shapes.add_picture(buf, Inches(1), Inches(1.6), width=Inches(8))
# Slide 4: Edit text on an existing slide (example: update slide 2 title)
prs.slides[1].shapes.title.text = "Machine Learning: Definition & Types"
# Slide 5: Summary
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "Summary"
tf = slide.shapes.placeholders[1].text_frame
tf.clear()
tf.text = "Key takeaways"
for bullet in [
"ML learns from data to make predictions or decisions",
"Model choice depends on task and constraints",
"Evaluation and iteration are essential",
]:
p = tf.add_paragraph()
p.text = bullet
prs.save(output_path)
def list_slide_titles(pptx_path: str) -> list[str]:
prs = Presentation(pptx_path)
titles = []
for slide in prs.slides:
title_shape = slide.shapes.title if hasattr(slide.shapes, "title") else None
if title_shape is not None and getattr(title_shape, "text", "").strip():
titles.append(title_shape.text.strip())
else:
titles.append("(no title)")
return titles
if __name__ == "__main__":
out = "machine_learning.pptx"
create_presentation(out)
print("Created:", out)
print("Slide titles:", list_slide_titles(out))
Implementation Details
- Core library: Uses
python-pptx to read/write the Open XML .pptx format.
- Slide layouts: Slides are created from built-in layouts (e.g.,
prs.slide_layouts[0] for title slide, prs.slide_layouts[1] for title+content). Layout availability can vary by template.
- Text editing model: Text is edited via
TextFrame and Paragraph objects. Clearing and rebuilding a text frame is a common approach to ensure consistent bullet structure.
- Image insertion:
- Remote images can be downloaded with
requests.
- Images are normalized with
Pillow (e.g., converting to PNG) before embedding to improve compatibility.
- Placement uses absolute positioning (e.g.,
Inches(x)) and optional sizing parameters.
- Extraction: Slide titles are typically accessed via
slide.shapes.title when present; some slides may not have a title placeholder.
- Export limitations:
python-pptx does not natively render slides to images or PDF. Thumbnail/PDF export generally requires external rendering (commonly LibreOffice in headless mode).
- Known constraints:
- Complex animations and some advanced PowerPoint features may not be editable.
- Large decks and high-resolution images increase processing time and memory usage.
When Not to Use
- Do not use this skill when the required source data, identifiers, files, or credentials are missing.
- Do not use this skill when the user asks for fabricated results, unsupported claims, or out-of-scope conclusions.
- Do not use this skill when a simpler direct answer is more appropriate than the documented workflow.
Required Inputs
- A clearly specified task goal aligned with the documented scope.
- All required files, identifiers, parameters, or environment variables before execution.
- Any domain constraints, formatting requirements, and expected output destination if applicable.
Recommended Workflow
- Validate the request against the skill boundary and confirm all required inputs are present.
- Select the documented execution path and prefer the simplest supported command or procedure.
- Produce the expected output using the documented file format, schema, or narrative structure.
- Run a final validation pass for completeness, consistency, and safety before returning the result.
Deterministic Output Rules
- Use the same section order for every supported request of this skill.
- Keep output field names stable and do not rename documented keys across examples.
- If a value is unavailable, emit an explicit placeholder instead of omitting the field.
Output Contract
- Return a structured deliverable that is directly usable without reformatting.
- If a file is produced, prefer a deterministic output name such as
pptx_skill_result.md unless the skill documentation defines a better convention.
- Include a short validation summary describing what was checked, what assumptions were made, and any remaining limitations.
Validation and Safety Rules
- Validate required inputs before execution and stop early when mandatory fields or files are missing.
- Do not fabricate measurements, references, findings, or conclusions that are not supported by the provided source material.
- Emit a clear warning when credentials, privacy constraints, safety boundaries, or unsupported requests affect the result.
- Keep the output safe, reproducible, and within the documented scope at all times.
Failure Handling
- If validation fails, explain the exact missing field, file, or parameter and show the minimum fix required.
- If an external dependency or script fails, surface the command path, likely cause, and the next recovery step.
- If partial output is returned, label it clearly and identify which checks could not be completed.
Completion Checklist
- Confirm all required inputs were present and valid.
- Confirm the supported execution path completed without unresolved errors.
- Confirm the final deliverable matches the documented format exactly.
- Confirm assumptions, limitations, and warnings are surfaced explicitly.
Quick Validation
Run this minimal verification path before full execution when possible:
python scripts/__init__.py --help
Expected output format:
Result file: pptx_skill_result.md
Validation summary: PASS/FAIL with brief notes
Assumptions: explicit list if any
Scope Reminder
- Core purpose: Create, edit, and extract content from PowerPoint (.pptx) files; use when you need to generate slides programmatically, update existing decks, or export slide previews.
1---2name: pptx-skill3description: Create, edit, and extract content from PowerPoint (.pptx) files; use when you need to generate slides programmatically, update existing decks, or export slide previews.4license: MIT5---6> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)
7
8## When to Use
9
10- You need to generate a new `.pptx` deck from a short prompt or structured outline (e.g., "5 slides about machine learning").
11- You want to update an existing presentation by adding slides or editing text without manually opening PowerPoint.
12- You need to extract structured information from a deck (e.g., slide titles) for indexing, review, or QA.
13- You want to export slides to images (thumbnails) or PDF for previews, sharing, or downstream processing.
14- You need to insert images into slides (local files or downloaded assets) as part of automated reporting.
15
16## Key Features
17
18- **Presentation creation**: Create new `.pptx` files and populate them with slides.
19- **Slide authoring**: Add slides with titles, body text, and images.
20- **Text editing**: Modify text content on existing slides.
21- **Image support**: Insert and handle images (including basic manipulation via Pillow).
22- **Template support**: Start from existing `.pptx` templates and extend them.
23- **Export options**: Export slides as images (thumbnails) and optionally export to PDF (via external tooling).
24- **Information extraction**: Read slide metadata such as slide titles.
25
26## Dependencies
27
28- **Python**: `>=3.7`
29- **python-pptx**: `>=0.6.21`
30- **Pillow**: `>=9.0.0` (image handling)
31- **requests**: `>=2.28.0` (downloading remote images)
32- **Optional (advanced export)**: LibreOffice `>=7.0` (e.g., PPTX → PDF conversion)
33
34## Example Usage
35
36```python
37# pip install python-pptx Pillow requests
38
39from pptx import Presentation
40from pptx.util import Inches
41from PIL import Image
42import requests
43from io import BytesIO
44
45def create_presentation(output_path: str) -> None:
46 prs = Presentation()
47
48 # Slide 1: Title slide
49 slide = prs.slides.add_slide(prs.slide_layouts[0])
50 slide.shapes.title.text = "Machine Learning"
51 slide.placeholders[1].text = "A 5-slide overview generated programmatically"
52
53 # Slide 2: Bullets
54 slide = prs.slides.add_slide(prs.slide_layouts[1])
55 slide.shapes.title.text = "What is Machine Learning?"
56 tf = slide.shapes.placeholders[1].text_frame
57 tf.clear()
58 tf.text = "A field of AI focused on learning patterns from data"
59 for bullet in [
60 "Supervised learning",
61 "Unsupervised learning",
62 "Reinforcement learning",
63 ]:
64 p = tf.add_paragraph()
65 p.text = bullet
66
67 # Slide 3: Add an image (downloaded)
68 img_url = "https://upload.wikimedia.org/wikipedia/commons/4/44/Neural_network.svg"
69 resp = requests.get(img_url, timeout=30)
70 resp.raise_for_status()
71
72 # Ensure the image is in a format python-pptx can embed reliably
73 img = Image.open(BytesIO(resp.content)).convert("RGBA")
74 buf = BytesIO()
75 img.save(buf, format="PNG")
76 buf.seek(0)
77
78 slide = prs.slides.add_slide(prs.slide_layouts[5]) # Title Only
79 slide.shapes.title.text = "Neural Networks (Illustration)"
80 slide.shapes.add_picture(buf, Inches(1), Inches(1.6), width=Inches(8))
81
82 # Slide 4: Edit text on an existing slide (example: update slide 2 title)
83 prs.slides[1].shapes.title.text = "Machine Learning: Definition & Types"
84
85 # Slide 5: Summary
86 slide = prs.slides.add_slide(prs.slide_layouts[1])
87 slide.shapes.title.text = "Summary"
88 tf = slide.shapes.placeholders[1].text_frame
89 tf.clear()
90 tf.text = "Key takeaways"
91 for bullet in [
92 "ML learns from data to make predictions or decisions",
93 "Model choice depends on task and constraints",
94 "Evaluation and iteration are essential",
95 ]:
96 p = tf.add_paragraph()
97 p.text = bullet
98
99 prs.save(output_path)
100
101def list_slide_titles(pptx_path: str) -> list[str]:
102 prs = Presentation(pptx_path)
103 titles = []
104 for slide in prs.slides:
105 title_shape = slide.shapes.title if hasattr(slide.shapes, "title") else None
106 if title_shape is not None and getattr(title_shape, "text", "").strip():
107 titles.append(title_shape.text.strip())
108 else:
109 titles.append("(no title)")
110 return titles
111
112if __name__ == "__main__":
113 out = "machine_learning.pptx"
114 create_presentation(out)
115 print("Created:", out)
116 print("Slide titles:", list_slide_titles(out))
117```
118
119## Implementation Details
120
121- **Core library**: Uses `python-pptx` to read/write the Open XML `.pptx` format.
122- **Slide layouts**: Slides are created from built-in layouts (e.g., `prs.slide_layouts[0]` for title slide, `prs.slide_layouts[1]` for title+content). Layout availability can vary by template.
123- **Text editing model**: Text is edited via `TextFrame` and `Paragraph` objects. Clearing and rebuilding a text frame is a common approach to ensure consistent bullet structure.
124- **Image insertion**:
125 - Remote images can be downloaded with `requests`.
126 - Images are normalized with `Pillow` (e.g., converting to PNG) before embedding to improve compatibility.
127 - Placement uses absolute positioning (e.g., `Inches(x)`) and optional sizing parameters.
128- **Extraction**: Slide titles are typically accessed via `slide.shapes.title` when present; some slides may not have a title placeholder.
129- **Export limitations**:
130 - `python-pptx` does not natively render slides to images or PDF. Thumbnail/PDF export generally requires external rendering (commonly LibreOffice in headless mode).
131- **Known constraints**:
132 - Complex animations and some advanced PowerPoint features may not be editable.
133 - Large decks and high-resolution images increase processing time and memory usage.
134
135## When Not to Use
136
137- Do not use this skill when the required source data, identifiers, files, or credentials are missing.
138- Do not use this skill when the user asks for fabricated results, unsupported claims, or out-of-scope conclusions.
139- Do not use this skill when a simpler direct answer is more appropriate than the documented workflow.
140
141## Required Inputs
142
143- A clearly specified task goal aligned with the documented scope.
144- All required files, identifiers, parameters, or environment variables before execution.
145- Any domain constraints, formatting requirements, and expected output destination if applicable.
146
147## Recommended Workflow
148
1491. Validate the request against the skill boundary and confirm all required inputs are present.
1502. Select the documented execution path and prefer the simplest supported command or procedure.
1513. Produce the expected output using the documented file format, schema, or narrative structure.
1524. Run a final validation pass for completeness, consistency, and safety before returning the result.
153
154## Deterministic Output Rules
155
156- Use the same section order for every supported request of this skill.
157- Keep output field names stable and do not rename documented keys across examples.
158- If a value is unavailable, emit an explicit placeholder instead of omitting the field.
159
160## Output Contract
161
162- Return a structured deliverable that is directly usable without reformatting.
163- If a file is produced, prefer a deterministic output name such as `pptx_skill_result.md` unless the skill documentation defines a better convention.
164- Include a short validation summary describing what was checked, what assumptions were made, and any remaining limitations.
165
166## Validation and Safety Rules
167
168- Validate required inputs before execution and stop early when mandatory fields or files are missing.
169- Do not fabricate measurements, references, findings, or conclusions that are not supported by the provided source material.
170- Emit a clear warning when credentials, privacy constraints, safety boundaries, or unsupported requests affect the result.
171- Keep the output safe, reproducible, and within the documented scope at all times.
172
173## Failure Handling
174
175- If validation fails, explain the exact missing field, file, or parameter and show the minimum fix required.
176- If an external dependency or script fails, surface the command path, likely cause, and the next recovery step.
177- If partial output is returned, label it clearly and identify which checks could not be completed.
178
179## Completion Checklist
180
181- Confirm all required inputs were present and valid.
182- Confirm the supported execution path completed without unresolved errors.
183- Confirm the final deliverable matches the documented format exactly.
184- Confirm assumptions, limitations, and warnings are surfaced explicitly.
185
186## Quick Validation
187
188Run this minimal verification path before full execution when possible:
189
190```bash
191python scripts/__init__.py --help
192```
193
194Expected output format:
195
196```text
197Result file: pptx_skill_result.md
198Validation summary: PASS/FAIL with brief notes
199Assumptions: explicit list if any
200```
201
202## Scope Reminder
203
204- Core purpose: Create, edit, and extract content from PowerPoint (.pptx) files; use when you need to generate slides programmatically, update existing decks, or export slide previews.