TransWikia.com

APIFunction with TextRecognize problems

Mathematica Asked on March 7, 2021

I have a simple API that takes a recipe and returns the list of ingredients:

api = CloudDeploy[APIFunction[{"img"->"Image"},
    (ResourceFunction["DeleteFailures"]@Map[Function[w, Interpreter["FoodType"][w]], Flatten @ TextRecognize[#img, "Word"]])&
], Permissions->"Public", IncludeDefinitions->True]

So here’s the example I’m trying to make work:

recipe = CloudGet@"https://www.wolframcloud.com/obj/fe25d585-acc3-4931-9223-da5ee1dce6bd";

enter image description here

The function inside the API works just fine locally (without the APIFunction & CloudDeploy) as you can see:

AbsoluteTiming[Function[{img}, ResourceFunction["DeleteFailures"]@Map[Function[w, 
     Interpreter["FoodType"][w]], Flatten@TextRecognize[img, "Word"]]][recipe]]

enter image description here

But when deployed as an API in the Wolfram Cloud, it refuses to return anything, how can I get this to work?

What I’ve Tried

A simple POST request with URLExecute gives a 408 error:

AbsoluteTiming[URLExecute[api, <|"img"->recipe|>, TimeConstraint->[Infinity]]]

enter image description here

Another attempt with the obsolete-but-still-super-useful URLFetch with multi-part data gives a 503 error (btw, does anyone know how to accomplish this without using an obsolete symbol?):

AbsoluteTiming[URLFetch[api, "Method" -> "POST",  "MultipartElements" -> {{"img", "image/jpeg"} -> ExportString[recipe, "JPEG"]}]]

enter image description here

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP