mirror of
https://github.com/sml2h3/ocr_api_server.git
synced 2025-05-04 05:43:04 +08:00
Merge 0bcd3bb2a1
into a40a6b96d7
This commit is contained in:
commit
ddc84e6134
@ -14,4 +14,4 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# 运行应用
|
# 运行应用
|
||||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
CMD ["python", "app/main.py"]
|
@ -9,11 +9,9 @@ app = FastAPI()
|
|||||||
|
|
||||||
from starlette.datastructures import UploadFile as StarletteUploadFile
|
from starlette.datastructures import UploadFile as StarletteUploadFile
|
||||||
|
|
||||||
|
|
||||||
async def decode_image(image: Union[UploadFile, StarletteUploadFile, str, None]) -> bytes:
|
async def decode_image(image: Union[UploadFile, StarletteUploadFile, str, None]) -> bytes:
|
||||||
if image is None:
|
if image is None:
|
||||||
raise HTTPException(status_code=400, detail="No image provided")
|
raise HTTPException(status_code=400, detail="No image provided")
|
||||||
|
|
||||||
if isinstance(image, (UploadFile, StarletteUploadFile)):
|
if isinstance(image, (UploadFile, StarletteUploadFile)):
|
||||||
return await image.read()
|
return await image.read()
|
||||||
elif isinstance(image, str):
|
elif isinstance(image, str):
|
||||||
@ -40,7 +38,6 @@ async def ocr_endpoint(
|
|||||||
try:
|
try:
|
||||||
if file is None and image is None:
|
if file is None and image is None:
|
||||||
return APIResponse(code=400, message="Either file or image must be provided")
|
return APIResponse(code=400, message="Either file or image must be provided")
|
||||||
|
|
||||||
image_bytes = await decode_image(file or image)
|
image_bytes = await decode_image(file or image)
|
||||||
result = ocr_service.ocr_classification(image_bytes, probability, charsets, png_fix)
|
result = ocr_service.ocr_classification(image_bytes, probability, charsets, png_fix)
|
||||||
return APIResponse(code=200, message="Success", data=result)
|
return APIResponse(code=200, message="Success", data=result)
|
||||||
@ -57,7 +54,7 @@ async def slide_match_endpoint(
|
|||||||
simple_target: bool = Form(False)
|
simple_target: bool = Form(False)
|
||||||
):
|
):
|
||||||
try:
|
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")
|
return APIResponse(code=400, message="Both target and background must be provided")
|
||||||
|
|
||||||
target_bytes = await decode_image(target_file or target)
|
target_bytes = await decode_image(target_file or target)
|
||||||
@ -85,4 +82,4 @@ async def detection_endpoint(
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
Loading…
Reference in New Issue
Block a user