Commit 46988c37 authored by zhougaofeng's avatar zhougaofeng
Browse files

Update pdf_server.py

parent aabeebfd
...@@ -20,7 +20,7 @@ import configparser ...@@ -20,7 +20,7 @@ import configparser
app = FastAPI() app = FastAPI()
method = 'auto' method = 'auto'
logger.add("../../parse.log", rotation="10 MB", level="INFO", logger.add("parse.log", rotation="10 MB", level="INFO",
format="{time} {level} {message}", encoding='utf-8', enqueue=True) format="{time} {level} {message}", encoding='utf-8', enqueue=True)
class ocrRequest(BaseModel): class ocrRequest(BaseModel):
...@@ -28,6 +28,11 @@ class ocrRequest(BaseModel): ...@@ -28,6 +28,11 @@ class ocrRequest(BaseModel):
output_dir: str output_dir: str
config_path: str config_path: str
class ocrResponse(BaseModel):
status_code: int
output_path: str
def parse_args(): def parse_args():
parser = ArgumentParser() parser = ArgumentParser()
parser.add_argument( parser.add_argument(
...@@ -87,7 +92,7 @@ async def pdf_ocr(request: ocrRequest): ...@@ -87,7 +92,7 @@ async def pdf_ocr(request: ocrRequest):
try: try:
file_name = str(Path(doc_path).stem) file_name = str(Path(doc_path).stem)
pdf_data = read_fn(doc_path) pdf_data = read_fn(doc_path)
do_parse( output_path = do_parse(
config_path, config_path,
output_dir, output_dir,
file_name, file_name,
...@@ -99,13 +104,18 @@ async def pdf_ocr(request: ocrRequest): ...@@ -99,13 +104,18 @@ async def pdf_ocr(request: ocrRequest):
end_page_id=end_page_id, end_page_id=end_page_id,
) )
logger.info(f'文件解析成功:{output_path}')
return output_path
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
logger.info(f'config_path:{request.config_path}') logger.info(f'config_path:{request.config_path}')
try: try:
parse_doc(path,request.config_path) output_path = parse_doc(path,request.config_path)
return {"status_code": "200", "message": "PDF parsed successfully"} logger.info(f'文件解析成功:{output_path}')
return {"status_code": 200, "output_path": output_path}
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
# Return error response with error details # Return error response with error details
...@@ -123,3 +133,4 @@ if __name__ == '__main__': ...@@ -123,3 +133,4 @@ if __name__ == '__main__':
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