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

Update pdf_server.py

parent aabeebfd
......@@ -20,7 +20,7 @@ import configparser
app = FastAPI()
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)
class ocrRequest(BaseModel):
......@@ -28,6 +28,11 @@ class ocrRequest(BaseModel):
output_dir: str
config_path: str
class ocrResponse(BaseModel):
status_code: int
output_path: str
def parse_args():
parser = ArgumentParser()
parser.add_argument(
......@@ -87,7 +92,7 @@ async def pdf_ocr(request: ocrRequest):
try:
file_name = str(Path(doc_path).stem)
pdf_data = read_fn(doc_path)
do_parse(
output_path = do_parse(
config_path,
output_dir,
file_name,
......@@ -99,13 +104,18 @@ async def pdf_ocr(request: ocrRequest):
end_page_id=end_page_id,
)
logger.info(f'文件解析成功:{output_path}')
return output_path
except Exception as e:
logger.exception(e)
logger.info(f'config_path:{request.config_path}')
try:
parse_doc(path,request.config_path)
return {"status_code": "200", "message": "PDF parsed successfully"}
output_path = parse_doc(path,request.config_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
......@@ -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