| """Gradio demo: linear slope y = wx + b via ONNX Runtime.""" | |
| import gradio as gr | |
| import numpy as np | |
| import onnxruntime as ort | |
| session = ort.InferenceSession("slope.onnx") | |
| def predict(x_val: float) -> float: | |
| x = np.array([[x_val]], dtype=np.float32) | |
| outputs = session.run(None, {"x": x}) | |
| return float(outputs[0][0, 0]) | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Number(label="x", value=2.0), | |
| outputs=gr.Number(label="y = wx + b"), | |
| title="ONNX Slope Demo", | |
| description=( | |
| "PyTorch-trained linear model exported to ONNX. " | |
| "Trained on y ≈ 2x + 1; enter x to get the predicted y." | |
| ), | |
| ) | |
| demo.launch() | |