Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

pyheartex

Python interface for running ML backend server and using it for active learning & prelabeling & prediction within Heartex platform

Installation

First make sure you have Redis server running (otherwise you can use only prediction, not active learning).

Install Heartex SDK:

git clone https://github.com/heartexlabs/pyheartex.git
cd pyheartex/
pip install -r requirements.txt
pip install -e .

Last thing you should do is to start RQ workers in the background:

rq worker default

Using Docker

Here is an example how to start serving image classifier:

cd examples/docker
docker-compose up

All you need to replace with your own model is to change loading, inference and training scripts from this file.

Quick start

Quick start guide provides the usage of the following popular machine learning frameworks within Heartex platform:

Scikit-learn

Let's serve scikit-learn model for text classification.

You can simply launch

python examples/quickstart.py

This script looks like

from htx.adapters.sklearn import serve

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline


if __name__ == "__main__":

    # Creating sklearn-compatible model
    my_model = make_pipeline(TfidfVectorizer(), LogisticRegression())

    # Start serving this model
    serve(my_model)

It starts serving at http://localhost:16118 listening for Heartex event. To connect your model, go to Heartex -> Settings -> Machine learning page and choose "Add custom model".

Or you can use Heartex API to activate your model:

curl -X POST -H 'Content-Type: application/json' \
-H 'Authorization: Token <PUT-YOUR-TOKEN-HERE>' \
-d '[{"url": "$HOST:$PORT", "name": "my_model", "title": "My model", "description": "My new model deployed on Heartex"}]' \
http://go.heartex.net/api/projects/{project-id}/backends/

where $HOST:$PORT is your server URL that should be accessible from the outside.

FastAI

You can integrate FastAI models similarly to scikit-learn. Check this example to learn how to plug in updateable image classifier.

Advanced usage

When you want to go beyond using sklearn compatible API, you can build your own model, by making manually input/output interface conversion. You have to subclass Heartex models as follows:

from htx.base_model import BaseModel

# This class exposes methods needed to handle model in the runtime (loading into memory, running predictions)
class MyModel(BaseModel):

    def get_input(self, task):
        """Extract input from serialized task"""
        pass

    def get_output(self, task):
        """Extract output from serialized task"""
        pass

    def load(self, train_output):
        """Loads model into memory. `train_output` dict is actually the output the `train` method (see below)"""
        pass

    def predict(self, tasks):
        """Get list of tasks, already processed by `get_input` method, and returns completions in Heartex format"""
        pass

# This method handles model retraining
def train(input_tasks, output_model_dir, **kwargs):
    """
    :param input_tasks: list of tasks already processed by `get_input`
    :param output_model_dir: output directory where you can optionally store model resources
    :param kwargs: any additional kwargs taken from `train_kwargs`
    :return: `train_output` dict for consequent model loading
    """
    pass

Release files for pyheartex 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyheartex 0.0.8
File Size Uploaded
pyheartex-0.0.8.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyheartex 0.0.8
File Interpreter ABI Platform
pyheartex-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 30.1 kB

Release files / pyheartex-0.0.8.tar.gz

Download URL pyheartex-0.0.8.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c1663561eff033711443bd2faf78b2bd4dbe9981aa1dee60d31e00a0b9619164
BLAKE2b-256 checksum
How to use checksums
dcb53f3b10acf77429f21fa8e575bef2b5ad5e39961554b12d3292608af2c332
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

Release files / pyheartex-0.0.8-py3-none-any.whl

Download URL pyheartex-0.0.8-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a7f680e620ff47f64e1eeb9a605726292587fc7a9d0063f366e94d9705b93a8
BLAKE2b-256 checksum
How to use checksums
654625dccd54890725ca411921f4ab146a4e230004840b06d9049abde2c72d70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page