Skip to main content
The other essential file in a Truss is model/model.py. In this file, you write a Model class: an interface between the ML model that you’re packaging and the model server that you’re running it on. The code to load and invoke a model in a Jupyter notebook or Python script maps directly to the code used in model/model.py.
We’ll go line-by-line through the code. Open model/model.py in your text editor.

Import transformers

Import transformers.pipeline at the top of model/model.py:
model/model.py

Load the model

The Model.load() function runs exactly once when the model server is spun up or patched and loads the model onto the model server. Update load() to bring in the text-classification model from transformers.pipeline:
model/model.py
You should see this change patched onto the model server in your truss watch terminal tab.