优化flask接口
This commit is contained in:
12
det_api.py
12
det_api.py
@@ -2,15 +2,19 @@ import base64
|
|||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify, Blueprint
|
||||||
|
|
||||||
from paddle_detection import detector
|
from paddle_detection import detector
|
||||||
|
from util.common_util import process_request
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
det_bp = Blueprint('det_bp', __name__)
|
||||||
|
app.register_blueprint(det_bp, url_prefix='/det')
|
||||||
|
|
||||||
|
|
||||||
@app.route("/det/detect_books", methods=['POST'])
|
@det_bp.route("/books", methods=['POST'])
|
||||||
def detect_books():
|
@process_request
|
||||||
|
def books():
|
||||||
try:
|
try:
|
||||||
file = request.files['image']
|
file = request.files['image']
|
||||||
image_data = file.read()
|
image_data = file.read()
|
||||||
@@ -29,4 +33,4 @@ def detect_books():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run("0.0.0.0")
|
app.run("0.0.0.0", 5000)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ def get_book_areas(image):
|
|||||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||||
after=lambda x: logging.warning("获取文档区域失败!"))
|
after=lambda x: logging.warning("获取文档区域失败!"))
|
||||||
def request_book_areas(image):
|
def request_book_areas(image):
|
||||||
url = "http://det_api:5000/det/detect_books"
|
url = "http://det_api:5000/det/books"
|
||||||
_, encoded_image = cv2.imencode('.jpg', image)
|
_, encoded_image = cv2.imencode('.jpg', image)
|
||||||
byte_stream = encoded_image.tobytes()
|
byte_stream = encoded_image.tobytes()
|
||||||
files = {"image": ("image.jpg", byte_stream)}
|
files = {"image": ("image.jpg", byte_stream)}
|
||||||
|
|||||||
Reference in New Issue
Block a user