HycJack commited on
Commit
0553381
·
1 Parent(s): 1c657d7

modified return value

Browse files
Files changed (1) hide show
  1. main.py +8 -8
main.py CHANGED
@@ -49,7 +49,7 @@ async def ocr(file: UploadFile = File(...)):
49
  return out_df.to_dict(orient='records')
50
 
51
  TMP_DIR = Path(__file__).parent / "tmp_uploads"
52
- # TMP_DIR.mkdir(parents=True, exist_ok=True)
53
  @app.post("/ocr_table")
54
  async def ocr_table(file: UploadFile = File(...)):
55
  # ------------------- ① 参数校验 -------------------
@@ -89,15 +89,15 @@ async def ocr_table(file: UploadFile = File(...)):
89
  table_engine = RapidTable(input_args)
90
  table_results = table_engine(tmp_path)
91
 
92
- #print(table_results.pred_htmls)
93
- return table_results
94
  finally:
95
  # ------------------- ⑥ 清理临时文件 -------------------
96
  # 为了防止磁盘被塞满,尽量在请求结束后删除文件
97
- # try:
98
- # if tmp_path.exists():
99
- # tmp_path.unlink()
100
  print(f"已删除临时文件 {tmp_path}")
101
- # except Exception as exc:
102
- # print(f"删除临时文件 {tmp_path} 失败: {exc}")
103
  return None
 
49
  return out_df.to_dict(orient='records')
50
 
51
  TMP_DIR = Path(__file__).parent / "tmp_uploads"
52
+ TMP_DIR.mkdir(parents=True, exist_ok=True)
53
  @app.post("/ocr_table")
54
  async def ocr_table(file: UploadFile = File(...)):
55
  # ------------------- ① 参数校验 -------------------
 
89
  table_engine = RapidTable(input_args)
90
  table_results = table_engine(tmp_path)
91
 
92
+ print(table_results.pred_htmls)
93
+ return {"pred_htmls": table_results.pred_htmls, "cell_bboxes": table_results.cell_bboxes}
94
  finally:
95
  # ------------------- ⑥ 清理临时文件 -------------------
96
  # 为了防止磁盘被塞满,尽量在请求结束后删除文件
97
+ try:
98
+ if tmp_path.exists():
99
+ tmp_path.unlink()
100
  print(f"已删除临时文件 {tmp_path}")
101
+ except Exception as exc:
102
+ print(f"删除临时文件 {tmp_path} 失败: {exc}")
103
  return None