Skip to content

Give your model an interface.

Describe the inputs a model needs and the reports it returns. MLForm validates the inputs, sends the values your backend expects, and renders the results, with or without its built-in UI.
A weather-station form rendered by MLForm: temperature, humidity and wind speed in three columns, a sensor location select, and two reports below, a next-hour temperature estimate and a classifier with Stable 92% and Changing 8%.A weather-station form rendered by MLForm: temperature, humidity and wind speed in three columns, a sensor location select, and two reports below, a next-hour temperature estimate and a classifier with Stable 92% and Changing 8%.
One schema, rendered by mountForm with the eshkra theme. Sections, column groups and both reports come from configuration.
main.ts
import { mountForm } from "mlform";
mountForm(document.querySelector<HTMLElement>("#forecast")!, {
schema: {
fields: [
{ id: "temperature", kind: "number", label: "Temperature", mappedTo: "temperature" },
{ id: "humidity", kind: "number", label: "Humidity", mappedTo: "humidity" },
],
reports: [
{ id: "forecast", kind: "regressor", label: "Next-hour estimate", mappedTo: "forecast" },
],
},
transport: {
async submit(request) {
const response = await fetch("/api/forecast", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(request.modelValues),
signal: request.signal,
});
if (!response.ok) throw new Error(`Forecast failed: ${response.status}`);
// Expected: { reports: [{ backend: "default", mappedTo: "forecast",
// status: "ready", payload: { value: 22.7 } }] }
return response.json();
},
},
});

MLForm is open source under the MIT license and part of eshkra. Install it from npm, try every example in the playground, or read the source on GitHub.