import tempfile import os import paddlehub as hub from PIL import Image pp_ocrv3 = hub.Module(name="ch_pp-ocrv3") def inference_img(img): with tempfile.TemporaryDirectory() as tempdir_name: pp_ocrv3.recognize_text(images=[img], use_gpu=False, output_dir=tempdir_name, visualization=True) result_names = os.listdir(tempdir_name) result_image = Image.open(os.path.join(tempdir_name, result_names[0])) return result_image def inference_json(img): results = pp_ocrv3.recognize_text(images=[img], use_gpu=False, visualization=False) return results