@@ -93,22 +93,21 @@ from Algorithmia import ADK
9393# API calls will begin at the apply() method, with the request body passed as 'input'
9494# For more details, see algorithmia.com/developers/algorithm-development/languages
9595
96- def apply (input , globals ):
96+ def apply (input , modelData ):
9797 # If your apply function uses state that's loaded into memory via load, you can pass that loaded state to your apply
9898 # function by defining an additional "globals" parameter in your apply function.
99- return " hello {} {} " .format(str (input ), str (globals [' payload' ]))
99+ return " hello {} {} " .format(str (input ), str (modelData.user_data [' payload' ]))
100100
101101
102- def load ():
102+ def load (modelData ):
103103 # Here you can optionally define a function that will be called when the algorithm is loaded.
104104 # The return object from this function can be passed directly as input to your apply function.
105105 # A great example would be any model files that need to be available to this algorithm
106106 # during runtime.
107107
108108 # Any variables returned here, will be passed as the secondary argument to your 'algorithm' function
109- globals = {}
110- globals [' payload' ] = " Loading has been completed."
111- return globals
109+ modelData.user_data[' payload' ] = " Loading has been completed."
110+ return modelData
112111
113112
114113# This turns your library code into an algorithm that can run on the platform.
@@ -175,27 +174,26 @@ def infer_image(image_url, n, globals):
175174 return result
176175
177176
178- def load (manifest ):
177+ def load (modelData ):
179178
180- state = {}
181- state[" SMID_ALGO" ] = " algo://util/SmartImageDownloader/0.2.x"
182- state[" model" ] = load_model(manifest.get_model(" squeezenet" ))
183- state[" labels" ] = load_labels(manifest.get_model(" labels" ))
184- return state
179+ modelData.user_data[" SMID_ALGO" ] = " algo://util/SmartImageDownloader/0.2.x"
180+ modelData.user_data[" model" ] = load_model(modelData.get_model(" squeezenet" ))
181+ modelData.user_data[" labels" ] = load_labels(modelData.get_model(" labels" ))
182+ return modelData
185183
186184
187- def apply (input , state ):
185+ def apply (input , modelData ):
188186 if isinstance (input , dict ):
189187 if " n" in input :
190188 n = input [" n" ]
191189 else :
192190 n = 3
193191 if " data" in input :
194192 if isinstance (input [" data" ], str ):
195- output = infer_image(input [" data" ], n, state )
193+ output = infer_image(input [" data" ], n, modelData.user_data )
196194 elif isinstance (input [" data" ], list ):
197195 for row in input [" data" ]:
198- row[" predictions" ] = infer_image(row[" image_url" ], n, state )
196+ row[" predictions" ] = infer_image(row[" image_url" ], n, modelData.user_data )
199197 output = input [" data" ]
200198 else :
201199 raise Exception (" \" data\" must be a image url or a list of image urls (with labels)" )
0 commit comments