barunsaha commited on
Commit
41af1c8
1 Parent(s): de061eb

Add some colors to the slides

Browse files
Files changed (1) hide show
  1. pptx_helper.py +17 -2
pptx_helper.py CHANGED
@@ -1,5 +1,6 @@
1
  import json5
2
  import pptx
 
3
 
4
 
5
  def generate_powerpoint_presentation(structured_contents: str, output_file_name: str):
@@ -23,6 +24,11 @@ def generate_powerpoint_presentation(structured_contents: str, output_file_name:
23
  title.text = json_data['presentation_title']
24
  subtitle.text = 'Generated by Slides Wizard AI :)'
25
 
 
 
 
 
 
26
  # Add content in a loop
27
  for a_slide in json_data['slides']:
28
  bullet_slide_layout = presentation.slide_layouts[1]
@@ -31,9 +37,7 @@ def generate_powerpoint_presentation(structured_contents: str, output_file_name:
31
 
32
  title_shape = shapes.title
33
  body_shape = shapes.placeholders[1]
34
-
35
  title_shape.text = a_slide['slide_heading']
36
-
37
  text_frame = body_shape.text_frame
38
 
39
  for an_item in a_slide['slide_contents']:
@@ -41,6 +45,10 @@ def generate_powerpoint_presentation(structured_contents: str, output_file_name:
41
  paragraph.text = an_item
42
  paragraph.level = 0
43
 
 
 
 
 
44
  # The thank-you slide
45
  last_slide_layout = presentation.slide_layouts[0]
46
  slide = presentation.slides.add_slide(last_slide_layout)
@@ -48,3 +56,10 @@ def generate_powerpoint_presentation(structured_contents: str, output_file_name:
48
  title.text = 'Thank you!'
49
 
50
  presentation.save(output_file_name)
 
 
 
 
 
 
 
 
1
  import json5
2
  import pptx
3
+ from pptx.dml.color import RGBColor
4
 
5
 
6
  def generate_powerpoint_presentation(structured_contents: str, output_file_name: str):
 
24
  title.text = json_data['presentation_title']
25
  subtitle.text = 'Generated by Slides Wizard AI :)'
26
 
27
+ background = slide.background
28
+ background.fill.solid()
29
+ background.fill.fore_color.rgb = RGBColor.from_string('C0C0C0') # Silver
30
+ title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 128) # Navy blue
31
+
32
  # Add content in a loop
33
  for a_slide in json_data['slides']:
34
  bullet_slide_layout = presentation.slide_layouts[1]
 
37
 
38
  title_shape = shapes.title
39
  body_shape = shapes.placeholders[1]
 
40
  title_shape.text = a_slide['slide_heading']
 
41
  text_frame = body_shape.text_frame
42
 
43
  for an_item in a_slide['slide_contents']:
 
45
  paragraph.text = an_item
46
  paragraph.level = 0
47
 
48
+ background = slide.background
49
+ background.fill.gradient()
50
+ background.fill.gradient_angle = -225.0
51
+
52
  # The thank-you slide
53
  last_slide_layout = presentation.slide_layouts[0]
54
  slide = presentation.slides.add_slide(last_slide_layout)
 
56
  title.text = 'Thank you!'
57
 
58
  presentation.save(output_file_name)
59
+
60
+
61
+ if __name__ == '__main__':
62
+ generate_powerpoint_presentation(
63
+ json5.loads(open('examples/example_02_structured_output.json', 'r').read()),
64
+ 'test.pptx'
65
+ )