Spaces:
Sleeping
Sleeping
Update export/ppt.py
Browse files- export/ppt.py +36 -35
export/ppt.py
CHANGED
|
@@ -1,44 +1,45 @@
|
|
|
|
|
| 1 |
from pptx import Presentation
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
for
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(
|
| 19 |
prs = Presentation()
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 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
|
|
|
|
|
|
|
| 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
|