File size: 1,537 Bytes
1f2480c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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

        # Create temp directory
        temp_dir = tempfile.mkdtemp()
        pptx_path = os.path.join(temp_dir, "generated_presentation.pptx")

        prs = Presentation()

        # --- Title Slide ---
        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"

        # --- Content Slides ---
        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)}"