File size: 3,268 Bytes
80f8512
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.text import PP_ALIGN
from pptx.dml.color import RGBColor

def create_ppt(slides_data, output_path):
    """

    Creates a premium, highly stylized PowerPoint presentation.

    """
    prs = Presentation()
    
    # Define colors
    bg_color = RGBColor(15, 23, 42) # #0F172A (Deep Navy)
    accent_color = RGBColor(59, 130, 246) # #3B82F6 (Bright Blue)
    text_color = RGBColor(248, 250, 252) # #F8FAFC (Near White)
    
    def apply_slide_background(slide):
        background = slide.background
        fill = background.fill
        fill.solid()
        fill.fore_color.rgb = bg_color

    def add_header_bar(slide):
        # Add a decorative accent bar at the top
        left = Inches(0)
        top = Inches(0)
        width = prs.slide_width
        height = Inches(0.1)
        shape = slide.shapes.add_shape(1, left, top, width, height) # 1 is Rectangle
        shape.fill.solid()
        shape.fill.fore_color.rgb = accent_color
        shape.line.fill.background()

    # 1. Title Slide
    title_layout = prs.slide_layouts[0]
    slide = prs.slides.add_slide(title_layout)
    apply_slide_background(slide)
    add_header_bar(slide)
    
    title = slide.shapes.title
    subtitle = slide.placeholders[1]
    
    title.text = slides_data[0].get("title", "Research Presentation") if slides_data else "Research Presentation"
    subtitle.text = "Generated by RepoAgent · Easy Mode"
    
    # Style title
    title.text_frame.paragraphs[0].font.color.rgb = text_color
    title.text_frame.paragraphs[0].font.bold = True
    subtitle.text_frame.paragraphs[0].font.color.rgb = accent_color
    
    # 2. Content Slides
    for slide_info in slides_data[1:]:
        # Use a blank layout to have full control
        blank_layout = prs.slide_layouts[6]
        slide = prs.slides.add_slide(blank_layout)
        apply_slide_background(slide)
        add_header_bar(slide)
        
        # Title
        left = Inches(0.5)
        top = Inches(0.4)
        width = prs.slide_width - Inches(1)
        height = Inches(1)
        
        txBox = slide.shapes.add_textbox(left, top, width, height)
        tf = txBox.text_frame
        p = tf.paragraphs[0]
        p.text = slide_info.get("title", "Key Point")
        p.font.bold = True
        p.font.size = Pt(32)
        p.font.color.rgb = accent_color
        
        # Content
        left = Inches(0.5)
        top = Inches(1.5)
        width = prs.slide_width - Inches(1)
        height = prs.slide_height - Inches(2)
        
        contentBox = slide.shapes.add_textbox(left, top, width, height)
        ctf = contentBox.text_frame
        ctf.word_wrap = True
        
        for idx, point in enumerate(slide_info.get("content", [])):
            if idx == 0:
                p = ctf.paragraphs[0]
            else:
                p = ctf.add_paragraph()
            
            p.text = f"• {point}"
            p.font.size = Pt(18)
            p.font.color.rgb = text_color
            p.space_after = Pt(10)
            
    # Save the presentation
    prs.save(output_path)
    return output_path