Exemplo n.º 1
0
def show_model_response():
    try:
        token = get_token_from_request()
        current_quotas = users.get_user_quotas(token=token)
        input_image=request.files.get("image")
        image = parse_info_as_image(input_image)
        gender= request.values.get("gender").encode('utf-8')
    except errors.UserAuthenticationError as bad_token_error:
        return errors.unauthorized_response(message=str(bad_token_error))
    except errors.UserNotFoundError:
        return errors.not_found_response("No user associated with your token.")
    except errors.ImageNotFoundError:
        return errors.bad_request_response("Please include an image in your request body.")

    if current_quotas["quota_left"] <= 0:
        return errors.unauthorized_response(message="No more request quota.", dict={"quotas": current_quotas})
    try:
        new_quotas = users.decrement_user_quota(token=token)
        predictions = classifier.predict(img=image, gender=gender)
    except Exception:
        print('error from classification')
        traceback.print_exc()
        return

    response_body = {
        "status": "ok",
        "quotas": new_quotas,
        "results": predictions
    }
    return jsonify(response_body)
Exemplo n.º 2
0
def show_user_quota():
    try:
        token = get_token_from_request()
        current_quotas = users.get_user_quotas(token=token)
    except errors.UserAuthenticationError as bad_token_error:
        return errors.unauthorized_response(message=str(bad_token_error))
    except errors.UserNotFoundError:
        return errors.not_found_response("No user associated with your token.")

    if current_quotas["quota_left"] <= 0:
        return errors.unauthorized_response(message="No more request quota.", dict={"quotas": current_quotas})

    response_body = {
        "status": "ok",
        "quotas": current_quotas
    }
    return jsonify(response_body)
Exemplo n.º 3
0
def show_echo():
    try:
        token = get_token_from_request()
        users.get_user_by_token(token=token)
        image = parse_info_as_image(request.data)
    except errors.UserAuthenticationError as bad_token_error:
        return errors.unauthorized_response(message=str(bad_token_error))
    except errors.UserNotFoundError:
        return errors.not_found_response("No user associated with your token.")
    except errors.ImageNotFoundError:
        return errors.bad_request_response("Please include an image in your request body.")

    return image
Exemplo n.º 4
0
def send_error_unauthorized(error):
    return errors.unauthorized_response()
Exemplo n.º 5
0
def send_error_not_admin():
    return errors.unauthorized_response(message="Admin access required.")