How to code the usage logic

This file defines how your model is *used during inference or deployment.
This is the code that powers the “Deploy” stage of BojAI—whether via CLI or GUI.

To define your own usage logic, extend the User base class and implement the use_model method.


Base Class: User

from user import User

class ImplementYourUser(User):
    def use_model(self, input):
        ...

Do not change the class name or base class. BojAI uses it to hook your logic into the pipeline.


Method: use_model(input)

You must implement this method to define how your model processes an input and returns a result.

Must return a value!

The output can be:

  • A string
  • A number
  • A list, dictionary, or anything serializable

Examples

Text model (e.g., sentiment analysis or translation)

def use_model(self, input):
    inputs = self.tokenizer(input, return_tensors="pt", padding=True)
    outputs = self.model(**inputs)
    return outputs

Image model (e.g., classification or detection)

from PIL import Image

def use_model(self, input):
    image = Image.open(input)
    processed = self.processor(image).unsqueeze(0)
    output = self.model(processed)
    return output

External logic (e.g., calling a CUDA binary or subprocess)

import subprocess

def use_model(self, input):
    result = subprocess.run(["./my_cuda_binary", input], capture_output=True, text=True)
    return result.stdout.strip()

When Is This Used?

This class powers the deployment stage of your pipeline:

In CLI:
bojai start --pipeline name-from-build --directory where/the/editing files/are --stage train

In UI: bojai start --pipeline name-from-build --directory where/the/editing files/are --stage train --ui

It is what end-users interact with when they submit input for inference.