Spaces:
Sleeping
Sleeping
Add slide with double column layout
Browse files
global_config.py
CHANGED
|
@@ -25,8 +25,8 @@ class GlobalConfig:
|
|
| 25 |
PRELOAD_DATA_FILE = 'examples/example_02.json'
|
| 26 |
SLIDES_TEMPLATE_FILE = 'langchain_templates/template_combined.txt'
|
| 27 |
# JSON_TEMPLATE_FILE = 'langchain_templates/text_to_json_template_02.txt'
|
| 28 |
-
INITIAL_PROMPT_TEMPLATE = 'langchain_templates/chat_prompts/
|
| 29 |
-
REFINEMENT_PROMPT_TEMPLATE = 'langchain_templates/chat_prompts/
|
| 30 |
|
| 31 |
PPTX_TEMPLATE_FILES = {
|
| 32 |
'Basic': {
|
|
|
|
| 25 |
PRELOAD_DATA_FILE = 'examples/example_02.json'
|
| 26 |
SLIDES_TEMPLATE_FILE = 'langchain_templates/template_combined.txt'
|
| 27 |
# JSON_TEMPLATE_FILE = 'langchain_templates/text_to_json_template_02.txt'
|
| 28 |
+
INITIAL_PROMPT_TEMPLATE = 'langchain_templates/chat_prompts/initial_template_v3_two_cols.txt'
|
| 29 |
+
REFINEMENT_PROMPT_TEMPLATE = 'langchain_templates/chat_prompts/refinement_template_v3_two_cols.txt'
|
| 30 |
|
| 31 |
PPTX_TEMPLATE_FILES = {
|
| 32 |
'Basic': {
|
helpers/pptx_helper.py
CHANGED
|
@@ -99,15 +99,23 @@ def generate_powerpoint_presentation(
|
|
| 99 |
|
| 100 |
# Add contents in a loop
|
| 101 |
for a_slide in parsed_data['slides']:
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
if not
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
_handle_default_display(slide, a_slide)
|
| 112 |
|
| 113 |
_handle_key_message(
|
|
@@ -178,6 +186,66 @@ def _handle_default_display(
|
|
| 178 |
paragraph.level = an_item[1]
|
| 179 |
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
def _handle_step_by_step_process(
|
| 182 |
slide: pptx.slide.Slide,
|
| 183 |
slide_json: dict,
|
|
@@ -191,7 +259,7 @@ def _handle_step_by_step_process(
|
|
| 191 |
:param slide_json: The content of the slide as JSON data.
|
| 192 |
:param slide_width_inch: The width of the slide in inches.
|
| 193 |
:param slide_height_inch: The height of the slide in inches.
|
| 194 |
-
:return True
|
| 195 |
"""
|
| 196 |
|
| 197 |
if 'bullet_points' in slide_json and slide_json['bullet_points']:
|
|
@@ -363,6 +431,28 @@ if __name__ == '__main__':
|
|
| 363 |
],
|
| 364 |
"key_message": ""
|
| 365 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
{
|
| 367 |
"heading": "Pros of AI",
|
| 368 |
"bullet_points": [
|
|
|
|
| 99 |
|
| 100 |
# Add contents in a loop
|
| 101 |
for a_slide in parsed_data['slides']:
|
| 102 |
+
is_processing_done = _handle_double_col_layout(
|
| 103 |
+
presentation=presentation,
|
| 104 |
+
slide_json=a_slide
|
| 105 |
+
)
|
| 106 |
|
| 107 |
+
if not is_processing_done:
|
| 108 |
+
bullet_slide_layout = presentation.slide_layouts[1]
|
| 109 |
+
slide = presentation.slides.add_slide(bullet_slide_layout)
|
| 110 |
+
|
| 111 |
+
is_processing_done = _handle_step_by_step_process(
|
| 112 |
+
slide=slide,
|
| 113 |
+
slide_json=a_slide,
|
| 114 |
+
slide_width_inch=slide_width_inch,
|
| 115 |
+
slide_height_inch=slide_height_inch,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
if not is_processing_done:
|
| 119 |
_handle_default_display(slide, a_slide)
|
| 120 |
|
| 121 |
_handle_key_message(
|
|
|
|
| 186 |
paragraph.level = an_item[1]
|
| 187 |
|
| 188 |
|
| 189 |
+
def _handle_double_col_layout(
|
| 190 |
+
presentation: pptx.Presentation(),
|
| 191 |
+
slide_json: dict
|
| 192 |
+
) -> bool:
|
| 193 |
+
"""
|
| 194 |
+
Add a slide with a double column layout for comparison.
|
| 195 |
+
|
| 196 |
+
:param presentation: The presentation object.
|
| 197 |
+
:param slide_json: The content of the slide as JSON data.
|
| 198 |
+
:return: True if double col layout has been added; False otherwise.
|
| 199 |
+
"""
|
| 200 |
+
|
| 201 |
+
if 'bullet_points' in slide_json and slide_json['bullet_points']:
|
| 202 |
+
double_col_content = slide_json['bullet_points']
|
| 203 |
+
|
| 204 |
+
if double_col_content and (
|
| 205 |
+
len(double_col_content) == 2
|
| 206 |
+
) and isinstance(double_col_content[0], dict) and isinstance(double_col_content[1], dict):
|
| 207 |
+
slide = presentation.slide_layouts[4]
|
| 208 |
+
slide = presentation.slides.add_slide(slide)
|
| 209 |
+
|
| 210 |
+
shapes = slide.shapes
|
| 211 |
+
title_placeholder = shapes.title
|
| 212 |
+
title_placeholder.text = remove_slide_number_from_heading(slide_json['heading'])
|
| 213 |
+
for placeholder in shapes.placeholders:
|
| 214 |
+
print(placeholder.placeholder_format.idx, placeholder.name)
|
| 215 |
+
# text_frame = body_shape.text_frame
|
| 216 |
+
left_heading, right_heading = shapes.placeholders[1], shapes.placeholders[3]
|
| 217 |
+
left_col, right_col = shapes.placeholders[2], shapes.placeholders[4]
|
| 218 |
+
left_col_frame, right_col_frame = left_col.text_frame, right_col.text_frame
|
| 219 |
+
|
| 220 |
+
if 'heading' in double_col_content[0]:
|
| 221 |
+
left_heading.text = double_col_content[0]['heading']
|
| 222 |
+
if 'bullet_points' in double_col_content[0]:
|
| 223 |
+
flat_items_list = get_flat_list_of_contents(
|
| 224 |
+
double_col_content[0]['bullet_points'], level=0
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
for an_item in flat_items_list:
|
| 228 |
+
paragraph = left_col_frame.add_paragraph()
|
| 229 |
+
paragraph.text = an_item[0].removeprefix(STEP_BY_STEP_PROCESS_MARKER)
|
| 230 |
+
paragraph.level = an_item[1]
|
| 231 |
+
|
| 232 |
+
if 'heading' in double_col_content[1]:
|
| 233 |
+
right_heading.text = double_col_content[1]['heading']
|
| 234 |
+
if 'bullet_points' in double_col_content[1]:
|
| 235 |
+
flat_items_list = get_flat_list_of_contents(
|
| 236 |
+
double_col_content[1]['bullet_points'], level=0
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
for an_item in flat_items_list:
|
| 240 |
+
paragraph = right_col_frame.add_paragraph()
|
| 241 |
+
paragraph.text = an_item[0].removeprefix(STEP_BY_STEP_PROCESS_MARKER)
|
| 242 |
+
paragraph.level = an_item[1]
|
| 243 |
+
|
| 244 |
+
return True
|
| 245 |
+
|
| 246 |
+
return False
|
| 247 |
+
|
| 248 |
+
|
| 249 |
def _handle_step_by_step_process(
|
| 250 |
slide: pptx.slide.Slide,
|
| 251 |
slide_json: dict,
|
|
|
|
| 259 |
:param slide_json: The content of the slide as JSON data.
|
| 260 |
:param slide_width_inch: The width of the slide in inches.
|
| 261 |
:param slide_height_inch: The height of the slide in inches.
|
| 262 |
+
:return True if this slide has a step-by-step process depiction added; False otherwise.
|
| 263 |
"""
|
| 264 |
|
| 265 |
if 'bullet_points' in slide_json and slide_json['bullet_points']:
|
|
|
|
| 431 |
],
|
| 432 |
"key_message": ""
|
| 433 |
},
|
| 434 |
+
{
|
| 435 |
+
"heading": "Pros and Cons: Deep Learning vs. Classical Machine Learning",
|
| 436 |
+
"bullet_points": [
|
| 437 |
+
{
|
| 438 |
+
"heading": "Classical Machine Learning",
|
| 439 |
+
"bullet_points": [
|
| 440 |
+
"Interpretability: Easy to understand the model",
|
| 441 |
+
"Faster Training: Quicker to train models",
|
| 442 |
+
"Scalability: Can handle large datasets"
|
| 443 |
+
]
|
| 444 |
+
},
|
| 445 |
+
{
|
| 446 |
+
"heading": "Deep Learning",
|
| 447 |
+
"bullet_points": [
|
| 448 |
+
"Handling Complex Data: Can learn from raw data",
|
| 449 |
+
"Feature Extraction: Automatically learns features",
|
| 450 |
+
"Improved Accuracy: Achieves higher accuracy"
|
| 451 |
+
]
|
| 452 |
+
}
|
| 453 |
+
],
|
| 454 |
+
"key_message": ""
|
| 455 |
+
},
|
| 456 |
{
|
| 457 |
"heading": "Pros of AI",
|
| 458 |
"bullet_points": [
|
langchain_templates/chat_prompts/initial_template_v3_two_cols.txt
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a helpful, intelligent chatbot. Create the slides for a presentation on the given topic.
|
| 2 |
+
Include main headings for each slide, detailed bullet points for each slide.
|
| 3 |
+
Add relevant content to each slide.
|
| 4 |
+
The content of each slide should be verbose, descriptive, and very detailed.
|
| 5 |
+
If relevant, add one or two examples to illustrate the concept.
|
| 6 |
+
Unless explicitly specified with the topic, create about 10 slides.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
### Topic:
|
| 10 |
+
{question}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
The output must be only a valid and syntactically correct JSON adhering to the following schema:
|
| 14 |
+
{{
|
| 15 |
+
"title": "Presentation Title",
|
| 16 |
+
"slides": [
|
| 17 |
+
{{
|
| 18 |
+
"heading": "Heading for the First Slide",
|
| 19 |
+
"bullet_points": [
|
| 20 |
+
"First bullet point",
|
| 21 |
+
[
|
| 22 |
+
"Sub-bullet point 1",
|
| 23 |
+
"Sub-bullet point 2"
|
| 24 |
+
],
|
| 25 |
+
"Second bullet point"
|
| 26 |
+
],
|
| 27 |
+
"key_message": ""
|
| 28 |
+
}},
|
| 29 |
+
{{
|
| 30 |
+
"heading": "Heading for the Second Slide",
|
| 31 |
+
"bullet_points": [
|
| 32 |
+
"First bullet point",
|
| 33 |
+
"Second bullet item",
|
| 34 |
+
"Third bullet point"
|
| 35 |
+
],
|
| 36 |
+
"key_message": "The key message conveyed in this slide"
|
| 37 |
+
}},
|
| 38 |
+
{{
|
| 39 |
+
"heading": "A slide that describes a step-by-step/sequential process",
|
| 40 |
+
"bullet_points": [
|
| 41 |
+
">> The first step of the process (begins with special marker >>)",
|
| 42 |
+
">> A second step (begins with >>)",
|
| 43 |
+
">> Third step",
|
| 44 |
+
],
|
| 45 |
+
"key_message": ""
|
| 46 |
+
}},
|
| 47 |
+
{{
|
| 48 |
+
"heading": "A slide with a double column layout (useful for side-by-side comparison/contrasting of related concepts, e.g., pros & cons, advantages & risks, old approach vs. modern approach, and so on)",
|
| 49 |
+
"bullet_points": [
|
| 50 |
+
{{
|
| 51 |
+
"heading": "Heading of the left column",
|
| 52 |
+
"bullet_points": [
|
| 53 |
+
"First bullet point",
|
| 54 |
+
"Second bullet item",
|
| 55 |
+
"Third bullet point"
|
| 56 |
+
]
|
| 57 |
+
}},
|
| 58 |
+
{{
|
| 59 |
+
"heading": "Heading of the right column",
|
| 60 |
+
"bullet_points": [
|
| 61 |
+
"First bullet point",
|
| 62 |
+
"Second bullet item",
|
| 63 |
+
"Third bullet point"
|
| 64 |
+
]
|
| 65 |
+
}}
|
| 66 |
+
],
|
| 67 |
+
"key_message": ""
|
| 68 |
+
}}
|
| 69 |
+
]
|
| 70 |
+
}}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
### Some more hints on the slide content and JSON output format:
|
| 74 |
+
- For two or three important slides, generate the key message that those slides convey and assign
|
| 75 |
+
them to the `key_message` elements of JSON output.
|
| 76 |
+
- Identify if a slide describes a step-by-step/sequential process, then begin the bullet points
|
| 77 |
+
with a special marker >>. Limit this to max two or three slides.
|
| 78 |
+
- Add at least one slide with double column layout by generating appropriate content based on
|
| 79 |
+
the description in the above JSON schema.
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
### Output:
|
| 83 |
+
```json
|
langchain_templates/chat_prompts/refinement_template_v3_two_cols.txt
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a helpful, intelligent chatbot. You follow instructions to refine an existing slide deck.
|
| 2 |
+
A list of user instructions is provided below in sequential order -- from the oldest to the latest.
|
| 3 |
+
The previously generated content of the slide deck in JSON format is also provided.
|
| 4 |
+
Follow the instructions to revise the content of the previously generated slides of the presentation on the given topic.
|
| 5 |
+
Include main headings for each slide, detailed bullet points for each slide.
|
| 6 |
+
Add relevant content to each slide.
|
| 7 |
+
The content of the slides should be descriptive, verbose, and detailed.
|
| 8 |
+
If relevant, add one or two examples to illustrate the concept.
|
| 9 |
+
Unless explicitly specified with the topic, create about 10 slides.
|
| 10 |
+
You also fix any syntax error that may be present in the JSON-formatted content.
|
| 11 |
+
|
| 12 |
+
A slide that describes a step-by-step/sequential process begins the bullet points
|
| 13 |
+
with a special marker >>
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
### List of instructions:
|
| 17 |
+
{instructions}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
### Previously generated slide deck content as JSON:
|
| 21 |
+
{previous_content}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
The output must be only a valid and syntactically correct JSON adhering to the following schema:
|
| 25 |
+
{{
|
| 26 |
+
"title": "Presentation Title",
|
| 27 |
+
"slides": [
|
| 28 |
+
{{
|
| 29 |
+
"heading": "Heading for the First Slide",
|
| 30 |
+
"bullet_points": [
|
| 31 |
+
"First bullet point",
|
| 32 |
+
[
|
| 33 |
+
"Sub-bullet point 1",
|
| 34 |
+
"Sub-bullet point 2"
|
| 35 |
+
],
|
| 36 |
+
"Second bullet point"
|
| 37 |
+
],
|
| 38 |
+
"key_message": ""
|
| 39 |
+
}},
|
| 40 |
+
{{
|
| 41 |
+
"heading": "Heading for the Second Slide",
|
| 42 |
+
"bullet_points": [
|
| 43 |
+
"First bullet point",
|
| 44 |
+
"Second bullet item",
|
| 45 |
+
"Third bullet point"
|
| 46 |
+
],
|
| 47 |
+
"key_message": "The key message conveyed in this slide"
|
| 48 |
+
}},
|
| 49 |
+
{{
|
| 50 |
+
"heading": "A slide that describes a step-by-step/sequential process",
|
| 51 |
+
"bullet_points": [
|
| 52 |
+
">> The first step of the process (begins with special marker >>)",
|
| 53 |
+
">> A second step (begins with >>)",
|
| 54 |
+
">> Third step",
|
| 55 |
+
],
|
| 56 |
+
"key_message": ""
|
| 57 |
+
}},
|
| 58 |
+
{{
|
| 59 |
+
"heading": "A slide with a double column layout (useful for side-by-side comparison/contrasting of related concepts, e.g., pros & cons, advantages & risks, old approach vs. modern approach, and so on)",
|
| 60 |
+
"bullet_points": [
|
| 61 |
+
{{
|
| 62 |
+
"heading": "Heading of the left column",
|
| 63 |
+
"bullet_points": [
|
| 64 |
+
"First bullet point",
|
| 65 |
+
"Second bullet item",
|
| 66 |
+
"Third bullet point"
|
| 67 |
+
]
|
| 68 |
+
}},
|
| 69 |
+
{{
|
| 70 |
+
"heading": "Heading of the right column",
|
| 71 |
+
"bullet_points": [
|
| 72 |
+
"First bullet point",
|
| 73 |
+
"Second bullet item",
|
| 74 |
+
"Third bullet point"
|
| 75 |
+
]
|
| 76 |
+
}}
|
| 77 |
+
],
|
| 78 |
+
"key_message": ""
|
| 79 |
+
}}
|
| 80 |
+
]
|
| 81 |
+
}}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
### Some more hints on the slide content and JSON output format:
|
| 85 |
+
- For two or three important slides, generate the key message that those slides convey and assign
|
| 86 |
+
them to the `key_message` elements of JSON output.
|
| 87 |
+
- Identify if a slide describes a step-by-step/sequential process, then begin the bullet points
|
| 88 |
+
with a special marker >>. Limit this to max two or three slides.
|
| 89 |
+
- Add at least one slide with double column layout by generating appropriate content based on
|
| 90 |
+
the description in the above JSON schema.
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
### Output:
|
| 94 |
+
```json
|