from flask import request, Flask, jsonify,logging import time import logging app = Flask(__name__) from RotateMatch.rotateInterface import * @app.route("/tailor", methods=["POST"]) def tailor(): start_time = time.time() """receive image and predict """ base64pic = request.json.get('base64pic') height = request.json.get("height") # print(request.data) data = {'success':False} if base64pic is None: data["errorinfo"] = "captcha tailor needs two params:base64pic and height,please check" return jsonify(data),404 try: img_b64 = base64pic.split(',')[-1] width = getMoveLength(img_b64,height) data["destination"] = width data["success"] = True data["cost"] = time.time()-start_time logging.info("tailor takes %.2f"%(time.time()-start_time)) return jsonify(data),200 except Exception as e: data["errorinfo"] = "exception with %s"%(str(e)) return jsonify(data),500 @app.route("/rotate", methods=["POST"]) def rotate(): start_time = time.time() """receive image and predict """ base64pic = request.json.get('base64pic') radius = request.json.get('radius') # print(request.data) data = {'success':False} if base64pic is None : data["errorinfo"] = "captcha tailor needs one params:base64pic,please check" return jsonify(data),404 try: img_b64 = base64pic.split(',')[-1] angle = getRotateAngle(img_b64,radius) data["angle"] = angle data["success"] = True data["cost"] = time.time()-start_time logging.info("tailor takes %.2f"%(time.time()-start_time)) return jsonify(data),200 except Exception as e: data["errorinfo"] = "exception with %s"%(str(e)) traceback.print_exc() return jsonify(data),500 if __name__ == '__main__': handler = logging.FileHandler('flask.log', encoding='UTF-8') app.logger.setLevel("INFO") logging_format = logging.Formatter( '%(asctime)s - %(levelname)s - %(filename)s -%(lineno)s - %(message)s' ) handler.setFormatter(logging_format) app.logger.addHandler(handler) app.run("0.0.0.0", port=17053, debug=False) # 2.177 本地IP