feat: lecture des .pptx dans inputs/ via python-pptx
This commit is contained in:
@@ -299,6 +299,34 @@ def _read_docx(path: Path) -> str:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def _read_pptx(path: Path) -> str:
|
||||||
|
"""Extrait le texte (titres, corps, notes) d'un PPTX via python-pptx."""
|
||||||
|
try:
|
||||||
|
from pptx import Presentation
|
||||||
|
prs = Presentation(str(path))
|
||||||
|
chunks = []
|
||||||
|
for i, slide in enumerate(prs.slides, 1):
|
||||||
|
texts = []
|
||||||
|
for shape in slide.shapes:
|
||||||
|
if shape.has_text_frame and shape.text_frame.text.strip():
|
||||||
|
texts.append(shape.text_frame.text.strip())
|
||||||
|
elif shape.has_table:
|
||||||
|
for row in shape.table.rows:
|
||||||
|
cells = [c.text.strip() for c in row.cells]
|
||||||
|
if any(cells):
|
||||||
|
texts.append(" | ".join(cells))
|
||||||
|
if slide.has_notes_slide:
|
||||||
|
notes = slide.notes_slide.notes_text_frame.text.strip()
|
||||||
|
if notes:
|
||||||
|
texts.append(f"[Notes] {notes}")
|
||||||
|
if texts:
|
||||||
|
chunks.append(f"-- Slide {i} --\n" + "\n".join(texts))
|
||||||
|
return "\n\n".join(chunks)
|
||||||
|
except Exception as e:
|
||||||
|
warn(f"PPTX illisible ({path.name}) : {e}")
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def load_documents(proj: Project, already_loaded: set) -> tuple[str, set]:
|
def load_documents(proj: Project, already_loaded: set) -> tuple[str, set]:
|
||||||
"""
|
"""
|
||||||
Charge les fichiers de inputs/ non encore injectés.
|
Charge les fichiers de inputs/ non encore injectés.
|
||||||
@@ -328,6 +356,8 @@ def load_documents(proj: Project, already_loaded: set) -> tuple[str, set]:
|
|||||||
txt = _read_pdf(f)
|
txt = _read_pdf(f)
|
||||||
elif ext == ".docx":
|
elif ext == ".docx":
|
||||||
txt = _read_docx(f)
|
txt = _read_docx(f)
|
||||||
|
elif ext == ".pptx":
|
||||||
|
txt = _read_pptx(f)
|
||||||
elif ext in (".txt", ".md", ".markdown", ".csv"):
|
elif ext in (".txt", ".md", ".markdown", ".csv"):
|
||||||
txt = f.read_text(encoding="utf-8", errors="replace")
|
txt = f.read_text(encoding="utf-8", errors="replace")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user