From 29145a689ef9d1392301eeefb50d3f58aa48cf8c Mon Sep 17 00:00:00 2001 From: Ruan HongChao Date: Mon, 7 Oct 2024 03:11:00 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=A0=A1=E9=AA=8C=E9=97=AE=E9=A2=98=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E9=95=9C=E5=83=8F=E5=90=AF=E5=8A=A8=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- app/main.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6a42a95..ae6f22c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,4 @@ RUN pip install --no-cache-dir -r requirements.txt EXPOSE 8000 # 运行应用 -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] +CMD ["python", "app/main.py"] diff --git a/app/main.py b/app/main.py index 532a4bc..c3e31d8 100644 --- a/app/main.py +++ b/app/main.py @@ -15,7 +15,11 @@ async def decode_image(image: Union[UploadFile, StarletteUploadFile, str, None]) raise HTTPException(status_code=400, detail="No image provided") if isinstance(image, (UploadFile, StarletteUploadFile)): - return await image.read() + content = await image.read() + if not content: + raise HTTPException(status_code=400, detail="Uploaded file is empty") + return content + elif isinstance(image, str): try: # 检查是否是 base64 编码的图片 @@ -38,7 +42,7 @@ async def ocr_endpoint( png_fix: bool = Form(False) ): try: - if file.size == 0 and image is None: + if file is None and image is None: return APIResponse(code=400, message="Either file or image must be provided") image_bytes = await decode_image(file or image) @@ -57,7 +61,7 @@ async def slide_match_endpoint( simple_target: bool = Form(False) ): try: - if (background is None and target is None) or (background_file.size == 0 and target_file.size == 0): + if (target_file is None and target is None) or (background_file is None and background is None): return APIResponse(code=400, message="Both target and background must be provided") target_bytes = await decode_image(target_file or target) @@ -74,7 +78,7 @@ async def detection_endpoint( image: Optional[str] = Form(None) ): try: - if file.size == 0 and image is None: + if file is None and image is None: return APIResponse(code=400, message="Either file or image must be provided") image_bytes = await decode_image(file or image)