Upload handler.py
Browse files12345678910111213141516171819202122232425import torchimport pickle
class TimeSeriesAnomalyDetectionHandler: def __init__(self): # Load the model from the .pt file with open("lstm_ed.pt", "rb") as f: self.model = torch.load(f)
def __call__(self, event, context): # Parse the input data from the event data = event["data"] inputs = data
# Run the model inference with torch.no_grad(): outputs = self.model.predict(**inputs)
# Process the model outputs predictions = outputs
# Return the predictions return {"predictions": predictions}handler.pyAdded+25