Skip to content

Instantly share code, notes, and snippets.

@yorrr78
Created January 7, 2024 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorrr78/2d5a123f612f54440ba4d873b91ea070 to your computer and use it in GitHub Desktop.
Save yorrr78/2d5a123f612f54440ba4d873b91ea070 to your computer and use it in GitHub Desktop.
MediumBlogging-Vertex AI custom container deployment-app.py
import logging
from flask import Flask, request, jsonify
import os
import opslib
# Set path for the model
cwd = os.path.abspath(os.path.dirname(__file__))
given_path = "model"
model_path = os.path.abspath(os.path.join(cwd, given_path))
logging.basicConfig(level=logging.DEBUG)
app = Flask(__name__)
@app.route("/", methods=['GET'])
def home():
html = "<h3>Model Serving</h3>"
return html.format(format)
@app.route("/predict", methods=['POST'])
def predict():
json_payload = request.json
instances = json_payload.get('instances', [])
app.logger.info(f"json_payload: {instances}")
predictions = opslib.predict(instances)
app.logger.info(f"predictions: {predictions}")
### Vertex AI reponse format ###
return jsonify({"predictions": predictions})
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment