Commit 0d0edaf5 authored by zhougaofeng's avatar zhougaofeng
Browse files

Update ocr_client.py

parent 24763973
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() # 记录开始时间
# 压缩图片 # 压缩图片
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment