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
cbe2abc6
Commit
cbe2abc6
authored
Oct 24, 2024
by
zhougaofeng
Browse files
Update pdf_server.py
parent
56f741c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
magic_pdf/tools/pdf_server.py
magic_pdf/tools/pdf_server.py
+11
-11
No files found.
magic_pdf/tools/pdf_server.py
View file @
cbe2abc6
...
...
@@ -22,11 +22,10 @@ method = 'auto'
logger
.
add
(
"parse.log"
,
rotation
=
"10 MB"
,
level
=
"INFO"
,
format
=
"{time} {level} {message}"
,
encoding
=
'utf-8'
,
enqueue
=
True
)
config_path
=
None
class
ocrRequest
(
BaseModel
):
path
:
str
output_dir
:
str
config_path
:
str
class
ocrResponse
(
BaseModel
):
status_code
:
int
...
...
@@ -68,6 +67,8 @@ def ocr_pdf_serve(args: str):
config
.
read
(
args
.
config_path
)
host
=
config
.
get
(
'server'
,
'pdf_host'
)
port
=
int
(
config
.
get
(
'server'
,
'pdf_port'
))
global
config_path
config_path
=
args
.
config_path
uvicorn
.
run
(
app
,
host
=
host
,
port
=
port
)
@
app
.
post
(
"/pdf_ocr"
)
...
...
@@ -82,7 +83,7 @@ async def pdf_ocr(request: ocrRequest):
debug_able
=
False
start_page_id
=
0
end_page_id
=
None
logger
.
info
(
f
"method:
{
method
}
, path:
{
path
}
, output_dir:
{
output_dir
}
, config_path:
{
request
.
config_path
}
"
)
logger
.
info
(
f
"method:
{
method
}
, path:
{
path
}
, output_dir:
{
output_dir
}
, config_path:
{
config_path
}
"
)
def
read_fn
(
path
):
disk_rw
=
DiskReaderWriter
(
os
.
path
.
dirname
(
path
))
...
...
@@ -110,16 +111,15 @@ async def pdf_ocr(request: ocrRequest):
except
Exception
as
e
:
logger
.
exception
(
e
)
logger
.
info
(
f
'config_path:
{
request
.
config_path
}
'
)
try
:
output_path
=
parse_doc
(
path
,
request
.
config_path
)
logger
.
info
(
f
'文件解析成功:
{
output_path
}
'
)
logger
.
info
(
f
'config_path:
{
config_path
}
'
)
output_path
=
parse_doc
(
path
,
config_path
)
if
output_path
:
logger
.
info
(
f
'文件解析成功:
{
output_path
}
'
)
return
{
"status_code"
:
200
,
"output_path"
:
output_path
}
except
Exception
as
e
:
logger
.
exception
(
e
)
# Return error response with error details
raise
HTTPException
(
status_code
=
500
,
detail
=
str
(
e
))
else
:
logger
.
error
(
f
'文件解析失败,文件为:
{
path
}
'
)
raise
HTTPException
(
status_code
=
500
)
def
main
():
args
=
parse_args
()
...
...
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