项目架构调整,模型全部采用接口调用

This commit is contained in:
2024-09-25 14:46:37 +08:00
parent 7647df7d74
commit b8c1202957
25 changed files with 467 additions and 222 deletions

View File

@@ -1,9 +1,93 @@
import json
import logging
import requests
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):
"""
请求图片OCR识别接口
:param img_path: 待识别图片路径
:return: 识别结果
"""
url = 'http://ocr_api:5001/ocr'
response = requests.post(url, {'img_path': img_path})
if response.status_code == 200:
return response.json()
else:
return None
@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):
"""
请求基本医保结算单信息抽取接口
:param img_path: 待抽取图片路径
:param layout: 图片ocr信息
:return: 抽取结果
"""
url = 'http://settlement_api:5002/nlp/settlement'
response = requests.post(url, {'img_path': img_path, 'layout': json.dumps(layout)})
if response.status_code == 200:
return response.json()
else:
return None
@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):
"""
请求出院记录信息抽取接口
:param img_path: 待抽取图片路径
:param layout: 图片ocr信息
:return: 抽取结果
"""
url = 'http://discharge_api:5003/nlp/discharge'
response = requests.post(url, {'img_path': img_path, 'layout': json.dumps(layout)})
if response.status_code == 200:
return response.json()
else:
return None
@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):
"""
请求费用清单信息抽取接口
:param img_path: 待抽取图片路径
:param layout: 图片ocr信息
:return: 抽取结果
"""
url = 'http://cost_api:5004/nlp/cost'
response = requests.post(url, {'img_path': img_path, 'layout': json.dumps(layout)})
if response.status_code == 200:
return response.json()
else:
return None
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
after=lambda x: logging.warning('获取图片方向失败!'))
def request_image_orientation(img_path):
"""
请求图片方向分类接口
:param img_path: 待分类图片路径
:return: 最有可能的两个图片方向
"""
url = 'http://clas_api:5005/clas/orientation'
response = requests.post(url, {'img_path': img_path})
if response.status_code == 200:
return response.json()
else:
return ['0', '90']
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
after=lambda x: logging.warning('获取文档区域失败!'))
def request_book_areas(img_path):
@@ -12,7 +96,7 @@ def request_book_areas(img_path):
:param img_path: 待识别图片路径
:return: 文档图片路径列表
"""
url = 'http://det_api:5000/det/books'
url = 'http://det_api:5006/det/books'
response = requests.post(url, {'img_path': img_path})
if response.status_code == 200:
return response.json()
@@ -28,25 +112,9 @@ def request_dewarped_image(img_path):
:param img_path: 待矫正图片路径
:return: 矫正后的图片路径
"""
url = 'http://det_api:5001/dewarp'
url = 'http://127.0.0.1:5007/dewarp'
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 request_image_orientation(img_path):
"""
请求图片方向分类接口
:param img_path: 待分类图片路径
:return: 最有可能的两个图片方向
"""
url = 'http://det_api:5002/clas/orientation'
response = requests.post(url, {'img_path': img_path})
if response.status_code == 200:
return response.json()
else:
return ['0', '90']