封装api:
#导入flask相关包
from flask import Flask,abort,jsonify,make_response,request
#导入要封装的函数
from extract_important_informations import extract_informations
app = Flask(__name__)
@app.route('/predict/' ,methods=['post'])
def predict_keywords_hotwords_summary():
? ? if not request.json or not 'input_json' in request.json:
? ? ? ? abort(400)
? ? input_json = request.json['input_json']
? ? output_json = extract_informations().extract_keywords_hotwords_summary(input_json)
? ? return jsonify(input_json)
if __name__ == '__main__':
? app.run(host='127.0.0.1', port='9017', debug=True)
客户端调用:
from requests import post
if __name__ == '__main__':
? ? doc = ' '.join([i.strip() for i in open('data/test.txt', 'r').readlines()])
? ? params = {"full_doc": doc}
? ? ret = post('http://127.0.0.1:9017/predict/',json={'input_json':params})
? ? result = eval(ret.text)
? ? print(result)