Create create_presentation.py
Browse filesThis tool:
Creates a PowerPoint presentation
Automatically splits content into slides
Supports titles + bullet points
Returns the file path so your agent can expose it for download
- tools/create_presentation.py +54 -0
tools/create_presentation.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import tool
|
| 2 |
+
import tempfile
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
@tool
|
| 6 |
+
def create_presentation(
|
| 7 |
+
title: str,
|
| 8 |
+
slides: list[str]
|
| 9 |
+
) -> str:
|
| 10 |
+
"""
|
| 11 |
+
Creates a PowerPoint presentation (.pptx).
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
title: Title of the presentation
|
| 15 |
+
slides: A list of slide contents. Each item represents one slide.
|
| 16 |
+
Use '\\n' inside a slide to create bullet points.
|
| 17 |
+
"""
|
| 18 |
+
try:
|
| 19 |
+
from pptx import Presentation
|
| 20 |
+
from pptx.util import Inches, Pt
|
| 21 |
+
|
| 22 |
+
# Create temp directory
|
| 23 |
+
temp_dir = tempfile.mkdtemp()
|
| 24 |
+
pptx_path = os.path.join(temp_dir, "generated_presentation.pptx")
|
| 25 |
+
|
| 26 |
+
prs = Presentation()
|
| 27 |
+
|
| 28 |
+
# --- Title Slide ---
|
| 29 |
+
title_slide_layout = prs.slide_layouts[0]
|
| 30 |
+
slide = prs.slides.add_slide(title_slide_layout)
|
| 31 |
+
slide.shapes.title.text = title
|
| 32 |
+
slide.placeholders[1].text = "Generated by AI Assistant"
|
| 33 |
+
|
| 34 |
+
# --- Content Slides ---
|
| 35 |
+
for slide_text in slides:
|
| 36 |
+
content_slide_layout = prs.slide_layouts[1]
|
| 37 |
+
slide = prs.slides.add_slide(content_slide_layout)
|
| 38 |
+
|
| 39 |
+
lines = slide_text.split("\n")
|
| 40 |
+
slide.shapes.title.text = lines[0][:80]
|
| 41 |
+
|
| 42 |
+
body = slide.placeholders[1].text_frame
|
| 43 |
+
body.clear()
|
| 44 |
+
|
| 45 |
+
for line in lines[1:]:
|
| 46 |
+
p = body.add_paragraph()
|
| 47 |
+
p.text = line.strip()
|
| 48 |
+
p.level = 1
|
| 49 |
+
|
| 50 |
+
prs.save(pptx_path)
|
| 51 |
+
return pptx_path
|
| 52 |
+
|
| 53 |
+
except Exception as e:
|
| 54 |
+
return f"Error creating presentation: {str(e)}"
|