Skip to content
Simple example of running a flask app from a Gradient job
Python Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Sometimes you want to serve a simple webservice from a GPU container. Maybe you want to test out a new model you have trained (not hodog?!) or want to serve a simple visualization of your machine learning model. This repo shows you how to make a simple flask app using Paperspace's Gradient°.

Things to note when running flask:

  1. You need to have the flask server listen on all interfaces by specifying"") for the interface to listen on.
  2. You need to install the flask and flask_restful packages as part of running the job if it is not already part of the container. (The flask_restful package optional if you are not using its functionality in your flask server.) The example here shows both these actions.

Also note, flask by default does not provide SSL/TLS security. See the flask package documentation for options on how to secure flask. Here is an article on running your flask-application over https.

Run the job

paperspace jobs create --machineType P5000 --container Test-Container --ports 5000:5000 --command 'pip install flask flask_restful && python' --workspace

or alternatively you can pull down this repo and run from your local machine:

> git clone && cd gradient-flask-example

> paperspace project init 

> paperspace jobs create --machineType P5000 --container Test-Container --ports 5000:5000 --command 'pip install flask flask_restful && python' 

Testing the web service

Your flask app is now running on the Gradient job container. Grab the public IP address of the container from the Gradient jobs console or from the CLI.

screen shot 2018-04-23 at 11 50 12 am

Once you have found your public IP you can hit the web service from a command line or from a web browser. Try it out!


And the output: {"key": "hellothere"}

screen shot 2018-04-23 at 12 15 57 pm

You can’t perform that action at this time.