9 min read
Deploying and Publishing Models
Deploy a model you trained, or a Hugging Face model with a page for its task, shape the page and check it, download it or publish it to a Hugging Face Space, a model repository, GitHub Pages or your project folder, roll back, and use packages built by pipelines.
Where a deployment starts
Open Deployment and press + New, or press Deploy on a model in the Model Builder, on a Fine-Tune result or on a model a pipeline run made. The start screen has two tabs:
- Models you trained: the models kept in the open project. A model that lives in the project folder is copied into this browser when you deploy it. If the list is empty, train one in the Model Builder or save one from code with
dlway.saveModel(...). - A model file: bring in a model made somewhere else: an ONNX file, a TensorFlow.js model (its
model.jsonwith the.binfiles beside it), or the zip a Teachable Machine project downloads, with its labels. The files are read in this browser and go nowhere else. What a file says becomes the model's signature; what it cannot say (what the columns and the classes are called, how pictures were scaled, whether scores are probabilities) is asked for in Inputs and outputs. See "How the model runs" below. - A Hugging Face model: put a public model in front of people without training anything. Search the Hub for a model that transformers.js can run, paste a model's ID or address, or start from a small one for each task. Before you choose, the card says whether it runs in a browser, the precisions it comes in and their sizes, its licence and whether it is gated. See "A Hugging Face model as a page" below.
Models that are not neural networks (trees, forests, support vector machines and the rest) are listed with a note on what each can be saved as: PMML, or ONNX for the ones that can be written in it. They cannot be deployed as a page yet.
Each deployment is listed on the left with its state (draft, ready, published or failing), what it builds and when. Packages built by a pipeline are listed below it. The line at the foot says what this project's deployments hold in the browser and links to Manage storage.
The model and the page
DLWAY reads the model and the table it was trained on and writes down what goes in and what comes out: the fields with their types, ranges and categories, an image's size, the class labels, each output of a model with several. That is the model's signature, and everything below is made from it, so the page, the module and the checks cannot disagree about what the model takes.
Under Inputs and outputs you can correct it. (A Hugging Face model has Model here instead.) A fact that could not be found (the labels of a model saved from code, a field's range) is listed as a finding with one control to answer it. A blank required field is an error on the page, never a 0.
Visitors enter their own values
A model trained on prepared data reads numbers a visitor does not have: a standardised income, a column of 0 and 1 for each plan. When the project knows how the data was prepared, Deployment can ask for the values as they are in your data (the income in money, the plan from a list, a date from a date control) and do the preparation itself, with the numbers it learned.
It finds the preparation in two places: a pipeline's Fit preprocessing step (it is found by following what the model was made from: the training run, the prepared data, the preparation fitted on the data before it), or the preparation a model was saved with. If it finds one, the Inputs and outputs section has What visitors enter, with the values in your data as the choice when they can be used, and the numbers the model reads as the other. The page, the Python apps and the CSV scorer all follow it.
- What goes with the model: filling missing values (mean, median, mode, a constant), standardising, min-max scaling, clipping and capping outliers, one-hot, ordinal and frequency encoding, grouping rare categories, case and spaces, the parts of a date, TF-IDF over a fitted vocabulary, and renaming. Steps that choose rows (filters, sorting, resampling) and training-only steps are left out, since there is one row to answer.
- A blank is allowed where the preparation fills it, and the model is given what it was trained with: the same answer as typing the average.
- A scaled target is given back in the units of your data.
- A step that cannot go (casting a type, binning, target encoding, a formula column, PCA, and others) is named, and visitors then enter the numbers the model reads.
- Checked: the Checks section runs the preparation beside the real fitted pipeline on made-up rows (each category, both ends of every range, a blank where one is allowed) and the numbers must match. Dates are read year first (2021-03-05) or month first (3/5/2021).
- Scored on rows the model did not learn from: when the model was evaluated (an Evaluate step, or a run in Model Builder) on the test rows of data that has a
splitcolumn, the Checks section gives the page up to a thousand of those rows, as your data has them, and compares the score with the one the Evaluate step recorded. Two points apart is fine (more when only a sample of a large set is scored); further apart is a warning, because it usually means the page prepares its input differently from how the model was trained. It never stops a build. It is skipped, with the reason, when nothing recorded an evaluation, the data has no split, or the preparation changed the target for good (a log, an encoding). A page that takes the prepared numbers is scored on the prepared test rows. If the page runs from weights stored at 16 or 8 bits, the score is the smaller model's.
A text model whose text was tokenised in the preparation reads typed text the same way: the scheme and the vocabulary come from the preparation, not from DLWAY's own hashing.
Make the page yours
App edits the page beside a live preview. The preview is the bundle itself, running in a sandboxed frame that cannot reach the Studio, so what you see is what ships.
- Page: the title, a tagline, the accent colour, the shape of the corners, light, dark or the visitor's own setting.
- Blocks: which parts appear and in what order: a header and a description, the form and the answer (always shown), examples, a batch tab that scores a CSV and offers the results as a download, the model's details and a disclaimer.
- Inputs: a number box or a slider, a drop-down, a switch, a text box, or a picture that can be dropped, chosen or taken with the camera. The Studio takes the photo and hands it to the page, because the sandbox has no camera of its own.
- Examples: type values in the preview and press Add the current values to make an example a visitor can click.
- Words: every visible string can be changed.
- Works offline and can be installed: the page keeps itself in the visitor's browser after the first visit.
Targets
Each target is made from the same bundle.
| Target | What it is |
| --- | --- |
| Web app | A folder: index.html, app.json, the model as standard TensorFlow.js files, the runtime, sample inputs, a README. Host it anywhere. |
| Single HTML file | The same page as one file that opens from disk or an email. Best for small models. |
| Widget | <dlway-model src="…">, a web component that keeps its styles to itself, and an iframe that sizes itself. An example page is included. |
| JavaScript module | predict() with types written from the model, and snippets for plain JavaScript, React, Vue and Svelte. |
| Model files | The TensorFlow.js files and a model card, and the model as an ONNX file where it can be written as one. tf.loadLayersModel("model/model.json") loads the first with no DLWAY code. |
Python targets
The same bundle as an app that runs in Python. The model runs on ONNX Runtime wherever it can be written as an ONNX file and that file has been held to TensorFlow.js's numbers (see "How the model runs"): a small install, with no TensorFlow. Otherwise it runs on Keras (tf-keras with TensorFlow), rebuilt from the layers and weights TensorFlow.js saved. Either way it gives the same numbers: each family of layers the Model Builder draws was compared with TensorFlow.js, on both.
| Target | What it is |
| --- | --- |
| Streamlit app | streamlit_app.py: a form with a control for each field as on the web page, examples, the answer with bars, a tab that scores a CSV, and a Dockerfile. |
| Gradio app | app.py: an interface with the same inputs and examples, and a CSV tab. |
| REST API | FastAPI: POST /predict, POST /predict/batch, GET /signature, GET /healthz, request types written from what the model takes, an optional X-API-Key (set DLWAY_API_KEY), and a Dockerfile. The documentation is at /docs. |
| Notebook | model.ipynb: loads the model, predicts, self-tests. It unzips the download itself on Colab or Kaggle. |
Each folder holds the model, dlway.json, tests.json, the page's description (app.json, which the apps read, so editing it changes the app), dlway_runtime.py, selftest.py, a pinned requirements.txt and a README. When an app starts it runs the bundle's test cases and shows a failure in place of the form, and the model's own files are checked against their hashes, so a damaged download is said, not answered with. A model that reads through a Hugging Face encoder, or takes audio, cannot be made into a Python app yet, and the card says why. An app on Keras needs TensorFlow, a large install (a few hundred megabytes), so a free host can take a minute to start one; an app on ONNX Runtime does not.
Keras 3 cannot read the layers TensorFlow.js writes, which is why an app on Keras pins tf-keras.
How the model runs
The Targets section starts with a card, How the model runs:
- In the browser the page runs the model on TensorFlow.js, or, once the ONNX file is offered, on ONNX Runtime Web. ONNX Runtime Web is a 50 KB script and a 13 MB engine from jsDelivr (pinned, the script under an integrity hash, kept by the browser); TensorFlow.js is 1.5 MB. The answers are the same.
- In Python the apps run on ONNX Runtime wherever they can, and on Keras otherwise or when you ask for it.
- Weights can be stored as 32-bit numbers (as trained), 16-bit floats (half the size) or 8-bit integers (a quarter), in the standard TensorFlow.js way, which TensorFlow.js and the Python runtime both read. The card shows the size each saves and how far the answers move before you choose, measured on inputs made from the shape of what the model reads (not on your data's held-out rows, which a deployment does not keep: score a smaller model on your own data before relying on it). The ONNX file is written from the same numbers as 32-bit values, so it stays the same size.
An ONNX file is offered only after a check. DLWAY writes the model as ONNX (every layer the Model Builder draws is covered: dense, merge, normalisation, convolution and pooling in one to three dimensions, separable and transposed, embeddings, simple, LSTM and GRU layers, bidirectional wrappers), TensorFlow.js answers some inputs made from the shape of the model's input, and ONNX Runtime Web, running in a sandboxed frame like the preview, answers them again from the ONNX file, together with the bundle's own sample inputs. Every number has to agree. A layer the exporter does not know is named, and the model carries on as TensorFlow.js and Keras. Nothing under a page you published changes until you publish again.
Bringing in a model file
A model file on the start screen takes an ONNX file or a TensorFlow.js model. The file is read here, and what it says becomes the signature: the shape of the input says whether it is a row of numbers, a picture (channels first, as PyTorch writes it, or last) or raw numbers; the operator that ends the model says whether its scores are probabilities. A file with several inputs, a size that is not fixed, a batch fixed above 1, weights kept in other files, or an output that is a list of maps cannot be made into a page, and the card says which and how to export it again (for PyTorch, external_data=False; for scikit-learn's skl2onnx, options={id(model): {'zipmap': False}}). A scikit-learn classifier's probabilities are read as probabilities, and its label is shown beside them. For an ONNX file there is no TensorFlow.js model to say what the sample inputs should answer, so ONNX Runtime does, when the file is brought in: they hold every copy of the page and every Python app to those answers, and they do not show that the model is right. A Teachable Machine download is opened, its labels become the classes, and its pixel values are set to the range -1 to 1.
Checks
Checks runs when the page is built and says what passed:
- the inputs and outputs are known;
- the bundle loads in the runtime that ships with it;
- every output has the right form;
- sample inputs, made from the signature and never from your training rows, give the answers the Studio gave;
- the page runs in the preview.
It measures the download size, the load time and the time for one prediction on each back end the browser offers, and it warns about what looks like personal data in the examples, the page's words, the model card or the sample inputs; a model card with no licence or no limits; a design edited after training; and a large download. A failing check blocks publishing and says what to do.
Download
Download gives each ticked target as a zip (the single file as the file itself). Each is a release too, kept in this browser.
Publish
Publishing opens when the checks pass and the build matches the page as it is now.
Hugging Face
Sign in with Hugging Face opens a popup, you agree on huggingface.co, and the Studio is signed in for a few hours; the section says when it ends and offers Sign in again. DLWAY asks only to make repositories in your account and reach the ones it made. Or Use a token instead: paste a token with write access, which is checked and the permission it lacks is named. The token stays in this browser and is sent only to huggingface.co. One connection serves the whole Studio, including the Data Hub's Hugging Face step.
- Static Space: free for everyone. DLWAY makes a public Space in your account, fills it, and shows its address. Publishing again updates it so that it holds exactly the new release. A Space made with a token can only be updated with that token.
- Model repository: the model's files and card as a repository, for people who want the model rather than the page. Hugging Face keeps every earlier version in its history.
GitHub Pages
A repository in your account with Pages switched on, made with the token in Settings → Source Control. A fine-grained token needs Contents (write), Pages (write) and Administration (write); a classic one needs the repo scope. The repository is public, which a free account needs for Pages.
A Python Space on Hugging Face
The Gradio app runs as a Gradio Space; the Streamlit app and the API run as Docker Spaces. Hugging Face sells the compute these Spaces run on: creating a Gradio or Docker Space needs a paid plan (PRO, or Team or Enterprise for an organisation), which the card says before you start. A static Space is free. The Space takes a few minutes to build the first time, since it installs TensorFlow.
GitHub, then Streamlit Community Cloud
The Streamlit app is pushed to a public repository in your account, with the token in Settings. Streamlit has no way to make an app from outside its own page, so you finish there: open share.streamlit.io, choose *Create app*, then *Paste GitHub URL* and paste the address the card gives you (the repository's streamlit_app.py). Nothing here is hosted by DLWAY.
Project folder
The files are written to deploy/<name>/ in the open project folder, replacing that folder as a whole, so your own source control and CI pick them up.
Releases, roll back, newer models
Each publish is a release. The live release and the one before it are kept for each place, with the latest build, and older ones are let go when a new one is made. Roll back to this sends a kept release again. When the model is trained again from the same design, or fine-tuned, a banner offers the newer model with its accuracy beside the current one, and Update to it points the deployment at it; what is live stays as it is until you publish. The list marks such a deployment Out of date.
Share it shows the live address, a QR code, the iframe and web-component code with the address in it, and a picture for link previews (the social card) to download and put next to the page.
Taking it down
Unpublish deletes the Space or repository, or switches Pages off (the GitHub repository stays). If Hugging Face does not let a sign-in delete, the screen links to the Space's settings page and does not ask for a wider permission.
DLWAY hosts nothing. The page lives in your account until you take it down, and anyone who can open it can also download the model.
A Hugging Face model as a page
A model from the Hub is deployed as a page with the form its task needs, and is published, downloaded and rolled back like any other deployment. The model runs in a web worker in the visitor's browser, on the graphics chip (WebGPU) where that suits and on the processor (WebAssembly) otherwise. What a visitor enters stays on their device; the model's files come from Hugging Face the first time, and the browser keeps them.
| Task | The page asks for | And shows |
| --- | --- | --- |
| Text classification, fill in the blank, audio classification | a text, or a sound | the likeliest answers with bars |
| Zero-shot text and picture classification | a text or a picture, and the labels to sort it into | the labels, scored |
| Entity recognition | a text | the names marked in the text, one colour to a kind |
| Question answering | a question and a passage | the answer, marked in the passage |
| Summarisation, translation, captioning | a text or a picture (and, for a model that translates between many languages, the two languages) | the text |
| Chat and text generation | a message, in a conversation that goes on | the answer, written as it comes, with a Stop button |
| Speech to text | a sound file, or the microphone (the visitor presses Record) | what was said, with when if asked |
| Object detection | a picture | a box drawn on it for each thing found |
The sections of such a deployment:
- Model: what the Hub says (runs in a browser, licence, gated, the commit the page is pinned to), how it runs (the processor, the graphics chip or automatic, and the precision on each, with its size), the task's settings (a visitor can change the ones marked), and where the files come from. A first visit costs what the card says; a page asks before it downloads more than 40 MB.
- Copy the model into the page: the model's files are published with the page, so it does not depend on the Hub. The page is then as large as the model. A gated or private model cannot be copied, since its owner has not said everyone may have it, and GitHub does not take a file over 100 MB.
- App and Publish: as for a trained model: the title, look, words, examples and model card, then a Hugging Face static Space, GitHub Pages, the project folder, or a download. There is no model repository to make (the model is on the Hub already), and the web component is for trained models; an iframe embeds the page, and asks for the microphone or camera only when the page uses it.
- Checks: whether transformers.js can run it, that the precisions chosen are in the repository, that a visitor is allowed to download it, the licence, what a first visit downloads, and that the bundle is whole. Run the model in the preview loads it and asks it a question of its own, on this device.
The page is pinned to the commit of the model it was set up with, so it does not change when the model's owner changes the model; Use the latest moves it. If the owner deletes the model, a page that loads from the Hub stops working, which is what copying the files in prevents.
The Python apps of a Hugging Face model
Targets can also hand the model on as a Streamlit app, a Gradio app or a REST API that runs it with transformers and PyTorch on a machine you run it on. They cover every task the page serves, and ask for what the task needs: a text, a picture or a recording, and besides it the labels to sort into (zero-shot text and picture classification), the question and the passage it is about, the languages of a translation by a model that knows many, or how sure a box must be (object detection, which draws the boxes on the picture). The settings you chose for the page (the labels it starts with, how many answers are listed, how long an answer may be, the instructions to a chat model) are the app's starting values. Audio needs ffmpeg. Summarising, translating, answering questions and captioning use transformers 4.57.6, the last version that still has those pipelines (transformers 5 removed them), and their Gradio apps the newest Gradio that works with it; the app's requirements say so. They are downloads: DLWAY does not publish them to a Space.
Packages built by pipelines
A pipeline's Build Package step turns a trained model into a package: a browser demo page, the model file, or both, plus a manifest.json that lists every file with its hash. Before packaging it checks the model with one input in a worker (unless you turn the check off). Rebuilding the same model the same way gives the same package hash. Put a Quality Gate in front of it: with a gate's decision connected, the model is packaged only if the decision approves that very model, and a rejection ends the run as "gated". Packages are listed on the left of Deployment with a Download .zip, and can open the packaged model as a deployment.
Keeping a live page up to date
A deployment you published once can be kept current by a pipeline. The Retrain a model and keep a live page up to date template (in Templates) reads a dataset, trains a model graph, evaluates it, passes it through a Quality Gate and ends in Publish Deployment, which builds the deployment you pick with the new model and sends it to the place you chose. Schedule the pipeline and the page follows the data.
- Nothing is sent unless everything passes: the gate must approve this very model, and the build must pass the same checks as the Deployment section's. A refusal or a failure ends the run with the reason and leaves what is live exactly as it was.
- What is sent is what you set up. The page, the corrections to what the model takes and gives, how the model runs and how its weights are stored are read from the deployment, so editing them there changes what the next run publishes. Once the new model has been published, the deployment follows it, and the banner that offers a newer model clears.
- Hugging Face needs a connection that is still good. A token you pasted in Deployment → Publish does not run out, which is what a run with no one there needs. A sign-in lasts a few hours: when a run you started by hand finds it has run out, the step asks for one click to sign in again and goes on; a scheduled run cannot ask, so it stops and says to paste a token or sign in and run again. GitHub uses the token in Settings → Source Control.
- It is never retried by itself and never reused: running it again publishes again. Each publish is a release, so an earlier one can be sent again from the Deployment section.
A package is a ready-to-use file set, not a running endpoint. Packages are kept in this browser's storage; Manage storage opens the Projects Storage tab, where each is listed with its size and can be deleted. Deleting one does not affect files you downloaded or published, and the model it was built from stays.
Gate conditions
A quality gate compares an evaluation with thresholds you set, or with a baseline evaluation. For classification you can use accuracy, macro and weighted precision, recall and F1; for regression, the error and fit metrics the evaluator reports. A missing or undefined metric fails its condition, and a baseline comparison is only made when both evaluations used the same task, partition, classes and dataset version. See Pipeline step reference.
Data and privacy
Building, checking and previewing run in your browser; nothing is uploaded until you publish, and then it goes from your browser to your own Hugging Face or GitHub account. A model that reads text or pictures through a Hugging Face encoder downloads that encoder the first time. A Hugging Face model's page is the same: what a visitor enters stays on their device, and the model's files come from the Hub (or from the page, if you copied them in). Asking the Hub about a model sends only its name, and your token if you have connected one, straight to Hugging Face. See Privacy and storage.