Do AutoMl predictions not work when uploaded into Google Cloud Functions

196 views Asked by At

Im writing code that makes a prediction based on a trained AutoMl multi-label Classifier. The function works if I run it locally, however, as soon as i upload the same code to Cloud Functions on GCP (a process that i know usually works) it provides me with this error

TypeError: predict() takes from 1 to 2 positional arguments but 4 were given

Here is a sample of my code, taken straight from the AutoMl documentation with some slight adjustments.

def get_sentiment(content):
    """
    Returns a google cloud platform payload class containing the sentiment score given by our NLP sentiment analyser.
    :param content: STRING (UTF-8 encoded, ASCII)
    :return: <class 'google.cloud.automl.types.PredictResponse'>
    """
    options = ClientOptions(api_endpoint='automl.googleapis.com')
    prediction_client =   automl_v1beta1.PredictionServiceClient(client_options=options)

    name = model_sentiment
    payload = {'text_snippet': {'content': content, 'mime_type': 'text/plain'}}
    params = {}
    request = prediction_client.predict(name, payload, params)
    return request

I have tried removing the params variable from prediction and replacing payload with content the only change is that I get the error:

TypeError: predict() takes from 1 to 2 positional arguments but 3 were given

Additionally, I have replaced automl_v1beta1 with automl and automl_v1. and again while both work locally they do not work on Google Cloud.

Thank you for any advice or help

1

There are 1 answers

0
Alfred Lindholm On

Update, Apparently there are some bugs in the latest version of AutoML and the error was fixed by running the code on a previous version of it. Specifically in my case v0.9.0