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
46988c37
Commit
46988c37
authored
Oct 23, 2024
by
zhougaofeng
Browse files
Update pdf_server.py
parent
aabeebfd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
magic_pdf/tools/pdf_server.py
magic_pdf/tools/pdf_server.py
+15
-4
No files found.
magic_pdf/tools/pdf_server.py
View file @
46988c37
...
@@ -20,7 +20,7 @@ import configparser
...
@@ -20,7 +20,7 @@ import configparser
app
=
FastAPI
()
app
=
FastAPI
()
method
=
'auto'
method
=
'auto'
logger
.
add
(
"
../../
parse.log"
,
rotation
=
"10 MB"
,
level
=
"INFO"
,
logger
.
add
(
"parse.log"
,
rotation
=
"10 MB"
,
level
=
"INFO"
,
format
=
"{time} {level} {message}"
,
encoding
=
'utf-8'
,
enqueue
=
True
)
format
=
"{time} {level} {message}"
,
encoding
=
'utf-8'
,
enqueue
=
True
)
class
ocrRequest
(
BaseModel
):
class
ocrRequest
(
BaseModel
):
...
@@ -28,6 +28,11 @@ class ocrRequest(BaseModel):
...
@@ -28,6 +28,11 @@ class ocrRequest(BaseModel):
output_dir
:
str
output_dir
:
str
config_path
:
str
config_path
:
str
class
ocrResponse
(
BaseModel
):
status_code
:
int
output_path
:
str
def
parse_args
():
def
parse_args
():
parser
=
ArgumentParser
()
parser
=
ArgumentParser
()
parser
.
add_argument
(
parser
.
add_argument
(
...
@@ -87,7 +92,7 @@ async def pdf_ocr(request: ocrRequest):
...
@@ -87,7 +92,7 @@ async def pdf_ocr(request: ocrRequest):
try
:
try
:
file_name
=
str
(
Path
(
doc_path
).
stem
)
file_name
=
str
(
Path
(
doc_path
).
stem
)
pdf_data
=
read_fn
(
doc_path
)
pdf_data
=
read_fn
(
doc_path
)
do_parse
(
output_path
=
do_parse
(
config_path
,
config_path
,
output_dir
,
output_dir
,
file_name
,
file_name
,
...
@@ -99,13 +104,18 @@ async def pdf_ocr(request: ocrRequest):
...
@@ -99,13 +104,18 @@ async def pdf_ocr(request: ocrRequest):
end_page_id
=
end_page_id
,
end_page_id
=
end_page_id
,
)
)
logger
.
info
(
f
'文件解析成功:
{
output_path
}
'
)
return
output_path
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
exception
(
e
)
logger
.
exception
(
e
)
logger
.
info
(
f
'config_path:
{
request
.
config_path
}
'
)
logger
.
info
(
f
'config_path:
{
request
.
config_path
}
'
)
try
:
try
:
parse_doc
(
path
,
request
.
config_path
)
output_path
=
parse_doc
(
path
,
request
.
config_path
)
return
{
"status_code"
:
"200"
,
"message"
:
"PDF parsed successfully"
}
logger
.
info
(
f
'文件解析成功:
{
output_path
}
'
)
return
{
"status_code"
:
200
,
"output_path"
:
output_path
}
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
exception
(
e
)
logger
.
exception
(
e
)
# Return error response with error details
# Return error response with error details
...
@@ -123,3 +133,4 @@ if __name__ == '__main__':
...
@@ -123,3 +133,4 @@ 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