# Bring-Your-Own-Task (BYOT)

The Bring-Your-Own-Task (BYOT) feature allows users to create custom tasks for training, evaluating, and deploying heart-related AI models. This feature is useful for creating custom workflows for a given application with minimal coding.

For an in-depth guide check out the [BYOT Notebook Guide](https://ambiqai.github.io/heartkit/guides/byot/).

## How it Works

1. **Create a Task**: Define a new task that inherits from the [HKTask](https://ambiqai.github.io/heartkit/api/heartkit/tasks/task) base class and implements the required methods: `train`, `evaluate`, `export`, and `demo`.

    ```py title="Python example" linenums="1"
    import heartkit as hk

    class CustomTask(hk.HKTask):

        @staticmethod
        def train(params: hk.HKTrainParams) -> None:
            pass

        @staticmethod
        def evaluate(params: hk.HKTestParams) -> None:
            pass

        @staticmethod
        def export(params: hk.HKExportParams) -> None:
            pass

        @staticmethod
        def demo(params: hk.HKDemoParams) -> None:
            pass

    ```

2. **Register the Task**: Register the new task with the `TaskFactory` by calling the `register` method. This method takes the task name and the task class as arguments.

    ```py title="Python example" linenums="1"
    # Register the custom task
    hk.TaskFactory.register("custom", CustomTask)
    ```

3. **Use the Task**: The new task can now be used with the `TaskFactory` to perform various operations such as training, evaluating, and deploying models.

    ```py title="Python example" linenums="1"
    # Define task parameters
    params = hk.HKTrainParams(...)

    # Get the custom task
    task = hk.TaskFactory.get("custom")

    # Train the model
    task.train(params)

    ```
