预期 python 中的缩进块与烧瓶
expected an indented block in python with flask
我在尝试从训练数据中获取响应时遇到此错误,我不确定原因:
“需要一个缩进块(第 55 行)pylint(语法错误)”
这是代码
app = Flask(__name__);
CORS(app)
@app.route("/bot", methods=["POST"])
#response
def response():
query = dict(request.form)['query']
# res = query + " "
sentence = tokenize(sentence)
X = bag_of_words(sentence, all_words)
X = X.reshape(1, X.shape[0])
X = torch.from_numpy(X).to(device)
output = model(X)
_, predicted = torch.max(output, dim=1)
tag = tags[predicted.item()]
probs = torch.softmax(output, dim=1)
prob = probs[0][predicted.item()]
if prob.item() > 0.75:
for intent in intents['intents']:
if tag == intent["tag"]:
# print(f"{bot_name}: {random.choice(intent['responses'])}")
return jsonify({"response" : random.choice(intent['responses'])}) #HERE IS THE ERROR
else:
return jsonify({"response" : "I do not understand..."})
if __name__=="__main__":
app.run(host="0.0.0.0",)
随机选择的想法是得到一个包含我之前定义的一些特征的响应....
问题似乎出在这一行,能否请您检查一下该块中的缩进是否合适
if prob.item() > 0.75:
for intent in intents['intents']:
if tag == intent["tag"]:
因此,您创建了一个 if 条件并且没有在其中编写任何语句。这就是它导致错误的原因。
行 return jsonify({"response": random.choice(intent['responses'])})
应该在 if 条件 if tag == intent["tag"]
.
内
if prob.item() > 0.75:
for intent in intents['intents']:
if tag == intent["tag"]:
# print(f"{bot_name}: {random.choice(intent['responses'])}")
return jsonify({"response": random.choice(intent['responses'])}) # HERE IS THE ERROR
else:
return jsonify({"response": "I do not understand..."})
我在尝试从训练数据中获取响应时遇到此错误,我不确定原因:
“需要一个缩进块(第 55 行)pylint(语法错误)”
这是代码
app = Flask(__name__);
CORS(app)
@app.route("/bot", methods=["POST"])
#response
def response():
query = dict(request.form)['query']
# res = query + " "
sentence = tokenize(sentence)
X = bag_of_words(sentence, all_words)
X = X.reshape(1, X.shape[0])
X = torch.from_numpy(X).to(device)
output = model(X)
_, predicted = torch.max(output, dim=1)
tag = tags[predicted.item()]
probs = torch.softmax(output, dim=1)
prob = probs[0][predicted.item()]
if prob.item() > 0.75:
for intent in intents['intents']:
if tag == intent["tag"]:
# print(f"{bot_name}: {random.choice(intent['responses'])}")
return jsonify({"response" : random.choice(intent['responses'])}) #HERE IS THE ERROR
else:
return jsonify({"response" : "I do not understand..."})
if __name__=="__main__":
app.run(host="0.0.0.0",)
随机选择的想法是得到一个包含我之前定义的一些特征的响应....
问题似乎出在这一行,能否请您检查一下该块中的缩进是否合适
if prob.item() > 0.75:
for intent in intents['intents']:
if tag == intent["tag"]:
因此,您创建了一个 if 条件并且没有在其中编写任何语句。这就是它导致错误的原因。
行 return jsonify({"response": random.choice(intent['responses'])})
应该在 if 条件 if tag == intent["tag"]
.
if prob.item() > 0.75:
for intent in intents['intents']:
if tag == intent["tag"]:
# print(f"{bot_name}: {random.choice(intent['responses'])}")
return jsonify({"response": random.choice(intent['responses'])}) # HERE IS THE ERROR
else:
return jsonify({"response": "I do not understand..."})