Created
December 21, 2020 06:35
-
-
Save deepak-karkala/d51c41cad25ea0363708378c5595b791 to your computer and use it in GitHub Desktop.
Revisions
-
deepak-karkala created this gist
Dec 21, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ # Serve Model predictions using REST API # Predict and return JSON data @app.route("/predict", methods=["POST"]) def predict(): # initialize the data dictionary that will be returned from the view data = {"success": False} # ensure an image was properly uploaded to our endpoint if flask.request.method == "POST": if flask.request.files.get("image"): data["predictions"] = [] # Read input as image image = flask.request.files["image"].read() image = Image.open(io.BytesIO(image)) # Run inference and get prediction seg_mask, seg_product_category = get_model_output_json(image) # Add prediction results to JSON data r = {"label": seg_product_category} data["predictions"].append(r) # indicate that the request was a success data["success"] = True # return the data dictionary as a JSON response return flask.jsonify(data)