12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- # 试题切割服务:TopicSegment predict
- from gevent import monkey; monkey.patch_all() # linux
- from gevent.pywsgi import WSGIServer
- from flask import Flask, jsonify
- # from flask import request
- from flask import request
- import json
- import time
- from flask_cors import *
- from PointerNet import config
- from PointerNet.predictor import Predictor
- logger = config.myLog(__name__, log_cate="TopicSegment_predict_log").getlog()
- app = Flask(__name__)
- app.debug = True
- CORS(app, supports_credentials=True)
- nerArgs = config.NerArgs()
- pred = Predictor(nerArgs)
- @app.route('/math_phy_TopicSegment_predict', methods=["POST", "GET"])
- def topicType_predict():
- """
- 物理题型预测
- post以json格式上传时,content可以传str或list
- :return:
- """
- content = request.json.get("content", "") # 试题/试卷
- text_type = request.json.get("text_type", "stem_block")
- subject = request.json.get("subject", "数学")
- paper_id = request.json.get("paper_id", "temp_{}".format(int(time.time())))
- logger.info(json.dumps({"log_level": "info",
- "request_ip": request.remote_addr,
- "content": content,
- "paper_id": paper_id,
- "subject": subject,
- "text_type": text_type}, ensure_ascii=False))
- if not content:
- return ""
- elif type(content) != str:
- return "只接受str传参类型"
-
- pred_res = pred.predict(content, con_type=text_type, paper_id=paper_id, subject=subject)
-
- logger.info(json.dumps({"log_level": "info",
- "content": content,
- "pred_res": pred_res}, ensure_ascii=False))
- return jsonify({"res":pred_res})
- if __name__ == "__main__":
- server = WSGIServer((config.server_ip, config.server_port), app)
- server.serve_forever()
-
-
|