@@ -93,22 +93,21 @@ from Algorithmia import ADK
93
93
# API calls will begin at the apply() method, with the request body passed as 'input'
94
94
# For more details, see algorithmia.com/developers/algorithm-development/languages
95
95
96
- def apply (input , globals ):
96
+ def apply (input , modelData ):
97
97
# If your apply function uses state that's loaded into memory via load, you can pass that loaded state to your apply
98
98
# 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' ]))
100
100
101
101
102
- def load ():
102
+ def load (modelData ):
103
103
# Here you can optionally define a function that will be called when the algorithm is loaded.
104
104
# The return object from this function can be passed directly as input to your apply function.
105
105
# A great example would be any model files that need to be available to this algorithm
106
106
# during runtime.
107
107
108
108
# 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
112
111
113
112
114
113
# 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):
175
174
return result
176
175
177
176
178
- def load (manifest ):
177
+ def load (modelData ):
179
178
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
185
183
186
184
187
- def apply (input , state ):
185
+ def apply (input , modelData ):
188
186
if isinstance (input , dict ):
189
187
if " n" in input :
190
188
n = input [" n" ]
191
189
else :
192
190
n = 3
193
191
if " data" in input :
194
192
if isinstance (input [" data" ], str ):
195
- output = infer_image(input [" data" ], n, state )
193
+ output = infer_image(input [" data" ], n, modelData.user_data )
196
194
elif isinstance (input [" data" ], list ):
197
195
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 )
199
197
output = input [" data" ]
200
198
else :
201
199
raise Exception (" \" data\" must be a image url or a list of image urls (with labels)" )
0 commit comments