Download handler.py from FloodWatch/anomalydetection: direct link, hf CLI and curl.
- Browser
- Download file 619 Bytes
-
https://huggingface.co/FloodWatch/anomalydetection/resolve/main/handler.py
- Command line
-
hf download hf://FloodWatch/anomalydetection/handler.py
-
curl -L -o handler.py https://huggingface.co/FloodWatch/anomalydetection/resolve/main/handler.py
619 Bytes
| import torch | |
| import 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} |