- 安装 paddle
![]()
- 在明道的 Docker 中安装
![]()
- 安装 pip 的 setuptools
![]()
- 安装 paddleocr
![]()
- 安装 fitz\PyMuPDF,正常通过 pip 安装即可
- 在代码块中引用即可。
import requests
import json
def getfilename(i):
str1=i[:i.find('?')]
str1=str1[str1.rfind('/')+1:]
str1=str1[str1.rfind('.')+1:]
print('str1',str1)
return(str1)
ocr = PaddleOCR(lang='ch',use_gpu=False,show_warning=False,show_log=False)
file_addr=input["att1"]
file_dir='/tmp/'
list1=file_addr[2:len(file_addr)-2].split('","')
retlist = []
for i in list1:
file_http_path = i.encode('gbk').decode('unicode_escape')
tmpfilename=getfilename(i)
if tmpfilename=='pdf':
file_name = file_dir+'test.pdf'
else:
file_name = file_dir+'test.'+tmpfilename
#print('file_http_path:',file_http_path)
response = requests.get(file_http_path)
with open(file_name, "wb") as file:
file.write(response.content)
result = ocr.ocr(file_name, cls=False)[0]
json1 = json.dumps(result, ensure_ascii=False)
retlist.append(json1)
#print('retlist',retlist)
output = {'att1': retlist}