Last active
December 6, 2021 23:39
-
-
Save hayatoy/0acb13b0213ca7c2440e20f03d4553ee to your computer and use it in GitHub Desktop.
Vertex AI Prediction example
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 characters
@app.route('/predict',methods=['GET','POST']) | |
def predict(): | |
# Decode image | |
request_json = request.get_json(silent=True, force=True) | |
data = request_json['instances'] | |
decoded = base64.urlsafe_b64decode(data[0]["b64"]) | |
img_in_bytes = io.BytesIO(decoded) | |
img = Image.open(img_in_bytes).convert('RGB') | |
# Generate Anime image | |
img_anime = face2paint(model=model2, img=img) | |
# Encode image for response | |
img_bytes = io.BytesIO() | |
img_anime.save(img_bytes, format='JPEG') | |
enc_out = base64.urlsafe_b64encode(img_bytes.getvalue()) | |
return json.dumps({"predictions": [{"b64": enc_out}]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment