Spaces:
Runtime error
Runtime error
Create exporters.py
Browse files- modules/exporters.py +55 -0
modules/exporters.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from docx import Document
|
| 3 |
+
from pptx import Presentation
|
| 4 |
+
|
| 5 |
+
EXPORT_DIR = Path("data")
|
| 6 |
+
|
| 7 |
+
def export_docx(proposal_markdown: str, company_name: str) -> str:
|
| 8 |
+
EXPORT_DIR.mkdir(parents=True, exist_ok=True)
|
| 9 |
+
doc = Document()
|
| 10 |
+
doc.add_heading(f"提案書({company_name}向け)", level=1)
|
| 11 |
+
for line in proposal_markdown.splitlines():
|
| 12 |
+
if line.startswith("#"):
|
| 13 |
+
doc.add_heading(line.lstrip("# ").strip(), level=2)
|
| 14 |
+
else:
|
| 15 |
+
doc.add_paragraph(line)
|
| 16 |
+
path = EXPORT_DIR / f"proposal_{company_name}.docx"
|
| 17 |
+
doc.save(path)
|
| 18 |
+
return str(path)
|
| 19 |
+
|
| 20 |
+
def export_pptx(proposal_markdown: str, company_name: str) -> str:
|
| 21 |
+
EXPORT_DIR.mkdir(parents=True, exist_ok=True)
|
| 22 |
+
prs = Presentation()
|
| 23 |
+
# タイトル
|
| 24 |
+
slide = prs.slides.add_slide(prs.slide_layouts[0])
|
| 25 |
+
slide.shapes.title.text = f"提案({company_name}向け)"
|
| 26 |
+
slide.placeholders[1].text = "Agent Studio"
|
| 27 |
+
|
| 28 |
+
# セクション分割
|
| 29 |
+
sections = []
|
| 30 |
+
current = {"title": "概要", "bullets": []}
|
| 31 |
+
for line in proposal_markdown.splitlines():
|
| 32 |
+
if line.startswith("#"):
|
| 33 |
+
if current["bullets"]:
|
| 34 |
+
sections.append(current)
|
| 35 |
+
current = {"title": line.lstrip("# ").strip(), "bullets": []}
|
| 36 |
+
elif line.strip():
|
| 37 |
+
current["bullets"].append(line.strip())
|
| 38 |
+
if current["bullets"]:
|
| 39 |
+
sections.append(current)
|
| 40 |
+
|
| 41 |
+
for sec in sections:
|
| 42 |
+
s = prs.slides.add_slide(prs.slide_layouts[1])
|
| 43 |
+
s.shapes.title.text = sec["title"]
|
| 44 |
+
body = s.placeholders[1].text_frame
|
| 45 |
+
first = True
|
| 46 |
+
for b in sec["bullets"][:8]:
|
| 47 |
+
if first:
|
| 48 |
+
body.text = b
|
| 49 |
+
first = False
|
| 50 |
+
else:
|
| 51 |
+
body.add_paragraph().text = b
|
| 52 |
+
|
| 53 |
+
path = EXPORT_DIR / f"proposal_{company_name}.pptx"
|
| 54 |
+
prs.save(path)
|
| 55 |
+
return str(path)
|