【发布时间】:2021-07-20 11:50:00
【问题描述】:
我正在尝试对解析器模型进行预测,使用预训练的 spacy 模型,我使用烧瓶作为 api 和 html 作为前端。但它会抛出错误请求。
@app.route('/index')
def index():
return flask.render_template('index.html')
@app.route('/index', methods=['GET', 'POST'])
def predict():
if request.method == 'POST':
image_file = request.files["file_image"]
nlp_model = spacy.load("nlp_model")
img2 = cv2.imread(image_file)
img_rgb = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB)
pytesseract.pytesseract.tesseract_cmd = r'C:\Tesseract-
OCR\tesseract.exe'
out_below_1 = pytesseract.image_to_string(img_rgb,
config=pytesseract.pytesseract.tesseract_cmd)
tx = " ".join(out_below_1.split('\n'))
doc = nlp_model(tx)
s = []
for ent in doc.ents:
s.append(ent)
return s
if __name__ == '__main__':
app.run()
【问题讨论】:
-
当您尝试访问
/index时是否会抛出该错误?有两个原因(实际上我不知道其中一个,但是......)首先你有两条相同的路线,所以烧瓶不知道要使用哪一条,其次装饰器之间应该没有空间和函数定义