def serve(model, port=16118, debug=True, **fit_kwargs): """ :param model: Sklearn-compatible model, that is pickleable and has interface for .fit(X, y) and .predict_proba(X) :param port: specify localhost port where the model will be served :param debug: whether to start at debug mode :return: """ init_model_server(create_model_func=partial(SklearnTextClassifier, model=model), train_script=partial(fit_sklearn_classifier, model=model), redis_queue=os.environ.get('RQ_QUEUE_NAME', 'default'), redis_host=os.environ.get('REDIS_HOST', 'localhost'), redis_port=os.environ.get('REDIS_HOST', 6379), **fit_kwargs) app.run(host='localhost', port=port, debug=debug)
def serve(learner_script, port=16118, debug=True, image_dir='~/.heartex/images', num_iter=10, **fit_kwargs): """ :param learner_script: function that takes (DataBunch, str) as input and returns Learner object :param port: specify localhost port where the model will be served :param debug: whether to start at debug mode :return: """ init_model_server(create_model_func=FastaiImageClassifier, train_script=fit_fastai_image_classifier, learner_script=learner_script, num_iter=num_iter, image_dir=image_dir, redis_queue=os.environ.get('RQ_QUEUE_NAME', 'default'), redis_host=os.environ.get('REDIS_HOST', 'localhost'), redis_port=os.environ.get('REDIS_HOST', 6379), **fit_kwargs) app.run(host='0.0.0.0', port=port, debug=debug)
import os import argparse from ner import TransformersBasedTagger, train_ner from htx import app, init_model_server init_model_server( # refer to class definition that inherits htx.BaseModel and implements load() and predict() methods create_model_func=TransformersBasedTagger, # training script that will be called within RQ train_script=train_ner, # name of the Redis queue redis_queue=os.environ.get('RQ_QUEUE_NAME', 'default'), # Redis host redis_host=os.environ.get('REDIS_HOST', 'localhost'), # here we pass the kwargs parameters to train script pretrained_model=os.environ.get('pretrained_model', 'bert-base-uncased'), cache_dir=os.environ.get('cache_dir', '~/.heartex/cache')) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--port', dest='port', default='9090') args = parser.parse_args() app.run(host='localhost', port=args.port, debug=True)
import os from htx import app, init_model_server from bert_classifier.train import train_classifier from bert_classifier.serve import LabelStudioTransformersClassifier init_model_server( create_model_func=LabelStudioTransformersClassifier, train_script=train_classifier, # name of the Redis queue redis_queue=os.environ.get('RQ_QUEUE_NAME', 'default'), # Redis host redis_host=os.environ.get('REDIS_HOST', 'localhost'), # here we pass the kwargs parameters to train script pretrained_model=os.environ.get('pretrained_model', 'bert-base-multilingual-cased'), cache_dir=os.environ.get('cache_dir', '/data/cache'), model_dir=os.environ.get('model_dir', '/data/model'), train_logs=os.environ.get('train_logs', '/data/train_logs'))
import os import logging import argparse logging.basicConfig(level=logging.INFO) from htx import app, init_model_server from image_classifier import FastaiImageClassifier, train_script init_model_server( create_model_func=FastaiImageClassifier, train_script=train_script, num_iter=10, image_dir='~/.heartex/images', redis_queue=os.environ.get('RQ_QUEUE_NAME', 'default'), redis_host=os.environ.get('REDIS_HOST', 'localhost'), redis_port=os.environ.get('REDIS_PORT', 6379), ) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--port', dest='port', default='9090') args = parser.parse_args() app.run(host='localhost', port=args.port, debug=True)
import os import argparse from tfhub_classifier import TFHubClassifier from htx import app, init_model_server init_model_server( # refer to class definition that inherits htx.BaseModel and implements load() and predict() methods create_model_func=TFHubClassifier, # training script that will be called within RQ train_script=TFHubClassifier.fit_single_label, # name of the Redis queue redis_queue=os.environ.get('RQ_QUEUE_NAME', 'default'), # Redis host redis_host=os.environ.get('REDIS_HOST', 'localhost'), # here we pass the kwargs parameters to train script tfhub_module_spec=os.environ.get( 'tfhub_module_spec', 'https://tfhub.dev/google/universal-sentence-encoder/2')) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--port', dest='port', default='9090') args = parser.parse_args() app.run(host='localhost', port=args.port, debug=True)
import os import logging import argparse logging.basicConfig(level=logging.INFO) from htx import app, init_model_server from image_classifier import FastaiImageClassifier, train_script from settings import REDIS_HOST, REDIS_PORT, RQ_QUEUE_NAME init_model_server( create_model_func=FastaiImageClassifier, train_script=train_script, num_iter=10, image_dir='~/.heartex/images', redis_queue=RQ_QUEUE_NAME, redis_host=REDIS_HOST, redis_port=REDIS_PORT, ) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--port', dest='port', default='9090') args = parser.parse_args() app.run(host='localhost', port=args.port, debug=True)