text: """
  Copyright (C) Microsoft Corporation. All rights reserved.​
   ​
  Microsoft Corporation (“Microsoft”) grants you a nonexclusive, perpetual,
  royalty-free right to use, copy, and modify the software code provided by us
  ("Software Code"). You may not sublicense the Software Code or any use of it
  (except to your affiliates and to vendors to perform work on your behalf)
  through distribution, network access, service agreement, lease, rental, or
  otherwise. This license does not purport to express any claim of ownership over
  data you may have shared with Microsoft in the creation of the Software Code.
  Unless applicable law gives you more rights, Microsoft reserves all other
  rights not expressly granted herein, whether by implication, estoppel or
  otherwise. ​
   ​
  THE SOFTWARE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  MICROSOFT OR ITS LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THE SOFTWARE CODE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE.
  """
  import pickle
  import json
  import numpy
  from sklearn.ensemble import RandomForestClassifier
  from azureml.core.model import Model
  
  
  def init():
      global model
      from sklearn.externals import joblib
  
      # load the model from file into a global object
      model_path = Model.get_model_path(model_name="sklearn_regression_model.pkl")
      model = joblib.load(model_path)
  
  
  def run(raw_data):
      try:
          data = json.loads(raw_data)["data"]
          data = numpy.array(data)
          result = model.predict(data)
          return json.dumps({"result": result.tolist()})
      except Exception as e:
          result = str(e)
          return json.dumps({"error": result})
  
  
  if __name__ == "__main__":
      # Test scoring
      init()
      test_row = '{"data":[[1,2,3,4,5,6,7,8,9,10],[10,9,8,7,6,5,4,3,2,1]]}'
      prediction = run(test_row)
      print("Test result: ", prediction)
  