diff --git a/src/spooklight/completion/build_pdf_from_story_files.py b/src/spooklight/completion/build_pdf_from_story_files.py index 18410bc..2b431e1 100644 --- a/src/spooklight/completion/build_pdf_from_story_files.py +++ b/src/spooklight/completion/build_pdf_from_story_files.py @@ -1,8 +1,8 @@ import os from colorama import Back, Fore from reportlab.lib.pagesizes import letter -from reportlab.lib.styles import getSampleStyleSheet -from reportlab.platypus import SimpleDocTemplate, Paragraph, Image, Spacer +from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle +from reportlab.platypus import SimpleDocTemplate, Paragraph, Image, Spacer, PageBreak from reportlab.lib.units import inch from spooklight.settings import Settings @@ -23,17 +23,31 @@ def build_pdf_from_story_files() -> None: styles = getSampleStyleSheet() story_flow = [] - # Add a title page + # Add a title page with the story concept (Concept) title_file = os.path.join(output_dir, "title.txt") + concept_file = os.path.join(output_dir, "concept.txt") + if os.path.exists(title_file): with open(title_file, "r") as f: title = f.read().strip() title_style = styles["Title"] story_flow.append(Paragraph(title, title_style)) - story_flow.append(Spacer(1, 2 * inch)) # Adds some space after the title + story_flow.append(Spacer(1, 0.5 * inch)) # Adds some space after the title else: print(Fore.RED + f"Warning: Title file '{title_file}' not found.") + if os.path.exists(concept_file): + with open(concept_file, "r") as f: + concept = f.read().strip() + concept_heading = Paragraph("Concept", styles["Heading2"]) + concept_text = Paragraph(concept, styles["BodyText"]) + story_flow.append(concept_heading) + story_flow.append(Spacer(1, 0.2 * inch)) # Space after the heading + story_flow.append(concept_text) + story_flow.append(PageBreak()) # Start a new page after the concept + else: + print(Fore.RED + f"Warning: Concept file '{concept_file}' not found.") + # Add each step to the PDF step = 0 while True: @@ -43,15 +57,15 @@ def build_pdf_from_story_files() -> None: if not os.path.exists(narrative_file) or not os.path.exists(image_file): break + # Add image + story_flow.append(Image(image_file, width=6 * inch, height=4.5 * inch)) + story_flow.append(Spacer(1, 0.5 * inch)) # Space between image and narrative + # Add narrative with open(narrative_file, "r") as f: narrative = f.read().strip() story_flow.append(Paragraph(narrative, styles["BodyText"])) - story_flow.append(Spacer(1, 0.5 * inch)) # Space between narrative and image - - # Add image - story_flow.append(Image(image_file, width=6 * inch, height=4.5 * inch)) - story_flow.append(Spacer(1, 1 * inch)) # Space before the next step + story_flow.append(PageBreak()) # Start a new page for the next step step += 1 diff --git a/src/spooklight/generate_story.py b/src/spooklight/generate_story.py index 8640e77..db36e67 100644 --- a/src/spooklight/generate_story.py +++ b/src/spooklight/generate_story.py @@ -39,6 +39,11 @@ def generate_story( starting_image_description=starting_image_description, ) + # Save the story concept to a file in the output directory with a name like "concept.txt" + output_dir = Settings.get_output_directory() + with open(f"{output_dir}/concept.txt", "w") as f: + f.write(story.concept) + # Generate the first story step generate_first_step( llm_client=llm_client, @@ -57,7 +62,6 @@ def generate_story( story.title = generate_title_from_narrative(llm_client, story) # Save the title to a file in the output directory with a name like "title.txt" - output_dir = Settings.get_output_directory() with open(f"{output_dir}/title.txt", "w") as f: f.write(story.title)