统一模型接口,新增文本分类接口
This commit is contained in:
@@ -36,7 +36,7 @@ def get_ocr_layout(ocr, img_path):
|
||||
return True
|
||||
|
||||
layout = []
|
||||
ocr_result = model_util.request_ocr(img_path)
|
||||
ocr_result = model_util.ocr(img_path)
|
||||
ocr_result = ocr_result[0]
|
||||
if not ocr_result:
|
||||
return layout
|
||||
|
||||
@@ -7,13 +7,13 @@ from tenacity import retry, stop_after_attempt, wait_random
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('OCR识别失败!'))
|
||||
def request_ocr(img_path):
|
||||
def ocr(img_path):
|
||||
"""
|
||||
请求图片OCR识别接口
|
||||
:param img_path: 待识别图片路径
|
||||
:return: 识别结果
|
||||
"""
|
||||
url = 'http://ocr_api:5001/ocr'
|
||||
url = 'http://ocr:5001'
|
||||
response = requests.post(url, {'img_path': img_path})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
@@ -23,14 +23,14 @@ def request_ocr(img_path):
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('抽取基本医保结算单失败!'))
|
||||
def request_discharge_info(img_path, layout):
|
||||
def ie_settlement(img_path, layout):
|
||||
"""
|
||||
请求基本医保结算单信息抽取接口
|
||||
:param img_path: 待抽取图片路径
|
||||
:param layout: 图片ocr信息
|
||||
:return: 抽取结果
|
||||
"""
|
||||
url = 'http://settlement_api:5002/nlp/settlement'
|
||||
url = 'http://ie_settlement:5002'
|
||||
response = requests.post(url, {'img_path': img_path, 'layout': json.dumps(layout)})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
@@ -40,14 +40,14 @@ def request_discharge_info(img_path, layout):
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('抽取出院记录失败!'))
|
||||
def request_discharge_info(img_path, layout):
|
||||
def ie_discharge(img_path, layout):
|
||||
"""
|
||||
请求出院记录信息抽取接口
|
||||
:param img_path: 待抽取图片路径
|
||||
:param layout: 图片ocr信息
|
||||
:return: 抽取结果
|
||||
"""
|
||||
url = 'http://discharge_api:5003/nlp/discharge'
|
||||
url = 'http://ie_discharge:5003'
|
||||
response = requests.post(url, {'img_path': img_path, 'layout': json.dumps(layout)})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
@@ -57,14 +57,14 @@ def request_discharge_info(img_path, layout):
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('抽取费用清单失败!'))
|
||||
def request_cost_info(img_path, layout):
|
||||
def ie_cost(img_path, layout):
|
||||
"""
|
||||
请求费用清单信息抽取接口
|
||||
:param img_path: 待抽取图片路径
|
||||
:param layout: 图片ocr信息
|
||||
:return: 抽取结果
|
||||
"""
|
||||
url = 'http://cost_api:5004/nlp/cost'
|
||||
url = 'http://ie_cost:5004'
|
||||
response = requests.post(url, {'img_path': img_path, 'layout': json.dumps(layout)})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
@@ -74,13 +74,13 @@ def request_cost_info(img_path, layout):
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('获取图片方向失败!'))
|
||||
def request_image_orientation(img_path):
|
||||
def clas_orientation(img_path):
|
||||
"""
|
||||
请求图片方向分类接口
|
||||
:param img_path: 待分类图片路径
|
||||
:return: 最有可能的两个图片方向
|
||||
"""
|
||||
url = 'http://clas_api:5005/clas/orientation'
|
||||
url = 'http://clas_orientation:5005'
|
||||
response = requests.post(url, {'img_path': img_path})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
@@ -90,13 +90,13 @@ def request_image_orientation(img_path):
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('获取文档区域失败!'))
|
||||
def request_book_areas(img_path):
|
||||
def det_book(img_path):
|
||||
"""
|
||||
请求文档区域识别接口
|
||||
:param img_path: 待识别图片路径
|
||||
:return: 文档图片路径列表
|
||||
"""
|
||||
url = 'http://det_api:5006/det/books'
|
||||
url = 'http://det_book:5006'
|
||||
response = requests.post(url, {'img_path': img_path})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
@@ -106,15 +106,33 @@ def request_book_areas(img_path):
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('矫正扭曲图片失败!'))
|
||||
def request_dewarped_image(img_path):
|
||||
def dewarp(img_path):
|
||||
"""
|
||||
请求矫正图片接口
|
||||
:param img_path: 待矫正图片路径
|
||||
:return: 矫正后的图片路径
|
||||
"""
|
||||
url = 'http://dewarp_api:5007/dewarp'
|
||||
url = 'http://dewarp:5007'
|
||||
response = requests.post(url, {'img_path': img_path})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
return img_path
|
||||
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('文本分类失败!'))
|
||||
def clas_text(text):
|
||||
"""
|
||||
请求文本分类接口
|
||||
:param text: 待分类文本
|
||||
:return: 分类结果
|
||||
"""
|
||||
if not text:
|
||||
return None
|
||||
url = 'http://clas_text:5008'
|
||||
response = requests.post(url, {'text': text})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user