File size: 656 Bytes
e9e1e05 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | """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()
|