app
= Flask
(__name__
)
api
= Api
(app
, version
='1.0', title
='文字识别接口')
predict
= api
.namespace
('predict')
ALLOWED_EXTENSIONS
= set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif','doc'])
@predict
.route
('/')
class CMDcommand(Resource
):
@api
.doc
()
def post(self
):
file = request
.files
['img']
if file is None:
return "未上传文件"
base64_data
= base64
.b64encode
(file.read
())
s
= base64_data
.decode
()
url
= "http://192.168.5.218:8866/predict/ocr_system"
data
= "{\"images\": [\"%s\"]}"%s
print(data
)
headers
= {
'Content-Type': 'application/json'
}
res
= requests
.post
(url
=url
,headers
=headers
,timeout
= 20,data
=data
)
return res
.text
def allowed_file(filename
):
return '.' in filename
and \
filename
.rsplit
('.', 1)[1] in ALLOWED_EXTENSIONS
转载请注明原文地址:https://tech.qufami.com/read-26613.html