Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pdf-miner
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Qin Kaijie
pdf-miner
Commits
ec1a6ef7
Commit
ec1a6ef7
authored
Mar 12, 2024
by
赵小蒙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加生成多模态markdown逻辑
parent
3c8b2545
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
ocr_mkcontent.py
magic_pdf/dict2md/ocr_mkcontent.py
+28
-0
ocr_cut_image.py
magic_pdf/pre_proc/ocr_cut_image.py
+2
-2
No files found.
magic_pdf/dict2md/ocr_mkcontent.py
View file @
ec1a6ef7
...
...
@@ -21,3 +21,31 @@ def mk_nlp_markdown(pdf_info_dict: dict):
# 在行末添加两个空格以强制换行
markdown
.
append
(
line_text
.
strip
()
+
' '
)
return
'
\n
'
.
join
(
markdown
)
def
mk_mm_markdown
(
pdf_info_dict
:
dict
):
markdown
=
[]
for
_
,
page_info
in
pdf_info_dict
.
items
():
blocks
=
page_info
.
get
(
"preproc_blocks"
)
if
not
blocks
:
continue
for
block
in
blocks
:
for
line
in
block
[
'lines'
]:
line_text
=
''
for
span
in
line
[
'spans'
]:
if
not
span
.
get
(
'content'
):
if
not
span
.
get
(
'image_path'
):
continue
else
:
content
=
f
""
else
:
content
=
span
[
'content'
]
.
replace
(
'$'
,
'
\
$'
)
# 转义$
if
span
[
'type'
]
==
'inline_equation'
:
content
=
f
"${content}$"
elif
span
[
'type'
]
==
'displayed_equation'
:
content
=
f
"$$
\n
{content}
\n
$$"
line_text
+=
content
+
' '
# 在行末添加两个空格以强制换行
markdown
.
append
(
line_text
.
strip
()
+
' '
)
return
'
\n
'
.
join
(
markdown
)
magic_pdf/pre_proc/ocr_cut_image.py
View file @
ec1a6ef7
...
...
@@ -12,8 +12,8 @@ def cut_image_and_table(spans, page, page_id, book_name, save_path):
for
span
in
spans
:
span_type
=
span
[
'type'
]
if
span_type
==
'image'
:
span
[
'image_path'
]
=
cut_image
(
span
[
'bbox'
],
page_id
,
page
,
img_save_path
(
'image'
))
span
[
'image_path'
]
=
cut_image
(
span
[
'bbox'
],
page_id
,
page
,
img_save_path
(
'image
s
'
))
elif
span_type
==
'table'
:
span
[
'image_path'
]
=
cut_image
(
span
[
'bbox'
],
page_id
,
page
,
img_save_path
(
'table'
))
span
[
'image_path'
]
=
cut_image
(
span
[
'bbox'
],
page_id
,
page
,
img_save_path
(
'table
s
'
))
return
spans
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment