rasa-api实现训练模型保存训练日志
作者:互联网
from flask import Flask, request
import json
import subprocess
app = Flask(__name__)
@app.route('/train_and_save/', methods=['POST'])
def save_train_log():
if request.method == 'POST':
get_cmd = request.get_data().decode('utf-8')
instruction_text = json.loads(get_cmd)
instruction = instruction_text['instruction']
print('instructions:', instruction)
if instruction == 'train_and_save':
cmd = 'rasa train 2>&1 | tee rasa_train_model.log'
subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
output_text = 'The model training is completed, and the training log is saved successfully'
return json.dumps(output_text, ensure_ascii=False)
else:
output_text = 'Please enter train_and_save to start training the model and save the training log....'
return json.dumps(output_text, ensure_ascii=False)
else:
return json.dumps('请使用POST请求访问连接', ensure_ascii=False)
if __name__ == '__main__':
app.run('0.0.0.0', port=2263, debug=True)
标签:__,训练,rasa,text,train,instruction,json,api,save 来源: https://blog.csdn.net/LuoFan_A/article/details/121769526