Coupling Tornado/Python with Octave

Coupling Tornado/Python with Octave

Introduction

When it comes to creating Web Services with Python, my first choice is Tornado. Tornado is undoubtedly a super web framework, it has an asynchronous philosophy, scales well and is widely adopted.

Also, as a guy coming from the Signal Processing arena, I really like Octave. Python's stack for working with scientific problems is pretty good, but the ease of use of Octave and the possibility of leveraging all the existent packages and code make it pretty appealing as well.

Fortunately, there's a way to couple Python and Octave, and expose all your numeric scripts through a web-framework. The oct2py package accomplishes exactly this.

Oct2Py

Oct2Py provides an interface between your m-files, and Python. It couldn't be simpler to use,

>>>oc=oct2py.Oct2Py()

>>>x=oc.zeros(3,3)


Example

To have a real feeling of how this all can be glued together we're going to explore a real application. In this example I'm going to show you how we can leverage some existent code for neural nets in octave and connect it to a web browser using a web service.

The application is based on a web canvas and looks like this,

 Explanation

So, what's happening under the hood here?. Well, first we have a web canvas where we capture user input(digits in this case), we perform some normalization(resizing) of the data, as shown in the lower left corner of the canvas.

After that, we encode the image using run length encoding, put the result in the body of a POST and call our web service.

On the backend we decode the image, pass the image through the feed forward part of a neural network, obtain the result and send it back to the browser. The browser will display the resulting digit in the box located above the canvas.

Code

I won't enter into the details of the code for all this, which can be found on github here. The only thing you have to do to see this demo running is first start the server,

>>>tornado-octave>python server.py

and then point your browser to http://localhost:8000/draw.html.

Walk yourself through the code, and ask for clarification if necessary. In the meantime, you can go here to see it working.

 

 

 

To view or add a comment, sign in

Others also viewed

Explore content categories