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
0d0edaf5
Commit
0d0edaf5
authored
Oct 24, 2024
by
zhougaofeng
Browse files
Update ocr_client.py
parent
24763973
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
3 deletions
+22
-3
magic_pdf/dict2md/ocr_client.py
magic_pdf/dict2md/ocr_client.py
+22
-3
No files found.
magic_pdf/dict2md/ocr_client.py
View file @
0d0edaf5
import
configparser
import
os
import
os
import
json
import
json
import
requests
import
requests
...
@@ -10,8 +11,8 @@ from PIL import Image
...
@@ -10,8 +11,8 @@ from PIL import Image
def
parse_args
():
def
parse_args
():
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
parser
.
add_argument
(
'--
url
'
,
'--
config_path
'
,
default
=
'
http://127.0.0.1:6020
'
,
default
=
'
/home/practice/magic_pdf-main/magic_pdf/config.ini
'
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
'--image_path'
,
'--image_path'
,
...
@@ -126,6 +127,21 @@ class PredictClient:
...
@@ -126,6 +127,21 @@ class PredictClient:
def
__init__
(
self
,
api_url
):
def
__init__
(
self
,
api_url
):
self
.
api_url
=
api_url
self
.
api_url
=
api_url
def
check_health
(
self
):
health_check_url
=
f
'
{
self
.
api_url
}
/health'
try
:
response
=
requests
.
get
(
health_check_url
)
if
response
.
status_code
==
200
:
logger
.
info
(
"Server is healthy and ready to process requests."
)
return
True
else
:
logger
.
error
(
f
'Server health check failed with status code:
{
response
.
status_code
}
'
)
return
False
except
requests
.
exceptions
.
RequestException
as
e
:
logger
.
error
(
f
'Health check request failed:
{
e
}
'
)
return
False
def
predict
(
self
,
image_path
:
str
,
text
:
str
):
def
predict
(
self
,
image_path
:
str
,
text
:
str
):
payload
=
{
payload
=
{
"image_path"
:
image_path
,
"image_path"
:
image_path
,
...
@@ -143,8 +159,11 @@ class PredictClient:
...
@@ -143,8 +159,11 @@ class PredictClient:
def
main
():
def
main
():
args
=
parse_args
()
args
=
parse_args
()
client
=
PredictClient
(
args
.
url
)
config
=
configparser
.
ConfigParser
()
config
.
read
(
args
.
config_path
)
ocr_server
=
config
.
get
(
'server'
,
'ocr_server'
)
client
=
PredictClient
(
ocr_server
)
try
:
try
:
start_time
=
time
.
time
()
# 记录开始时间
start_time
=
time
.
time
()
# 记录开始时间
# 压缩图片
# 压缩图片
...
...
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