Embed summary in transcript DOCX for 'Transcribe & summarize'; remove separate summary files
This commit is contained in:
+32
-4
@@ -439,7 +439,7 @@ def _add_transcript_paragraph(doc, line_text, line_number):
|
||||
|
||||
# ------------ Public DOCX functions ------------
|
||||
|
||||
def create_transcript_docx(text: str, filename: str):
|
||||
def create_transcript_docx(text: str, filename: str, summary_text: str = ""):
|
||||
"""
|
||||
Create a transcript DOCX with:
|
||||
- 1" margins on all sides
|
||||
@@ -450,10 +450,14 @@ def create_transcript_docx(text: str, filename: str):
|
||||
- Blank spacing between number and text preserved
|
||||
- Page break after every 29 lines
|
||||
- Centered footer: "X of Y"
|
||||
- If summary_text is provided:
|
||||
- Page break after transcript
|
||||
- Centered "SUMMARY" title
|
||||
- Summary content (markdown-aware)
|
||||
"""
|
||||
from . import docx_styles
|
||||
|
||||
# Step 1: Prepare transcript into pages of 29 lines each
|
||||
# Each line <= 60 chars total, words preserved, no clipping
|
||||
# Structure: nested list of paragraphs (pages -> lines)
|
||||
prepared_pages = []
|
||||
current_page = []
|
||||
line_count = 0
|
||||
@@ -535,7 +539,31 @@ def create_transcript_docx(text: str, filename: str):
|
||||
for line_num, line_text in enumerate(page_lines, start=1):
|
||||
_add_transcript_paragraph(doc, line_text, line_number=line_num)
|
||||
|
||||
# Step 5: Add footer: "X of Y" centered
|
||||
# Step 5: If summary_text provided, append it with page break
|
||||
if summary_text and summary_text.strip():
|
||||
# Page break after transcript
|
||||
p_break = doc.add_paragraph()
|
||||
pPr = p_break._p.get_or_add_pPr()
|
||||
for child in list(pPr):
|
||||
tag = child.tag.split("}")[-1] if "}" in child.tag else child.tag
|
||||
if tag in ("tabs", "spacing", "ind"):
|
||||
pPr.remove(child)
|
||||
page_break = OxmlElement("w:pageBreak")
|
||||
page_break.set("{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val", "1")
|
||||
pPr.append(page_break)
|
||||
|
||||
# Centered "SUMMARY" title
|
||||
title_p = doc.add_paragraph()
|
||||
title_p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
run = title_p.add_run("SUMMARY")
|
||||
run.font.name = "Courier"
|
||||
run.font.size = Pt(18)
|
||||
run.bold = True
|
||||
|
||||
# Add summary content using markdown-aware styling
|
||||
docx_styles.parse_simple_md_to_paragraphs(doc, summary_text.strip())
|
||||
|
||||
# Step 6: Add footer: "X of Y" centered
|
||||
section = doc.sections[0]
|
||||
footer = section.footer
|
||||
footer.is_linked_to_previous = False
|
||||
|
||||
Reference in New Issue
Block a user