Skip to content

Instantly share code, notes, and snippets.

@Sembiance
Created March 19, 2021 15:07
Show Gist options
  • Save Sembiance/a279e1575f1a2877182db2c074964759 to your computer and use it in GitHub Desktop.
Save Sembiance/a279e1575f1a2877182db2c074964759 to your computer and use it in GitHub Desktop.
Example lobe.ai tensor server using Flask
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