Deploy notebook in IBM Watson

Asked by At

I have a python notebook in IBM Watson Studio for a time series forecasting purpose.

it takes two input data

  1. MAX
  2. MIN

and it returns two lists of data having 10 steps ahead prediction of both MAX and MIN.

I want to make it available for an external application. I have searched for the solution like API creation but didn't get any source. can anyone suggest me the proper way or helpful resources to do it?

1 Answers

2
Majo_Jose On Best Solutions

Now I got the solution of my own question through my 2 days of research and attempts. Nobody gave me any solution so I thought that it would be posted here for future references.

Here, I have added my practical experience so that it might be a long answer.

1. Why IBM Notebook?

We choose a notebook instead of available models if we need more customization. we will get most of the models that are not available in the built-in models

2. Ways to do that?

As per my enquiry, I found two ways to do that

  • Deploy it as python function ( Worked for me )
  • Deploy it with the help of jupyter notebook, IBM Cloud and Github See this tutorial

3. Deploy it as python function [source]

  • Wrap up all your functionalities under a single function (Step 1). like it takes input and returns the output.

  • In each call, the variables or data structures you have in the code will lose the data. so avoid these items in your python function and manage it in your application.

  • Another important point is that if you want to import libraries you have to include it as a subprocess inside the main function Because of the difference in testing environments and deployed environment. you can do it by simply adding like this

  • Sample Format python Function

    def my_deployable_function():
    
       import subprocess
       subprocess.check_output( "pip install ipython--user",stderr=subprocess.STDOUT,shell=True )
    
        def score( payload ):
    
           num1=int(payload["values"][0])
           num2=int(payload["values"][1])  
           ans=num1+num2
    
        return ans
    

    *Here, the payload is the data you passed to the python function from the API and ans is the output

  • Test the Function

    function_result = my_deployable_function()( { "values" : [ 100,200] } )
    print( function_result )
    

    *Input payload is a dictionary. as per your need, you can add the elements but make sure that you are not changing the structure ie, Everything Should be under a single root element here it is values.

  • output

    300
    
  • As you follow (Step 2) in source you need credentials, if you have any problem with existing credentials then create a new one because older one may be expired.

  • If your plan is Lite you are not able to perform more than 5 Deployments (Step 3). so make it count. if it exceeded, create a new service by deleting the older (only one is allowed).
  • If you are creating a new service, check it in Project settings is it associated with your project or not. otherwise, the credential will work only in the IBM Watson, not through REST API (Step 4).

Follow the official documentation and keep these instructions to save your time.