mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
27 lines
775 B
Python
27 lines
775 B
Python
import os
|
|
import urllib.parse
|
|
from predictions import prediction
|
|
|
|
|
|
def handler(event, context):
|
|
"""
|
|
Take in event and trigger the prediction pipeline
|
|
"""
|
|
|
|
# Assuming a file in a bucket landing for now?
|
|
# Assuming we have a model to use
|
|
|
|
bucket = event["Records"][0]["s3"]["bucket"]["name"]
|
|
key = urllib.parse.unquote_plus(
|
|
event["Records"][0]["s3"]["bucket"]["key"], encoding="utf-8"
|
|
)
|
|
|
|
prediction_file = bucket + "/" + key
|
|
|
|
# TODO: put a model into s3, both locally and in aws
|
|
model_path = os.environ.get("MODEL_PATH", "http://minio:9000/data/model_directory/")
|
|
|
|
try:
|
|
prediction(model_path=model_path, data_path=prediction_file)
|
|
except (Exception, KeyError, ValueError):
|
|
print("Prediction failed")
|