Created
January 7, 2024 23:58
-
-
Save yorrr78/2d5a123f612f54440ba4d873b91ea070 to your computer and use it in GitHub Desktop.
MediumBlogging-Vertex AI custom container deployment-app.py
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 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