<jupyter_start><jupyter_text>Serving of Tensorflow2 model with Konduit-servingStep 1: Initiate the server with  konduit serve --config config.yaml  Step 2: Run client.ipynb<jupyter_code>import re
import io
import logging
import time
import numpy as np
import pickle
import tensorflow as tf

from konduit.load import client_from_file

logging.basicConfig(level='DEBUG')
logging.info("Test")


input_path = 'D:\\Users\\chiawei\\konduit\\Github\\newsgroup_data\\20news-bydate\\20news-bydate-test\\misc.forsale\\76128'
#input_path = 'D:\\Users\\chiawei\\konduit\\Github\\newsgroup_data\\20news-bydate\\20news-bydate-test\\rec.autos\\103066'
#input_path = 'D:\\Users\\chiawei\\konduit\\Github\\newsgroup_data\\20news-bydate\\20news-bydate-test\\comp.os.ms-windows.misc\\10003'

handle = open(input_path, 'r')
input_data = list([handle.read()])

tokenizer_path = 'tokenizer.pickle'
handle = open(tokenizer_path, 'rb')
tokenizer = pickle.load(handle)

print('Load index label')
label_path = "labelclass.pickle"
labelhandler = open(label_path, 'rb')
labelhandler = pickle.load(labelhandler)

MAX_LEN = 256
input_sequence = tokenizer.texts_to_sequences(input_data)
input = tf.keras.preprocessing.sequence.pad_sequences(input_sequence, maxlen = MAX_LEN, padding = "post")

client = client_from_file("config.yaml")

responses = []

start = time.time()

for i in range(10):
    response = client.predict({"default": input})
    responses.append(response)

end = time.time()

print("%f seconds elapsed for %d requests (%d RPS)" % (end - start, len(responses), (10.0 / (end - start))))
response = client.predict({"default": input})

results = response["output"]["probabilities"]
index = int(np.argmax(response['output']['probabilities'], 1)[0])

print("Class: {}".format(labelhandler[index]))
print("Probabilities: {}".format(np.max(response['output']['probabilities'])))<jupyter_output>DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost:65322
DEBUG:urllib3.connectionpool:http://localhost:65322 "POST /classification/numpy HTTP/1.1" 200 610
{'fraction_non_alphanumeric': 0.15519765739385066, 'fraction_numerical': 0.030258662762323085, 'mean_word_length': 5.925675675675675, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '515287', 'license': 'Apache-2.0', 'n_tokens_mistral': 738, 'n_tokens_neox': 693, 'n_words': 132, 'path': '2_NewsGroupClassification/tf2-simple-model/serving/client.ipynb', 'repo_name': 'codenamewei/nlp-with-use-case', 'size': '2049'}