ReproAgent / server /ppt_generator.py
Yusufarsh's picture
Upload 9 files
80f8512 verified
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