Package: nanowire-flask
This library is designed to allow a python developer to easily create a nanowire plugin using the flask APIs structure.The function you mount for image plugins, using the functionmount_Image_functionmust have the argumentsimgandvariablesif you want initialise a model or other variables when the sever starts you may make the function to be mounted into a function of a
class which is initiated with the functionmount_Image_function. You should expectimgto be a PIL RGB image object andvariablesto be a dictionary containing the variables sent to the plugin in the curl request.The function for mounting a text based plugin is similar however it is calledmount_text_functionand expects the argumentstext(a string) andvariables.The curl requests for images may be formatted 2 ways. The first involves sending the image as a file attached to the curl request. For example:curl-F"image=@./1.jpg"-XPOSThttp://0.0.0.0:5000/model/predict?threshold=0.5alternatively the file may be sent as a link using a dictionary eg.curl-XPOST-H"Content-Type:application/json"-d'{"contentUrl":"http://127.0.0.1:8000/1.jpg","threshold":0.5}'http://0.0.0.0:5000/model/predictThe currently supported image formats are:jpgpngbmptifppmThe curl request for text is similar to that used for images except that it may take either raw text or a file containing raw text. You may either post a document containing the raw text using the commandcurl-F"doc=@./doc1.txt"-XPOSThttp://0.0.0.0:5000/model/predict?deactivate_ngrams=Trueor the raw text can be sent using:curl-XPOST-H"Content-Type:application/json"-d'{"text":"Exampletext about whichever subject you're interested in","deactivate_ngrams"="True"}'http://0.0.0.0:5000/model/predictThe library may also accept CSV objects using command likecurl-F"csv=@./example.csv"-XPOSThttp://0.0.0.0:5000/model/predict?ignore_col=texta xlsx file may be sent in the same way:curl-F"xlsx=@./example.xlsx"-XPOST'http://0.0.0.0:5000/model/predict?ignore_col=text&customStops=horse,course&indexCol=uuid'alternatively a link to a csv or xlsx file may be sent such as:curl-XPOST-H"Content-Type:application/json"-d'{"contentUrl":"http://localhost:8000/example.csv","ignore_col":"dates"}'http://0.0.0.0:5000/model/predictThe library may also accept JSON objects using commands such ascurl-XPOST-H"Content-Type:application/json"-d'{"inputJSON":{"this":"is","an":"example"},"variables":{"customStops":["horse","course"]}'http://0.0.0.0:5000/model/predictalternatively a JSON file may be sent from a servercurl-XPOST-H"Content-Type:application/json"-d'{"contentUrl":"http://localhost:8000/example.json"}'http://0.0.0.0:5000/model/predictan old version of this command would accept:curl-XPOST-H"Content-Type:application/json"-d'{"this":"is","an":"example"}'http://0.0.0.0:5000/model/predicthowever this is deprecated and will no longer be accepted in future versions of this library.This library will eventually be expanded to be able to handle video, sound and arbitrary files however for now it is limited to text, images, csv files and json files.The API you create will also return maximum memory usage (in MB), maximum cpu usage (in %) and time taken (in seconds) when processing a given API call.Notes for advanced usersimage_tools.mount_Image_functionParametersfunction:- The function to be mounted on the API. The function must take img and variables as arguments when processing images. The function must return a dictionary.hostoptional:- default is ‘0.0.0.0’. Set the IP address to host the API on.portoptional:- default 5000. Set the port to host the API on.pathoptional:- default ‘/model/predict’. Set the path for the API.text_tools.mount_text_functionParameters*function:- The function to be mounted on the API. The function must take text and variables as arguments when processing text. The function must return a dictionary.
*hostoptional:- default is ‘0.0.0.0’. Set the IP address to host the API on.
*portoptional:- default 5000. Set the port to host the API on.
*pathoptional:- default ‘/model/predict’. Set the path for the API.csv_tools.mount_csv_functionParameters*function:- The function to be mounted on the API. The function must take df (a pandas dataframe) and variables (a dictionary) as arguments when processing a csv. The function must return a dictionary.
*hostoptional:- default is ‘0.0.0.0’. Set the IP address to host the API on.
*portoptional:- default 5000. Set the port to host the API on.
*pathoptional:- default ‘/model/predict’. Set the path for the API.json_tools.mount_json_functionParameters*function:- The function to be mounted on the API. The function must take inputJSON as an argument. The function must return a dictionary.
*hostoptional:- default is ‘0.0.0.0’. Set the IP address to host the API on.
*portoptional:- default 5000. Set the port to host the API on.
*pathoptional:- default ‘/model/predict’. Set the path for the API.Notes on debug modeIn order to activate debug mode the environmental variablePYTHON_DEBUGmust be set to true.Debug mode will mean that any errors encountered whilst running the function will also give a full traceback of the error in the returned JSON.Notes on taskIDIf the post containstaskIDas an argument the taskID given will also be returned in the output JSON.