Embed summary in transcript DOCX for 'Transcribe & summarize'; remove separate summary files
Mirror and run GitLab CI / build (push) Has been cancelled
Ruff / ruff (push) Has been cancelled

This commit is contained in:
admin
2026-06-20 03:58:37 +00:00
parent 5b5904c354
commit 800a009c85
2 changed files with 46 additions and 32 deletions
+32 -4
View File
@@ -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
+10 -24
View File
@@ -417,8 +417,15 @@ def process_transcription_task(
f.write(transcript_text)
temp_files.append(md_transcript_path)
# Transcript .docx (standalone, no cover page)
# Transcript .docx (with summary appended if transcript_and_summarize)
docx_transcript_path = _safe_filename("TRANSCRIPT", local, date_tag, ".docx")
if summary_text:
create_transcript_docx(
transcript_text,
docx_transcript_path,
summary_text=summary_text,
)
else:
create_transcript_docx(
transcript_text,
docx_transcript_path,
@@ -445,25 +452,8 @@ def process_transcription_task(
json.dump(json_data, f, indent=2, ensure_ascii=False)
temp_files.append(json_path)
# Summary files (if present)
md_summary_path = None
docx_summary_path = None
if summary_text:
# Summary .md
md_summary_path = _safe_filename("SUMMARY", local, date_tag, ".md")
with open(md_summary_path, "w", encoding="utf-8") as f:
f.write("# Summary\n\n")
f.write(summary_text)
temp_files.append(md_summary_path)
# Summary .docx (standalone, no cover page)
docx_summary_path = _safe_filename("SUMMARY", local, date_tag, ".docx")
create_summary_docx(
summary_text,
docx_summary_path,
)
temp_files.append(docx_summary_path)
# No separate summary DOCX/MD when using transcript_and_summarize
# (summary is now embedded in the transcript DOCX)
# 5) Build attachments list
@@ -474,10 +464,6 @@ def process_transcription_task(
json_path,
]
# If summary is present, add summary MD and DOCX
if summary_text:
attachments += [md_summary_path, docx_summary_path]
# 6) Send success email
send_success_email(
to=email_to,