Spaces:
Paused
Paused
File size: 975 Bytes
0017280 9815e49 0017280 f95cdb7 fbd18c8 f95cdb7 fbd18c8 f95cdb7 0017280 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | """Reader for Word .docx files."""
def read_docx(file_path: str) -> list[dict]:
try:
from docx import Document
doc = Document(file_path)
paragraphs = [p.text.strip() for p in doc.paragraphs if p.text.strip()]
# Extract embedded tables
for table in doc.tables:
for row in table.rows:
seen_elements = set()
cells = []
for cell in row.cells:
if id(cell._element) not in seen_elements:
seen_elements.add(id(cell._element))
if cell.text.strip():
cells.append(cell.text.strip())
if cells:
paragraphs.append(" | ".join(cells))
if not paragraphs:
return []
return [{"page": 1, "text": "\n\n".join(paragraphs)}]
except Exception as e:
print(f"Warning: Could not read {file_path}: {e}")
return []
|