soarli

Flask上线部署解除测试环境警告
前言最近发现Flask项目在运行时会报[WARNING: This is a development server...
扫描右侧二维码阅读全文
04
2022/04

Flask上线部署解除测试环境警告

前言

最近发现Flask项目在运行时会报[WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead警告,意思是不要在生产环境使用这种方案启动程序:

image-20220404052003732

解决

使用WSGI启动服务即可解决问题(中间可能需要pip3 install gevent

原版代码:

from paddleocr import PaddleOCR
from flask import Flask, request
import cv2
import numpy
app = Flask(__name__)

ocr = PaddleOCR(det_model_dir='./inference/small/ch_PP-OCRv2_det_infer/', rec_model_dir='./inference/small/ch_PP-OCRv2_rec_infer/',cls_model_dir='./inference/small/ch_ppocr_mobile_v2.0_cls_infer/',use_angle_cls=True,use_space_char=True, use_gpu=False)
@app.route('/xxxxxx/', methods=['get', 'POST'])
def xxxxxx():
    img_path = request.args.get("fname")
    result = ocr.ocr(img_path)
    ret = ''
    for line in result:
        ret += str(line[1][0]) + "\n"
    return str(ret)

if __name__ == '__main__':
    app.run(host='0.0.0.0')

新版代码:

from paddleocr import PaddleOCR
from flask import Flask, request
import cv2
import numpy
from gevent import pywsgi

app = Flask(__name__)

ocr = PaddleOCR(det_model_dir='./inference/small/ch_PP-OCRv2_det_infer/', rec_model_dir='./inference/small/ch_PP-OCRv2_rec_infer/',cls_model_dir='./inference/small/ch_ppocr_mobile_v2.0_cls_infer/',use_angle_cls=True,use_space_char=True, use_gpu=False)
@app.route('/xxxxxx/', methods=['get', 'POST'])
def xxxxxx():
    img_path = request.args.get("fname")
    result = ocr.ocr(img_path)
    ret = ''
    for line in result:
        ret += str(line[1][0]) + "\n"
    return str(ret)

if __name__ == '__main__':
    server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
    server.serve_forever()

解决问题!

参考资料:

https://blog.csdn.net/weixin_43642491/article/details/114916769

https://www.cnblogs.com/mlp1234/p/13743254.html

最后修改:2022 年 04 月 06 日 10 : 09 PM

发表评论