Commit cbe2abc6 authored by zhougaofeng's avatar zhougaofeng
Browse files

Update pdf_server.py

parent 56f741c2
......@@ -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()
......
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