diff --git a/rapidocr_web/ocrweb.py b/rapidocr_web/ocrweb.py index afc669d..5024642 100644 --- a/rapidocr_web/ocrweb.py +++ b/rapidocr_web/ocrweb.py @@ -15,13 +15,21 @@ root_dir = Path(__file__).resolve().parent app = Flask(__name__, template_folder="templates") -app.config["MAX_CONTENT_LENGTH"] = 3 * 1024 * 1024 processor = OCRWebUtils() @app.route("/") def index(): - return render_template("index.html") + # Expose max upload size (in MB) to the frontend; 0 means unlimited + mcl = app.config.get("MAX_CONTENT_LENGTH", None) + if mcl is None: + max_upload_mb = 0 + else: + try: + max_upload_mb = int(mcl // (1024 * 1024)) + except Exception: + max_upload_mb = 0 + return render_template("index.html", max_upload_mb=max_upload_mb) @app.route("/ocr", methods=["POST"]) @@ -36,8 +44,16 @@ def main(): parser = argparse.ArgumentParser("rapidocr_web") parser.add_argument("-ip", "--ip", type=str, default="0.0.0.0", help="IP Address") parser.add_argument("-p", "--port", type=int, default=9003, help="IP port") + parser.add_argument("-m", "--max-content-length", type=int, default=3, + help="Max upload size in MB. Set 0 for unlimited.") args = parser.parse_args() + # Configure MAX_CONTENT_LENGTH based on CLI argument + if args.max_content_length is None or args.max_content_length == 0: + app.config["MAX_CONTENT_LENGTH"] = None # Unlimited + else: + app.config["MAX_CONTENT_LENGTH"] = int(args.max_content_length) * 1024 * 1024 + print(f"Successfully launched and visit http://{args.ip}:{args.port} to view.") server = make_server(args.ip, args.port, app) server.serve_forever() diff --git a/rapidocr_web/templates/index.html b/rapidocr_web/templates/index.html index 57d208c..2884ae3 100644 --- a/rapidocr_web/templates/index.html +++ b/rapidocr_web/templates/index.html @@ -42,7 +42,14 @@

粘贴剪贴板图像、拖拽图片或点击上传

-

支持 PNG、JPG、JPEG、BMP、WEBP 格式,文件大小不超过 3MB

+

+ 支持 PNG、JPG、JPEG、BMP、WEBP 格式, + {% if max_upload_mb and max_upload_mb > 0 %} + 文件大小不超过 {{ max_upload_mb }}MB + {% else %} + 文件大小不限制 + {% endif %} +