123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #!/usr/bin/env/python
- # -*- coding:utf-8 -*-
- import pickle
- from gevent import monkey
- monkey.patch_all() # 打上猴子补丁
- from flask import Flask, render_template, send_from_directory
- from flask import request, redirect, Response
- from flask_cors import *
- from multiprocessing import Process, Queue
- from gevent import pywsgi
- import configs
- from structure.danti_structure import single_parse
- from structure.structure_main import WordParseStructure
- import os, datetime, hashlib
- import time, json, random
- import pprint
- from utils.ruku_opera import Ruku
- from pprint import pprint
- logger = configs.myLog(__name__, log_cate="reparse_ruku_log").getlog()
- app = Flask(__name__)
- app.debug = True
- CORS(app, supports_credentials=True)
- @app.route('/danti_structure', methods=["GET", "POST"])
- def danti_structure():
- """
- 单题再解析、结构化
- :return:
- """
- word_id = request.json.get("paper_id", 0)
- one_item = request.json.get("single_item_data", "")
- item_type = request.json.get("item_type", "")
- logger.info("【单题解析】==request.POST.dict==>word_id:{}, item_type:{}".format(word_id, item_type))
- # logger.info("【单题解析】==request.POST.single_item_data==>\n{}\n".format(one_item))
- print(word_id, item_type)
- res = {"errcode": 0, "errmsgs":"", "data": {}}
- if item_type:
- one_res = single_parse(one_item, item_type, word_id)
- if type(one_res) == str:
- res["errcode"] = 1
- res["errmsgs"] = one_res
- else:
- res["data"] = one_res
- else:
- res["errcode"] = 1
- res["errmsgs"] = "没有选定题型"
- return json.dumps(res, ensure_ascii=False)
- @app.route('/ser_static/<path:file_path>', methods=["GET"])
- def ser_static(file_path): # endpoint的位置是函数接口名,不能用static,与flask内部变量重名
- """
- :param file_path: 图片的本地绝对路径
- :return:
- """
- return send_from_directory(configs.IMG_FOLDER, file_path)
- def start_new_server(port):
- server = pywsgi.WSGIServer(('',port),app)
- server.start_accepting()
- if __name__ == "__main__":
- # app.run(host=configs.server_ip, port=configs.server_port, processes=True, debug=True) # threaded=True
- # app.run(processes=4) # 多进程或多线程只能选择一个,不能同时开启
- # 5fc64a0a4994183dda7e74b9
- from multiprocessing import cpu_count, Process
- # app.debug = True
- # server = pywsgi.WSGIServer((configs.server_ip, configs.server_port), app)
- # server.serve_forever()
- for i in range(cpu_count()):
- p = Process(target=start_new_server)
- p.start()
|