Download src/predict.py from ByteJoseph/SolveQ: direct link, hf CLI and curl.
- Browser
- Download file 425 Bytes
-
https://huggingface.co/ByteJoseph/SolveQ/resolve/main/src/predict.py
- Command line
-
hf download hf://ByteJoseph/SolveQ/src/predict.py
-
curl -L -o predict.py https://huggingface.co/ByteJoseph/SolveQ/resolve/main/src/predict.py
425 Bytes
| import torch | |
| from model import LinearModel | |
| def predict(x_value): | |
| model = LinearModel() | |
| model.load_state_dict(torch.load("models/model.pt")) | |
| model.eval() | |
| x = torch.tensor([[x_value]], dtype=torch.float32) | |
| y = model(x) | |
| print(f"Input: {x_value} | Prediction: {y.item()}") | |
| def actual(x): | |
| return 2 * x + 3 | |
| if __name__ == "__main__": | |
| predict(4.0) | |
| print(f"Actual: {actual(4.0)}") |