Spaces:
Running
Running
Add three presentation templates and remove background colors
Browse files- .gitignore +1 -1
- app.py +22 -1
- global_config.py +15 -0
- pptx_helper.py +17 -10
- pptx_templates/Blank.pptx +0 -0
- pptx_templates/Ion_Boardroom.pptx +0 -0
- pptx_templates/Urban_monochrome.pptx +0 -0
.gitignore
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
client_secret.json
|
2 |
credentials.json
|
3 |
token.json
|
4 |
-
|
5 |
|
6 |
|
7 |
### Python template
|
|
|
1 |
client_secret.json
|
2 |
credentials.json
|
3 |
token.json
|
4 |
+
/*.pptx
|
5 |
|
6 |
|
7 |
### Python template
|
app.py
CHANGED
@@ -31,6 +31,7 @@ def build_ui():
|
|
31 |
except (FileExistsError, FileNotFoundError):
|
32 |
preload_data = {'topic': '', 'audience': ''}
|
33 |
|
|
|
34 |
topic = st.text_area(
|
35 |
APP_TEXT['input_labels'][0],
|
36 |
value=preload_data['topic']
|
@@ -38,8 +39,14 @@ def build_ui():
|
|
38 |
|
39 |
# Button with callback function
|
40 |
st.button(APP_TEXT['button_labels'][0], on_click=button_clicked, args=[0])
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
if st.session_state.clicked[0]:
|
|
|
43 |
progress_text = 'Generating your presentation slides...give it a moment'
|
44 |
progress_bar = st.progress(0, text=progress_text)
|
45 |
|
@@ -59,7 +66,7 @@ def process_topic_inputs(topic: str, progress_bar):
|
|
59 |
topic_length = len(topic)
|
60 |
print(f'Input length:: topic: {topic_length}')
|
61 |
|
62 |
-
if topic_length
|
63 |
print(
|
64 |
f'Topic: {topic}\n'
|
65 |
)
|
@@ -139,9 +146,22 @@ def process_slides_contents(text: str, progress_bar: st.progress):
|
|
139 |
st.header(APP_TEXT['section_headers'][2])
|
140 |
st.caption(APP_TEXT['section_captions'][2])
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
st.button(APP_TEXT['button_labels'][2], on_click=button_clicked, args=[2])
|
|
|
143 |
|
144 |
if st.session_state.clicked[2]:
|
|
|
145 |
progress_text = 'Creating the slide deck...give it a moment'
|
146 |
progress_bar = st.progress(0, text=progress_text)
|
147 |
|
@@ -154,6 +174,7 @@ def process_slides_contents(text: str, progress_bar: st.progress):
|
|
154 |
all_headers = pptx_helper.generate_powerpoint_presentation(
|
155 |
json_str,
|
156 |
as_yaml=False,
|
|
|
157 |
output_file_name=output_file_name
|
158 |
)
|
159 |
progress_bar.progress(100, text='Done!')
|
|
|
31 |
except (FileExistsError, FileNotFoundError):
|
32 |
preload_data = {'topic': '', 'audience': ''}
|
33 |
|
34 |
+
# with st.form('describe-topic-form'):
|
35 |
topic = st.text_area(
|
36 |
APP_TEXT['input_labels'][0],
|
37 |
value=preload_data['topic']
|
|
|
39 |
|
40 |
# Button with callback function
|
41 |
st.button(APP_TEXT['button_labels'][0], on_click=button_clicked, args=[0])
|
42 |
+
# desc_topic_btn_submitted = st.form_submit_button(
|
43 |
+
# APP_TEXT['button_labels'][0],
|
44 |
+
# on_click=button_clicked,
|
45 |
+
# args=[0]
|
46 |
+
# )
|
47 |
|
48 |
if st.session_state.clicked[0]:
|
49 |
+
# if desc_topic_btn_submitted:
|
50 |
progress_text = 'Generating your presentation slides...give it a moment'
|
51 |
progress_bar = st.progress(0, text=progress_text)
|
52 |
|
|
|
66 |
topic_length = len(topic)
|
67 |
print(f'Input length:: topic: {topic_length}')
|
68 |
|
69 |
+
if topic_length >= 10:
|
70 |
print(
|
71 |
f'Topic: {topic}\n'
|
72 |
)
|
|
|
146 |
st.header(APP_TEXT['section_headers'][2])
|
147 |
st.caption(APP_TEXT['section_captions'][2])
|
148 |
|
149 |
+
texts = list(GlobalConfig.PPTX_TEMPLATE_FILES.keys())
|
150 |
+
captions = [GlobalConfig.PPTX_TEMPLATE_FILES[x]['caption'] for x in texts]
|
151 |
+
|
152 |
+
# with st.form('create-slides-form'):
|
153 |
+
pptx_template = st.radio(
|
154 |
+
'Select a presentation template:',
|
155 |
+
texts,
|
156 |
+
captions=captions,
|
157 |
+
horizontal=True
|
158 |
+
)
|
159 |
+
|
160 |
st.button(APP_TEXT['button_labels'][2], on_click=button_clicked, args=[2])
|
161 |
+
# create_slides_btn_submitted = st.form_submit_button(APP_TEXT['button_labels'][2])
|
162 |
|
163 |
if st.session_state.clicked[2]:
|
164 |
+
# if create_slides_btn_submitted:
|
165 |
progress_text = 'Creating the slide deck...give it a moment'
|
166 |
progress_bar = st.progress(0, text=progress_text)
|
167 |
|
|
|
174 |
all_headers = pptx_helper.generate_powerpoint_presentation(
|
175 |
json_str,
|
176 |
as_yaml=False,
|
177 |
+
slides_template=pptx_template,
|
178 |
output_file_name=output_file_name
|
179 |
)
|
180 |
progress_bar.progress(100, text='Done!')
|
global_config.py
CHANGED
@@ -28,3 +28,18 @@ class GlobalConfig:
|
|
28 |
PRELOAD_DATA_FILE = 'examples/example_02.json'
|
29 |
SLIDES_TEMPLATE_FILE = 'langchain_templates/template_07.txt'
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
PRELOAD_DATA_FILE = 'examples/example_02.json'
|
29 |
SLIDES_TEMPLATE_FILE = 'langchain_templates/template_07.txt'
|
30 |
|
31 |
+
PPTX_TEMPLATE_FILES = {
|
32 |
+
'Blank': {
|
33 |
+
'file': 'pptx_templates/Blank.pptx',
|
34 |
+
'caption': 'Good for starting'
|
35 |
+
},
|
36 |
+
'Ion Boardroom': {
|
37 |
+
'file': 'pptx_templates/Ion_Boardroom.pptx',
|
38 |
+
'caption': 'Choose some bold colors'
|
39 |
+
},
|
40 |
+
'Urban Monochrome': {
|
41 |
+
'file': 'pptx_templates/Urban_monochrome.pptx',
|
42 |
+
'caption': 'Bring in some elegance'
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
pptx_helper.py
CHANGED
@@ -4,7 +4,7 @@ import pptx
|
|
4 |
import re
|
5 |
import yaml
|
6 |
|
7 |
-
from
|
8 |
|
9 |
|
10 |
PATTERN = re.compile(r"^slide[ ]+\d+:", re.IGNORECASE)
|
@@ -24,12 +24,18 @@ def remove_slide_number_from_heading(header: str) -> str:
|
|
24 |
return header
|
25 |
|
26 |
|
27 |
-
def generate_powerpoint_presentation(
|
|
|
|
|
|
|
|
|
|
|
28 |
"""
|
29 |
Create and save a PowerPoint presentation file containing the contents in JSON or YAML format.
|
30 |
|
31 |
:param structured_data: The presentation contents as "JSON" (may contain trailing commas) or YAML
|
32 |
:param as_yaml: True if the input data is in YAML format; False if it is in JSON format
|
|
|
33 |
:param output_file_name: The name of the PPTX file to save as
|
34 |
:return A list of presentation title and slides headers
|
35 |
"""
|
@@ -45,7 +51,8 @@ def generate_powerpoint_presentation(structured_data: str, as_yaml: bool, output
|
|
45 |
# The structured "JSON" might contain trailing commas, so using json5
|
46 |
parsed_data = json5.loads(structured_data)
|
47 |
|
48 |
-
|
|
|
49 |
|
50 |
# The title slide
|
51 |
title_slide_layout = presentation.slide_layouts[0]
|
@@ -57,10 +64,10 @@ def generate_powerpoint_presentation(structured_data: str, as_yaml: bool, output
|
|
57 |
subtitle.text = 'by Myself and SlideDeck AI :)'
|
58 |
all_headers = [title.text, ]
|
59 |
|
60 |
-
background = slide.background
|
61 |
-
background.fill.solid()
|
62 |
-
background.fill.fore_color.rgb = RGBColor.from_string('C0C0C0') # Silver
|
63 |
-
title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 128) # Navy blue
|
64 |
|
65 |
# Add contents in a loop
|
66 |
for a_slide in parsed_data['slides']:
|
@@ -89,9 +96,9 @@ def generate_powerpoint_presentation(structured_data: str, as_yaml: bool, output
|
|
89 |
paragraph.text = sub_item
|
90 |
paragraph.level = 1
|
91 |
|
92 |
-
background = slide.background
|
93 |
-
background.fill.gradient()
|
94 |
-
background.fill.gradient_angle = -225.0
|
95 |
|
96 |
# The thank-you slide
|
97 |
last_slide_layout = presentation.slide_layouts[0]
|
|
|
4 |
import re
|
5 |
import yaml
|
6 |
|
7 |
+
from global_config import GlobalConfig
|
8 |
|
9 |
|
10 |
PATTERN = re.compile(r"^slide[ ]+\d+:", re.IGNORECASE)
|
|
|
24 |
return header
|
25 |
|
26 |
|
27 |
+
def generate_powerpoint_presentation(
|
28 |
+
structured_data: str,
|
29 |
+
as_yaml: bool,
|
30 |
+
slides_template: str,
|
31 |
+
output_file_name: str
|
32 |
+
) -> List:
|
33 |
"""
|
34 |
Create and save a PowerPoint presentation file containing the contents in JSON or YAML format.
|
35 |
|
36 |
:param structured_data: The presentation contents as "JSON" (may contain trailing commas) or YAML
|
37 |
:param as_yaml: True if the input data is in YAML format; False if it is in JSON format
|
38 |
+
:param slides_template: The PPTX template to use
|
39 |
:param output_file_name: The name of the PPTX file to save as
|
40 |
:return A list of presentation title and slides headers
|
41 |
"""
|
|
|
51 |
# The structured "JSON" might contain trailing commas, so using json5
|
52 |
parsed_data = json5.loads(structured_data)
|
53 |
|
54 |
+
print(f"*** Using PPTX template: {GlobalConfig.PPTX_TEMPLATE_FILES[slides_template]['file']}")
|
55 |
+
presentation = pptx.Presentation(GlobalConfig.PPTX_TEMPLATE_FILES[slides_template]['file'])
|
56 |
|
57 |
# The title slide
|
58 |
title_slide_layout = presentation.slide_layouts[0]
|
|
|
64 |
subtitle.text = 'by Myself and SlideDeck AI :)'
|
65 |
all_headers = [title.text, ]
|
66 |
|
67 |
+
# background = slide.background
|
68 |
+
# background.fill.solid()
|
69 |
+
# background.fill.fore_color.rgb = RGBColor.from_string('C0C0C0') # Silver
|
70 |
+
# title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 128) # Navy blue
|
71 |
|
72 |
# Add contents in a loop
|
73 |
for a_slide in parsed_data['slides']:
|
|
|
96 |
paragraph.text = sub_item
|
97 |
paragraph.level = 1
|
98 |
|
99 |
+
# background = slide.background
|
100 |
+
# background.fill.gradient()
|
101 |
+
# background.fill.gradient_angle = -225.0
|
102 |
|
103 |
# The thank-you slide
|
104 |
last_slide_layout = presentation.slide_layouts[0]
|
pptx_templates/Blank.pptx
ADDED
Binary file (33.9 kB). View file
|
|
pptx_templates/Ion_Boardroom.pptx
ADDED
Binary file (619 kB). View file
|
|
pptx_templates/Urban_monochrome.pptx
ADDED
Binary file (44.4 kB). View file
|
|