Created
March 19, 2021 15:07
-
-
Save Sembiance/a279e1575f1a2877182db2c074964759 to your computer and use it in GitHub Desktop.
Example lobe.ai tensor server using Flask
This file contains 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 characters
import os | |
import logging | |
from PIL import Image | |
from flask import Flask, request, jsonify | |
from TensorModel import TensorModel | |
app = Flask(__name__) | |
logging.getLogger('werkzeug').setLevel(logging.WARNING) | |
modelTest = TensorModel(os.path.realpath(os.path.join(os.path.dirname(__file__), "subdir-path-to-model", "model"))) | |
@app.route("/classify/test", methods=["POST"]) | |
def classifyTest(): | |
image = Image.open(request.json["imageFilePath"]) | |
if image.mode != "RGB": | |
image = image.convert("RGB") | |
return jsonify(modelTest.predict(image)) | |
app.run(host="127.0.0.1", port=8080, threaded=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment