From 0cb588f7bf767005199877fa32389b5ef28f71f2 Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:06:02 +0800 Subject: [PATCH] Fix docx parser line bug (#1715) ### What problem does this PR solve? #1704 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: Kevin Hu --- deepdoc/parser/pdf_parser.py | 2 +- rag/app/naive.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/deepdoc/parser/pdf_parser.py b/deepdoc/parser/pdf_parser.py index 31a132adf..0afc67ab1 100644 --- a/deepdoc/parser/pdf_parser.py +++ b/deepdoc/parser/pdf_parser.py @@ -952,7 +952,7 @@ class RAGFlowPdfParser: fnm, str) else pdfplumber.open(BytesIO(fnm)) self.page_images = [p.to_image(resolution=72 * zoomin).annotated for i, p in enumerate(self.pdf.pages[page_from:page_to])] - self.page_chars = [[{**c, 'top': max(0, c['top'] - 10), 'bottom': max(0, c['bottom'] - 10)} for c in page.dedupe_chars().chars if self._has_color(c)] for page in + self.page_chars = [[{**c, 'top': c['top'], 'bottom': c['bottom']} for c in page.dedupe_chars().chars if self._has_color(c)] for page in self.pdf.pages[page_from:page_to]] self.total_page = len(self.pdf.pages) except Exception as e: diff --git a/rag/app/naive.py b/rag/app/naive.py index a22ebf619..ccb357e5e 100644 --- a/rag/app/naive.py +++ b/rag/app/naive.py @@ -23,6 +23,8 @@ from rag.utils import num_tokens_from_string from PIL import Image from functools import reduce from markdown import markdown + + class Docx(DocxParser): def __init__(self): pass @@ -81,7 +83,8 @@ class Docx(DocxParser): continue if 'w:br' in run._element.xml and 'type="page"' in run._element.xml: pn += 1 - new_line = [(line[0], reduce(concat_img, line[1])) for line in lines] + new_line = [(line[0], reduce(concat_img, line[1]) if line[1] else None) for line in lines] + tbls = [] for tb in self.doc.tables: html= ""