<jupyter_start><jupyter_text>**RNN Serving** The following section we create a new model serving function which wraps our class , and specify model and other resources. Deploying the serving function will provide us an http endpoint that can handle requests in real time. This function is part of the [stock-analysis demo](https://github.com/mlrun/demos/tree/master/stock-analysis).To see how the model is trained or how the data-set is generated, check out code folder in the demo repository.  **Steps**1. [Setup function parameters](Setup-function-parameters)2. [Importing the function](Importing-the-function)3. [Testing the function locally](Testing-the-function-locally)4. [Testing the function remotely](Testing-the-function-remotely)<jupyter_code>import warnings
warnings.filterwarnings("ignore")
# Following packages are required, make sure to install
# !pip install pip install torch==1.6.0
# !pip install tensorflow
# !pip install keras<jupyter_output><empty_output><jupyter_text>**Setup function parameters**<jupyter_code># Setting up models path
rnn_model_path = 'https://s3.wasabisys.com/iguazio/models/function-marketplace-models/rnn_serving/rnn_model.h5'
data_path = 'https://s3.wasabisys.com/iguazio/data/function-marketplace-data/rnn_serving/stocks_data.pkl'<jupyter_output><empty_output><jupyter_text>**Importing the function**<jupyter_code>import mlrun
mlrun.set_environment(project='function-marketplace')

# Importing the function from the hub
fn = mlrun.import_function("hub://rnn_serving")
fn.apply(mlrun.auto_mount())

# Manually specifying needed packages 
fn.spec.build.commands = ['pip install torch==1.6.0', 'pip install tensorflow', 'pip install keras']

# Adding the model 
fn.add_model(key='rnn_model', model_path=rnn_model_path ,class_name='RNN_Model_Serving')<jupyter_output>> 2021-10-17 10:43:46,363 [info] loaded project function-marketplace from MLRun DB<jupyter_text>**Testing the function locally**<jupyter_code># When mocking, class has to be present
from rnn_serving import *

# Mocking function
server = fn.to_mock_server()
# Getting the data
import cloudpickle as cp
from urllib.request import urlopen

rnn_data = cp.load(urlopen(data_path))<jupyter_output><empty_output><jupyter_text>model used in this example take inputs with the shape `(None, None, 11)`. whereas the first dimenstion is the number of instances, the second dimenstion is the number of timestampsand the last dimenstion is the number of features the dataset have.our testing dataset has `(1,10,11)` means one instance to predict, with sequence length of 10, each step has 11 features.<jupyter_code>import requests

# KFServing protocol event
event_data = {"inputs": rnn_data}

response = server.test(path='/v2/models/rnn_model/predict',body=event_data)
response<jupyter_output><empty_output><jupyter_text>**Testing the function remotely**<jupyter_code>address = fn.deploy()
import json
import requests

# using requests to predict
response = requests.put(address+"/v2/models/rnn_model/predict", json = json.dumps(event_data))
json.loads(response.text)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10252263906856404, 'fraction_numerical': 0.01390685640362225, 'mean_word_length': 6.771356783919598, 'pattern_counts': {'":': 1, '<': 24, '<?xml version=': 0, '>': 25, 'https://': 3, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '440795', 'license': 'Apache-2.0', 'n_tokens_mistral': 996, 'n_tokens_neox': 955, 'n_words': 271, 'path': 'rnn_serving/rnn_serving.ipynb', 'repo_name': 'aviaIguazio/functions', 'size': '3092'}