1414from fastapi import FastAPI , Form , UploadFile
1515from PIL import Image
1616from rapidocr import RapidOCR
17+ from starlette .formparsers import MultiPartParser
1718
19+ MultiPartParser .max_part_size = 10 * 1024 * 1024 # 10MB
20+ MultiPartParser .max_file_size = 20 * 1024 * 1024 # 20MB
1821sys .path .append (str (Path (__file__ ).resolve ().parent .parent ))
1922
2023
@@ -36,7 +39,7 @@ def __init__(self) -> None:
3639 )
3740
3841 def __call__ (
39- self , ori_img : Image .Image , use_det = None , use_cls = None , use_rec = None , ** kwargs
42+ self , ori_img : Image .Image , use_det = None , use_cls = None , use_rec = None , ** kwargs
4043 ) -> Dict :
4144 img = np .array (ori_img )
4245 ocr_res = self .ocr (
@@ -48,7 +51,7 @@ def __call__(
4851
4952 out_dict = {}
5053 for i , (boxes , txt , score ) in enumerate (
51- zip (ocr_res .boxes , ocr_res .txts , ocr_res .scores )
54+ zip (ocr_res .boxes , ocr_res .txts , ocr_res .scores )
5255 ):
5356 out_dict [i ] = {"rec_txt" : txt , "dt_boxes" : boxes .tolist (), "score" : score }
5457 return out_dict
@@ -65,11 +68,11 @@ def root():
6568
6669@app .post ("/ocr" )
6770def ocr (
68- image_file : Optional [UploadFile ] = None ,
69- image_data : str = Form (None ),
70- use_det : bool = Form (None ),
71- use_cls : bool = Form (None ),
72- use_rec : bool = Form (None ),
71+ image_file : Optional [UploadFile ] = None ,
72+ image_data : str = Form (None ),
73+ use_det : bool = Form (None ),
74+ use_cls : bool = Form (None ),
75+ use_rec : bool = Form (None ),
7376):
7477 if image_file :
7578 img = Image .open (image_file .file )
0 commit comments