Skip to content

Commit

Permalink
feat(rapidocr_api): try import RapidOCR (#282)
Browse files Browse the repository at this point in the history
try import RapidOCR from rapidocr_onnxruntime or rapidocr_paddle or rapidocr_openvino
  • Loading branch information
hbh112233abc authored Dec 4, 2024
1 parent a58d5d2 commit 43efc5d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/rapidocr_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
import sys
from pathlib import Path
from typing import Dict
import importlib.util

import numpy as np
import uvicorn
from fastapi import FastAPI, Form, UploadFile
from PIL import Image
from rapidocr_onnxruntime import RapidOCR

if importlib.util.find_spec("rapidocr_runtime"):
from rapidocr_onnxruntime import RapidOCR
elif importlib.util.find_spec("rapidocr_paddle"):
from rapidocr_paddle import RapidOCR
elif importlib.util.find_spec("rapidocr_openvino"):
from rapidocr_openvino import RapidOCR
else:
raise ImportError(
"Pleas install one of [rapidocr-runtime,rapidocr-paddle,rapidocr-openvino]"
)

sys.path.append(str(Path(__file__).resolve().parent.parent))

Expand Down

0 comments on commit 43efc5d

Please sign in to comment.