生成结果

最后将程序封装部署成web app的形式,程序网址为:

http://127.0.0.1:5002/?inputStr=””

在引号里面输入要识别的语句

<span class='yzk_title_799'>【Python】深度学习笔记03</span>-Maxchen个人博客
通过浏览器使用程序
def config_model(char_to_id, tag_to_id):
    config = OrderedDict()
    config["model_type"] = FLAGS.model_type
    config["num_chars"] = len(char_to_id)
    config["char_dim"] = FLAGS.char_dim
    config["num_tags"] = len(tag_to_id)
    config["seg_dim"] = FLAGS.seg_dim
    config["lstm_dim"] = FLAGS.lstm_dim
    config["batch_size"] = FLAGS.batch_size

    config["emb_file"] = FLAGS.emb_file
    config["clip"] = FLAGS.clip
    config["dropout_keep"] = 1.0 - FLAGS.dropout
    config["optimizer"] = FLAGS.optimizer
    config["lr"] = FLAGS.lr
    config["tag_schema"] = FLAGS.tag_schema
    config["pre_emb"] = FLAGS.pre_emb
    config["zeros"] = FLAGS.zeros
    config["lower"] = FLAGS.lower
    return config
with open(FLAGS.map_file, "rb") as f:
    if pyversion=='three':    
        char_to_id, id_to_char, tag_to_id, id_to_tag = pickle.load(f)
    else:
        char_to_id, id_to_char, tag_to_id, id_to_tag = pickle.load(f,protocol=2)
        # make path for store log and model if not exist
make_path(FLAGS)
if os.path.isfile(FLAGS.config_file):
    config = load_config(FLAGS.config_file)
else:
    config = config_model(char_to_id, tag_to_id)
    save_config(config, FLAGS.config_file)
make_path(FLAGS)
app = Flask(__name__)
log_path = os.path.join("log", FLAGS.log_file)
logger = get_logger(log_path)
tf_config = tf.ConfigProto()
sess=tf.Session(config=tf_config)
sess.run(tf.global_variables_initializer()) 
model = create_model(sess, Model, FLAGS.ckpt_path, load_word2vec, config, id_to_char, logger)
@app.route('/', methods=['POST','GET'])
def get_text_input():
    #return "connect successfully"
    #logging.info("connect successfully")
    #tf_config = tf.ConfigProto()
    #tf_config.gpu_options.allow_growth = True   
    #http://127.0.0.1:5002/?inputStr="最开心"
    text=request.args.get('inputStr')
    #return text
    #return text
    #text="乙肝倒计时"
    if text:     
        aa=model.evaluate_line(sess, input_from_line(text, char_to_id), id_to_tag)
        return jsonify(aa)
if __name__ == "__main__":   
    app.config['JSON_AS_ASCII'] = False
    app.run(host='127.0.0.1',port=5002)
   # r=requests.post('http://192.168.5.40:5001/Neo4jAPI/P_relation', data={'patient_id':'10502005'})
记录你的想法-丰富你的知识
  • <span class='yzk_title_765'>【Python】深度学习笔记02</span>
    【Python】深度学习笔记02
  • <span class='yzk_title_712'>【Python】深度学习笔记01</span>
    【Python】深度学习笔记01
  • <span class='yzk_title_528'>【Python】将.mat格式的数据保存在数据库中</span>
    【Python】将.mat格式的数据保存在数据库中
  • <span class='yzk_title_1668'>【Java】Spring Cloud学习笔记05</span>
    【Java】Spring Cloud学习笔记05
  • <span class='yzk_title_1601'>【Java】Spring Cloud学习笔记04</span>
    【Java】Spring Cloud学习笔记04
  • <span class='yzk_title_1492'>【Java】Spring Cloud学习笔记03</span>
    【Java】Spring Cloud学习笔记03
发表评论

坐等沙发