Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
zhougaofeng
magic_pdf
Commits
0e8f989e
Commit
0e8f989e
authored
Oct 24, 2024
by
zhougaofeng
Browse files
Update common_parse.py
parent
922eeb6e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
magic_pdf/parse/common_parse.py
magic_pdf/parse/common_parse.py
+14
-6
No files found.
magic_pdf/parse/common_parse.py
View file @
0e8f989e
...
@@ -37,14 +37,15 @@ def process_file(file_path, pdf_ocr, excel_ocr, output_dir):
...
@@ -37,14 +37,15 @@ def process_file(file_path, pdf_ocr, excel_ocr, output_dir):
"""Process a single file for OCR based on its extension."""
"""Process a single file for OCR based on its extension."""
try
:
try
:
res
=
''
res
=
''
start
=
time
.
time
()
if
file_path
.
endswith
(
'.pdf'
):
if
file_path
.
endswith
(
'.pdf'
):
res
=
pdf_ocr
.
ocr_pdf_client
(
path
=
file_path
,
output_dir
=
output_dir
)
res
=
pdf_ocr
.
ocr_pdf_client
(
path
=
file_path
,
output_dir
=
output_dir
)
elif
file_path
.
endswith
(
'.xls'
)
or
file_path
.
endswith
(
'.xlsx'
):
elif
file_path
.
endswith
(
'.xls'
)
or
file_path
.
endswith
(
'.xlsx'
):
res
=
excel_ocr
.
parse
(
file_path
,
output_dir
)
res
=
excel_ocr
.
parse
(
file_path
,
output_dir
)
end
=
time
.
time
()
if
res
:
if
res
:
logger
.
info
(
f
"文件处理成功,输出文件路径为: '
{
res
}
'"
)
logger
.
info
(
f
"文件处理成功,输出文件路径为: '
{
res
}
'
, 耗时为:
{
end
-
start
}
"
)
else
:
else
:
logger
.
warning
(
f
"文件处理结果为空: '
{
file_path
}
'"
)
logger
.
warning
(
f
"文件处理结果为空: '
{
file_path
}
'"
)
except
requests
.
exceptions
.
RequestException
as
req_err
:
except
requests
.
exceptions
.
RequestException
as
req_err
:
...
@@ -83,12 +84,19 @@ def main():
...
@@ -83,12 +84,19 @@ def main():
config
.
read
(
args
.
config_path
)
config
.
read
(
args
.
config_path
)
pdf_server
=
config
.
get
(
'server'
,
'pdf_server'
)
pdf_server
=
config
.
get
(
'server'
,
'pdf_server'
)
pdf_ocr
=
ocrPdfClient
(
pdf_server
)
pdf_ocr
=
ocrPdfClient
(
pdf_server
)
excel_ocr
=
ExcelParser
()
status
=
pdf_ocr
.
check_health
()
if
not
status
:
pdf_ocr
=
None
logger
.
warning
(
f
'Health check failed. The server at "
{
pdf_server
}
" is not responding as expected.'
)
logger
.
info
(
f
'文件解析服务无法正常运行'
)
return
None
else
:
excel_ocr
=
ExcelParser
()
logger
.
info
(
f
'输入目录或文件的路径为:
{
input_path
}
'
)
logger
.
info
(
f
'输入目录或文件的路径为:
{
input_path
}
'
)
logger
.
info
(
f
'输出目录为:
{
output_dir
}
'
)
logger
.
info
(
f
'输出目录为:
{
output_dir
}
'
)
process_input
(
input_path
,
pdf_ocr
,
excel_ocr
,
output_dir
)
process_input
(
input_path
,
pdf_ocr
,
excel_ocr
,
output_dir
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
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