Gradio - an easy way to create an ML web app

Gradio is likely the easiest way to prototype web apps for ML models. In fact, it takes just one line of code!

Here is an example of a cat/dog classifier taken from lesson 1 of the course turned into a simple web app:

To use Gradio, you define the input and output types (including: image, audio, textbox, dataframe, a generic file, and more) and a prediction function that takes in the defined input type and outputs the defined output type. All these are passed into an interface class and the launch method is called, launching a web app locally or hosted under a Gradio subdomain for ~6 hours. Gradio also provides latency information, the ability to flag different scenarios, and take screenshots of the web app (shown above). I haven’t tried all the different types of inputs/outputs, but I know the image input comes with an image editor where you can play around with the image (crop, enhance, rotate, etc.) and you can see how robust your model might be (accessible with the EDIT button).

Here is a tutorial notebook demonstrating how simple it is to use Gradio:
Colab notebook

A Gradio subdomain link is provided at the end where you can try out the web app.

You can see it basically takes one line of code to create the interface:

gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=len(labels))).launch()

It is also possible to deploy the Gradio web app to Heroku. Here are some instruction for this:

An example of such a deployment is available here (Heroku setup code here).

Hope this serves as a great option for prototyping ML web apps!

Note: I am not affliated with Gradio in any way, I just find it to be a really nice library for creating ML web apps really quickly.


Thank you very much! I was looking for that.

1 Like