Skip to content

Commit

Permalink
let presentation do raptor (#2838)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

#2837

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
KevinHuSh authored Oct 15, 2024
1 parent 260d694 commit b540d41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions api/apps/document_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,9 @@ def change_parser():
else:
return get_json_result(data=True)

if doc.type == FileType.VISUAL or re.search(
r"\.(ppt|pptx|pages)$", doc.name):
if ((doc.type == FileType.VISUAL and req["parser_id"] != "picture")
or (re.search(
r"\.(ppt|pptx|pages)$", doc.name) and req["parser_id"] != "presentation")):
return get_data_error_result(retmsg="Not supported yet!")

e = DocumentService.update_by_id(doc.id,
Expand Down
11 changes: 10 additions & 1 deletion rag/app/qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __call__(self, fnm, binary=None, callback=None):
[rmPrefix(q) for q, _ in random_choices(res, k=30) if len(q) > 1])
return res


class Pdf(PdfParser):
def __call__(self, filename, binary=None, from_page=0,
to_page=100000, zoomin=3, callback=None):
Expand Down Expand Up @@ -155,6 +156,7 @@ def sort_key(element):
if last_q:
qai_list.append((last_q, last_a, *self.crop(last_tag, need_position=True)))
return qai_list, tbls

def get_tbls_info(self, tbls, tbl_index):
if tbl_index >= len(tbls):
return 1, 0, 0, 0, 0, '@@0\t0\t0\t0\t0##', ''
Expand All @@ -166,10 +168,13 @@ def get_tbls_info(self, tbls, tbl_index):
tbl_tag = "@@{}\t{:.1f}\t{:.1f}\t{:.1f}\t{:.1f}##" \
.format(tbl_pn, tbl_left, tbl_right, tbl_top, tbl_bottom)
tbl_text = ''.join(tbls[tbl_index][0][1])
return tbl_pn, tbl_left, tbl_right, tbl_top, tbl_bottom, tbl_tag, tbl_text
return tbl_pn, tbl_left, tbl_right, tbl_top, tbl_bottom, tbl_tag,


class Docx(DocxParser):
def __init__(self):
pass

def get_picture(self, document, paragraph):
img = paragraph._element.xpath('.//pic:pic')
if not img:
Expand Down Expand Up @@ -242,6 +247,7 @@ def __call__(self, filename, binary=None, from_page=0, to_page=100000, callback=
tbls.append(((None, html), ""))
return qai_list, tbls


def rmPrefix(txt):
return re.sub(
r"^(问题|答案|回答|user|assistant|Q|A|Question|Answer|问|答)[\t:: ]+", "", txt.strip(), flags=re.IGNORECASE)
Expand All @@ -258,6 +264,7 @@ def beAdocPdf(d, q, a, eng, image, poss):
add_positions(d, poss)
return d


def beAdocDocx(d, q, a, eng, image):
qprefix = "Question: " if eng else "问题:"
aprefix = "Answer: " if eng else "回答:"
Expand All @@ -268,6 +275,7 @@ def beAdocDocx(d, q, a, eng, image):
d["image"] = image
return d


def beAdoc(d, q, a, eng):
qprefix = "Question: " if eng else "问题:"
aprefix = "Answer: " if eng else "回答:"
Expand All @@ -282,6 +290,7 @@ def mdQuestionLevel(s):
match = re.match(r'#*', s)
return (len(match.group(0)), s.lstrip('#').lstrip()) if match else (0, s)


def chunk(filename, binary=None, lang="Chinese", callback=None, **kwargs):
"""
Excel and csv(txt) format files are supported.
Expand Down

0 comments on commit b540d41

Please sign in to comment.