Coverage for src/lightmlrestapi/cli/make_ml_upload.py: 53%

19 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-06-06 07:16 +0200

1""" 

2@file 

3@brief Creates and runs an Falcon application. 

4""" 

5import os 

6import sys 

7 

8 

9def upload_model(login="", pwd="", name="", pyfile="", data="", url='127.0.0.1:8081', # pylint: disable=W0102 

10 timeout=50, fLOG=print): # pylint: disable=W0622 

11 """ 

12 Uplaods a machine learned models to a REST API defined by 

13 @see cl MLStoragePost. 

14 

15 :param login: user login 

16 :param pwd: user pasword 

17 :param name: name of the model, should be unique and not already used 

18 :param pyfile: python file which computes the prediction, 

19 the file must follows the specification defined in 

20 :ref:`l-template-ml` 

21 :param data: files to upload 

22 :param url: url of the REST API 

23 :param timeout: timeout 

24 :param fLOG: logging function 

25 

26 .. cmdref:: 

27 :title: Uploads a machine model 

28 :cmd: -m lightmlrestapi upload_model --help 

29 :lid: cmd_upload_model_cmd 

30 

31 Uploads a machine learned model to a REST API 

32 created with *lightmlrestapi*. The code of this command line is equivalent 

33 to: 

34 

35 :: 

36 

37 from lightmlrestapi.netrest import submit_rest_request, json_upload_model 

38 req = json_upload_model(name=name, pyfile=pyfile, data=data) 

39 submit_rest_request(req, login=login, pwd=pwd, url=url) 

40 """ 

41 try: 

42 from ..netrest import submit_rest_request, json_upload_model 

43 except (ImportError, ValueError): 

44 folder = os.path.normpath(os.path.join( 

45 os.path.abspath(os.path.dirname(__file__)), "..", "..")) 

46 sys.path.append(folder) 

47 from lightmlrestapi.netrest import submit_rest_request, json_upload_model 

48 

49 if isinstance(data, str): 

50 data = data.split(',') 

51 if fLOG: 

52 fLOG('[upload_model] Prepare the JSON request.') 

53 req = json_upload_model(name=name, pyfile=pyfile, data=data) 

54 if fLOG: 

55 fLOG('[upload_model] Submit request - size:', len(req['zip'])) 

56 submit_rest_request(req, login=login, pwd=pwd, url=url, fLOG=fLOG) 

57 if fLOG: 

58 fLOG('[upload_model] Done.')