Unexpected character error when calling self-build ML skill

After developing our own ML skill and uploading it to the AI Center, we receive the following error when calling it from Studio;

Post request with accessUri failed, error: Unexpected character encountered while parsing value: <. Path ‘’, line 0, position 0.

The skill works fine when testing locally on our machine, and was validated & deployed successfully on AI Center.

The input for the skill is a simple string in the following format;
[‘text’, ‘text’]. No < is used in the input/output, so the error seems quite odd to me.

Hi @Senne_Symons
Looks like an issue in the way you provide/handle input in your Skill, any chance you provide your main.py file? What input type did you select for your ML Skill?

Jeremy

Hi Jeremy,

My predict function is the following;

def predict(self, input):
        temp = json.loads(input)
        a = temp['body']
        b = temp['subject']
        df = pd.DataFrame({'body':a, 'subject':b}, index=[0])
        df = clean_df(df)
        X = tokenize(df)
        preds = self.model.predict(X)
        return {LABELS[i]: preds[0][i] for i in range(len(LABELS))}

When testing locally, it works as expected;

>>> m.predict('{"subject":"test","body":"test"}')
2021-09-24 08:38:55.806018: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR Optimization Passes are enabled (registered 2)
{'aanmaning': 0.11007609, 'andere': 0.10001555, 'factuur': 0.78990835}

But when calling from ML Skill activity;
Untitled

ok the issue is the output, function should return a string not a dict, you should use json.dumps of your current output.

Hi Jeremy,

Thanks for the feedback! That fixed it. :slight_smile:

It’s my first time building a custom ML skill, so still need to figure a lot of stuff out. :smiley:

Awesome! No issue happy to see that you managed to create your first ML Package!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.