from flask import Blueprint, render_template, abort # from jinja2 import TemplateNotFound router = Blueprint('image', __name__) @router.route('//test', methods=['POST']) def test(name): # dataset = @router.route('//face', methods=['POST']) def upload(name): file = request.files['query_img'] fn = file.filename if fn.endswith('blob'): fn = 'filename.jpg' basename, ext = os.path.splitext(fn) print("got {}, type {}".format(basename, ext)) if ext.lower() not in valid_exts: return jsonify({ 'error': 'not an image' }) uploaded_fn = datetime.now().isoformat() + "_" + basename uploaded_fn = sanitize_re.sub('', uploaded_fn) uploaded_img_path = "static/uploaded/" + uploaded_fn + ext uploaded_img_path = uploaded_img_path.lower() print('query: {}'.format(uploaded_img_path)) img = Image.open(file.stream).convert('RGB') # img.save(uploaded_img_path) # vec = db.load_feature_vector_from_file(uploaded_img_path) vec = fe.extract(img) # print(vec.shape) results = db.search(vec, limit=limit) query = { 'timing': time.time() - start, } print(results) return jsonify({ 'results': results, })