mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import os
|
|
import urllib.parse
|
|
from predictions import prediction
|
|
|
|
RUNTIME_ENVIRONMENT = os.environ.get("RUNTIME_ENVIRONMENT", "dev")
|
|
|
|
|
|
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
|
|
|
|
payload = event["body"]
|
|
data_path = payload["file_location"]
|
|
property_id = payload["property_id"]
|
|
portfolio_id = payload["portfolio_id"]
|
|
created_at = payload["created_at"]
|
|
|
|
try:
|
|
# We could fix the model path but for the moment, we just take the best model path based on the registry
|
|
outputs = prediction(model_path=None, data_path=data_path)
|
|
# Store into s3, with key of {portfolio_id}-{property_id}
|
|
|
|
storage_filepath = f"s3://retrofit-sap-predictions-{RUNTIME_ENVIRONMENT}/{portfolio_id}/{property_id}/" \
|
|
f"{created_at}.csv"
|
|
outputs.to_csv(storage_filepath)
|
|
return storage_filepath
|
|
|
|
except (Exception, KeyError, ValueError) as e:
|
|
print("Prediction failed")
|
|
print(e)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
handler()
|