<jupyter_start><jupyter_text>Framework imports<jupyter_code>from noronha.tools.serving import OnlinePredict, LazyModelServer
from noronha.tools.shortcuts import model_path<jupyter_output><empty_output><jupyter_text>Application imports<jupyter_code>import json
import numpy as np
import joblib
import pickle<jupyter_output><empty_output><jupyter_text>Loading the model<jupyter_code>#clf_path = model_path('clf.pkl')
#clf = joblib.load(clf_path)<jupyter_output><empty_output><jupyter_text>Defining the prediction function<jupyter_code>def predict(x):
    features = json.loads(x)
    features = np.array(features).reshape(1, -1)
    return clf.predict(features)[0]<jupyter_output><empty_output><jupyter_text>Creating the prediction service<jupyter_code>def load(path, meta):
    return joblib.load(path + '/clf.pkl')

def pred(x, clf, meta):
    data = json.loads(x)
    return clf.predict(np.array(data).reshape(1,-1))[0]

server = LazyModelServer(
    predict_func=pred,
    load_model_func=load,
    model_name='iris-clf3',
    #server_type='gunicorn',
    #webapp='fastapi',
    server_conf={'timeout':300, 'loglevel':'debug'}#, 'worker_class': 'uvicorn.workers.UvicornWorker'}
    #server_conf={'timeout':300, 'threads':12, 'worker_class': 'uvicorn.workers.UvicornWorker'}
)

server()

OnlinePredict(
    predict_func=predict, 
#    webapp='fastapi',
#    server_type = 'gunicorn',
#    server_conf = {'worker_class': 'uvicorn.workers.UvicornWorker'}
)()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13853396099529253, 'fraction_numerical': 0.010087424344317418, 'mean_word_length': 7.0, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '435422', 'license': 'Apache-2.0', 'n_tokens_mistral': 561, 'n_tokens_neox': 544, 'n_words': 77, 'path': 'examples/1_iris/notebooks/predict.ipynb', 'repo_name': 'pierodesenzi/noronha', 'size': '1487'}