Skip to main content

Tool for creating nanowire tools with the flask structure.

Project description

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 function mount_Image_function must have the arguments img and variables if 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 function mount_Image_function. You should expect img to be a PIL RGB image object and variables to 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 called mount_text_function and expects the arguments text (a string) and variables.

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" -XPOST http://0.0.0.0:5000/model/predict?threshold=0.5

alternatively the file may be sent as a link using a dictionary eg.

curl -X POST -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/predict

The currently supported image formats are:

  • jpg

  • png

  • bmp

  • tif

  • ppm

The 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 command

curl -F "doc=@./doc1.txt" -XPOST http://0.0.0.0:5000/model/predict?deactivate_ngrams=True

or the raw text can be sent using:

curl -X POST -H "Content-Type:application/json" -d '{"text":"Example text about whichever subject you're interested in", "deactivate_ngrams"="True"}' http://0.0.0.0:5000/model/predict

The library may also accept CSV objects using command like

curl -F "csv=@./example.csv" -XPOST http://0.0.0.0:5000/model/predict?ignore_col=text

a 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 -X POST -H "Content-Type:application/json" -d '{"contentUrl":"http://localhost:8000/example.csv", "ignore_col":"dates"}' http://0.0.0.0:5000/model/predict

The library may also accept JSON objects using commands such as

curl -X POST -H "Content-Type:application/json" -d '{"inputJSON": {"this":"is", "an":"example"}, "variables":{"customStops":["horse", "course"]}' http://0.0.0.0:5000/model/predict

alternatively a JSON file may be sent from a server

curl -X POST -H "Content-Type:application/json" -d '{"contentUrl":"http://localhost:8000/example.json"}' http://0.0.0.0:5000/model/predict

an old version of this command would accept:

curl -X POST -H "Content-Type:application/json" -d '{"this":"is", "an":"example"}' http://0.0.0.0:5000/model/predict

however 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 users

image_tools.mount_Image_function

Parameters

  • function :- 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.

  • host optional:- default is ‘0.0.0.0’. Set the IP address to host the API on.

  • port optional:- default 5000. Set the port to host the API on.

  • path optional:- default ‘/model/predict’. Set the path for the API.

text_tools.mount_text_function

Parameters * 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. * host optional:- default is ‘0.0.0.0’. Set the IP address to host the API on. * port optional:- default 5000. Set the port to host the API on. * path optional:- default ‘/model/predict’. Set the path for the API.

csv_tools.mount_csv_function

Parameters * 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. * host optional:- default is ‘0.0.0.0’. Set the IP address to host the API on. * port optional:- default 5000. Set the port to host the API on. * path optional:- default ‘/model/predict’. Set the path for the API.

json_tools.mount_json_function

Parameters * function :- The function to be mounted on the API. The function must take inputJSON as an argument. The function must return a dictionary. * host optional:- default is ‘0.0.0.0’. Set the IP address to host the API on. * port optional:- default 5000. Set the port to host the API on. * path optional:- default ‘/model/predict’. Set the path for the API.

Notes on debug mode

In order to activate debug mode the environmental variable PYTHON_DEBUG must 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 taskID

If the post contains taskID as an argument the taskID given will also be returned in the output JSON.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanowire_flask-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

nanowire_flask-0.1.0-py2-none-any.whl (21.9 kB view details)

Uploaded Python 2

File details

Details for the file nanowire_flask-0.1.0.tar.gz.

File metadata

  • Download URL: nanowire_flask-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/2.7.17

File hashes

Hashes for nanowire_flask-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d82195ed7bf95d81480df2bb73ab02563bbc28cceb66607dafb5418085e95d9e
MD5 b891f9ae6ee932bc464279260c987ee0
BLAKE2b-256 16ee0f4de903fd7eb9a3407ff248cab912eb391ef08d8e987201a9d8c4234581

See more details on using hashes here.

File details

Details for the file nanowire_flask-0.1.0-py2-none-any.whl.

File metadata

  • Download URL: nanowire_flask-0.1.0-py2-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/2.7.17

File hashes

Hashes for nanowire_flask-0.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 53037f2c7b66a2c48016dac2550f1b14d7373657c118f6bf5ff699c067291a3a
MD5 2380093238b874d652638dbf9794f2cf
BLAKE2b-256 f095163aeec280b92f2e75086b7e7cbcec63adb9e6061b1c980d33d3ec8e6238

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page