|
|
from smolagents import tool |
|
|
import tempfile |
|
|
import os |
|
|
|
|
|
@tool |
|
|
def create_presentation( |
|
|
title: str, |
|
|
slides: list[str] |
|
|
) -> str: |
|
|
""" |
|
|
Creates a PowerPoint presentation (.pptx). |
|
|
|
|
|
Args: |
|
|
title: Title of the presentation |
|
|
slides: A list of slide contents. Each item represents one slide. |
|
|
Use '\\n' inside a slide to create bullet points. |
|
|
""" |
|
|
try: |
|
|
from pptx import Presentation |
|
|
from pptx.util import Inches, Pt |
|
|
|
|
|
|
|
|
temp_dir = tempfile.mkdtemp() |
|
|
pptx_path = os.path.join(temp_dir, "generated_presentation.pptx") |
|
|
|
|
|
prs = Presentation() |
|
|
|
|
|
|
|
|
title_slide_layout = prs.slide_layouts[0] |
|
|
slide = prs.slides.add_slide(title_slide_layout) |
|
|
slide.shapes.title.text = title |
|
|
slide.placeholders[1].text = "Generated by AI Assistant" |
|
|
|
|
|
|
|
|
for slide_text in slides: |
|
|
content_slide_layout = prs.slide_layouts[1] |
|
|
slide = prs.slides.add_slide(content_slide_layout) |
|
|
|
|
|
lines = slide_text.split("\n") |
|
|
slide.shapes.title.text = lines[0][:80] |
|
|
|
|
|
body = slide.placeholders[1].text_frame |
|
|
body.clear() |
|
|
|
|
|
for line in lines[1:]: |
|
|
p = body.add_paragraph() |
|
|
p.text = line.strip() |
|
|
p.level = 1 |
|
|
|
|
|
prs.save(pptx_path) |
|
|
return pptx_path |
|
|
|
|
|
except Exception as e: |
|
|
return f"Error creating presentation: {str(e)}" |
|
|
|