Corin1998 commited on
Commit
efc6dd5
·
verified ·
1 Parent(s): c1a58c7

Update export/ppt.py

Browse files
Files changed (1) hide show
  1. export/ppt.py +36 -35
export/ppt.py CHANGED
@@ -1,44 +1,45 @@
 
1
  from pptx import Presentation
2
- from pptx.util import Pt
3
 
4
- def _add_slide(prs, title, bullets, footnotes):
5
- slide_layout = prs.slide_layouts[1]
6
- slide = prs.slides.add_slide(slide_layout)
7
- slide.shapes.title.text = title
8
- body = slide.shapes.placeholders[1].text_frame
9
- body.clear()
10
- for b in bullets:
11
- p = body.add_paragraph()
12
- p.text = b
 
 
 
 
 
 
13
  p.level = 0
14
- tx = slide.shapes.add_textbox(left=Pt(10), top=Pt(680), width=Pt(900), height=Pt(40)).text_frame
15
- tx.text = "Sources: " + " ".join([f"[{i}] {u}" for i, u in footnotes])
16
- tx.paragraphs[0].font.size = Pt(8)
17
 
18
- def build_deck(summary_sections: dict, links):
19
  prs = Presentation()
20
- _add_slide(prs, "IR/PR Co-Pilot Pro 自動生成サマリ", [
21
- "対象: 指定企業の直近開示(EDINET/TDnet)",
22
- "本資料は自動要約(RAG)により生成",
23
- "各ページ末尾に根拠リンク(脚注)を付与"
24
- ], links)
25
- chapter_map = [
26
- ("業績ハイライト", summary_sections.get("highlights", "")),
27
- ("見通し", summary_sections.get("outlook", "")),
28
- ("セグメント", summary_sections.get("segments", "")),
29
- ("財務", summary_sections.get("finance", "")),
30
- ("株主還元", summary_sections.get("shareholder", "")),
31
- ("ESG", summary_sections.get("esg", "")),
32
- ("リスク", summary_sections.get("risks", "")),
33
- ]
34
- for title, text in chapter_map:
35
- bullets = [s.strip("- ").strip() for s in text.split("\n") if s.strip()]
36
- bullets = bullets[:6]
37
- _add_slide(prs, title, bullets, links)
38
- _add_slide(prs, "想定Q&A(ダイジェスト1/2)", ["詳細は添付CSV参照"], links)
39
- _add_slide(prs, "想定Q&A(ダイジェスト2/2)", ["詳細は添付CSV参照"], links)
40
  return prs
41
 
42
- def save_pptx(prs, path="data/ir_summary.pptx"):
 
 
43
  prs.save(path)
44
  return path
 
1
+ # export/ppt.py
2
  from pptx import Presentation
3
+ from typing import Dict, List
4
 
5
+ def _add_bullets(prs: Presentation, title: str, body: str):
6
+ layout = prs.slide_layouts[1] # Title and Content
7
+ s = prs.slides.add_slide(layout)
8
+ s.shapes.title.text = title
9
+ tf = s.placeholders[1].text_frame
10
+ tf.clear()
11
+ lines = [l.strip("•-  ") for l in (body or "").splitlines() if l.strip()]
12
+ if not lines: lines = ["(なし)"]
13
+ first = True
14
+ for line in lines:
15
+ if first:
16
+ p = tf.paragraphs[0]; first = False
17
+ else:
18
+ p = tf.add_paragraph()
19
+ p.text = line
20
  p.level = 0
 
 
 
21
 
22
+ def build_deck(sections: Dict[str, str], links: List[str]) -> Presentation:
23
  prs = Presentation()
24
+ title_slide_layout = prs.slide_layouts[0]
25
+ s0 = prs.slides.add_slide(title_slide_layout)
26
+ s0.shapes.title.text = "IR/PR サマリー"
27
+ s0.placeholders[1].text = "自動生成(RAG)"
28
+
29
+ _add_bullets(prs, "業績ハイライト", sections.get("highlights",""))
30
+ _add_bullets(prs, "見通し", sections.get("outlook",""))
31
+ _add_bullets(prs, "セグメント", sections.get("segments",""))
32
+ _add_bullets(prs, "財務", sections.get("finance",""))
33
+ _add_bullets(prs, "株主還元", sections.get("shareholder",""))
34
+ _add_bullets(prs, "ESG", sections.get("esg",""))
35
+ _add_bullets(prs, "リスク", sections.get("risks",""))
36
+
37
+ # 参考リンク
38
+ _add_bullets(prs, "参考リンク", "\n".join(links or []))
 
 
 
 
 
39
  return prs
40
 
41
+ def save_pptx(prs: Presentation, path: str) -> str:
42
+ import os
43
+ os.makedirs(os.path.dirname(path), exist_ok=True)
44
  prs.save(path)
45
  return path