60
60
fields .URL : str ,
61
61
fields .Url : str ,
62
62
fields .UUID : str ,
63
+ fields .Field : str ,
63
64
}
64
65
65
66
@@ -159,6 +160,18 @@ def _get_model_name(model_name=None):
159
160
sys .exit (1 )
160
161
161
162
163
+ def _get_file_args (fields_in ):
164
+ """Function to retrieve a list of file-type fields
165
+ :param fields_in: mashmallow fields
166
+ :return: list
167
+ """
168
+ file_fields = []
169
+ for k , v in fields_in .items ():
170
+ if type (v ) is fields .Field :
171
+ file_fields .append (k )
172
+ return file_fields
173
+
174
+
162
175
# Get the model name
163
176
model_name = CONF .model_name
164
177
@@ -174,6 +187,10 @@ def _get_model_name(model_name=None):
174
187
predict_args = _fields_to_dict (model_obj .get_predict_args ())
175
188
train_args = _fields_to_dict (model_obj .get_train_args ())
176
189
190
+ # Find which of the arguments are going to be files
191
+ file_args = {}
192
+ file_args ['predict' ] = _get_file_args (model_obj .get_predict_args ())
193
+ file_args ['train' ] = _get_file_args (model_obj .get_train_args ())
177
194
178
195
# Function to add later these arguments to CONF via SubCommandOpt
179
196
def _add_methods (subparsers ):
@@ -285,29 +302,31 @@ def main():
285
302
if CONF .deepaas_with_multiprocessing :
286
303
mp .set_start_method ("spawn" , force = True )
287
304
288
- # TODO(multi-file): change to many files ('for' itteration)
289
- if CONF .methods .__contains__ ("files" ):
290
- if CONF .methods .files :
305
+ # Create file wrapper for file args (if provided)
306
+ for farg in file_args [CONF .methods .name ]:
307
+ if getattr (CONF .methods , farg , None ):
308
+ fpath = conf_vars [farg ]
309
+
291
310
# create tmp file as later it supposed
292
311
# to be deleted by the application
293
312
temp = tempfile .NamedTemporaryFile ()
294
313
temp .close ()
295
314
# copy original file into tmp file
296
- with open (conf_vars [ "files" ] , "rb" ) as f :
315
+ with open (fpath , "rb" ) as f :
297
316
with open (temp .name , "wb" ) as f_tmp :
298
317
for line in f :
299
318
f_tmp .write (line )
300
319
301
320
# create file object
302
- file_type = mimetypes .MimeTypes ().guess_type (conf_vars [ "files" ] )[0 ]
321
+ file_type = mimetypes .MimeTypes ().guess_type (fpath )[0 ]
303
322
file_obj = v2_wrapper .UploadedFile (
304
323
name = "data" ,
305
324
filename = temp .name ,
306
325
content_type = file_type ,
307
- original_filename = conf_vars [ "files" ] ,
326
+ original_filename = fpath ,
308
327
)
309
- # re-write 'files' parameter in conf_vars
310
- conf_vars ["files" ] = file_obj
328
+ # re-write parameter in conf_vars
329
+ conf_vars [farg ] = file_obj
311
330
312
331
# debug of input parameters
313
332
LOG .debug ("[DEBUG provided options, conf_vars]: {}" .format (conf_vars ))
0 commit comments