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:
https://towardsdatascience.com/how-to-deploy-a-machine-learning-ui-on-heroku-in-5-steps-b8cd3c9208e6

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.

22 Likes

Thank you very much! I was looking for that.

2 Likes

Is it possible with Gradio to make a Webpage where the user can upload images, label them (mabe correct labels) and press a button to train a new model? Or is it only for showing the inference part of the model? If Gradio is not able to provide for data collection and training, what would be a fast path towards a web frontend and deep learning model server backend for someone who is not a web developer?

Gradio could serve as a frontend for that, but you would have to develop it and provide a backend for storage and training as well.

There are a number of services that provide this out of the box, each with their own strengths and limitations. You are going to want to look for No/low code AI platforms such as:

  • Lobe
  • MakeML
  • Azure custom vision
  • Vertex AI
  • HuggingFace (I think they provide such a service, but have not tried it)
  • SeeMe.ai (disclosure: I’m the creator of SeeMe.ai)

Hope it helps!

1 Like

Thank you. I will check those suggestions!